Class DefaultA2AClientBuilder<T>
- All Implemented Interfaces:
A2AClientBuilder<T>, InternalAgent, AgentInstance, InvocationHandler
-
Method Summary
Modifier and TypeMethodDescriptionThe condition under which this agent runs when it is invoked as a subagent, ornullwhen it always runs.activationCondition(String description, Predicate<AgenticScope> activationCondition) Sets the condition under which the agent runs when it is invoked as a subagent of an agentic system.agentCardHeaders(Supplier<Map<String, String>> headers) Sets the HTTP headers used to fetch the remote agent card, for example anAuthorizationheader.agentId()voidbooleanasync()async(boolean async) Sets whether the agent should be invoked asynchronously, allowing the workflow to continue without waiting for the agent's result.build()Builds the A2A client proxy implementing the agent service interface.clientCustomizer(Consumer<?> clientCustomizer) Sets a customizer that will be applied to the underlying a2a-java SDKClientBuilderbefore theClientis constructed.The explicit description, else the one of the agent card, which is fetched at this point if not yet done.description(String description) Sets the description of the agent, used by the supervisor and the other planners to decide when to invoke it.Sets the state keys whose values will be sent as message parts to the remote agent.listener()listener(AgentListener agentListener) Sets anAgentListenerfor observing agent invocations.name()The name is always known locally, without fetching the agent card: it is the explicit one, else the one of the annotation of the agent method, else the name of that method for a typed agent, else a placeholder derived from the A2A server URL.Sets the name of the agent, from which its id in the reports, in the agents list sent to a supervisor and in the error handler context is derived.Sets the state key under which the agent's response will be stored.parent()voidregisterInheritedParentListener(AgentListener parentListener) resolutionTimeout(Duration resolutionTimeout) Sets the time given to the fetch of the agent card, which happens the first time the card is needed, normally on the first invocation of the agent, on a thread of the LangChain4j executor.voidsetParent(InternalAgent parent) streamingClientListener(A2AStreamingClientListener<?> clientListener) Sets anA2AStreamingClientListenerfor observing updates received from the remote agent during streaming invocation.Sets the tenant identifier that will be sent with every A2A message.topology()Class<?> type()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface A2AClientBuilder
activationConditionMethods inherited from interface AgentInstance
as, leaf, optionalMethods inherited from interface InternalAgent
allowChatMemory, allowStreamingOutput, compensateOnError, enableCrossAgentCompensation, setAgentId
-
Method Details
-
build
Description copied from interface:A2AClientBuilderBuilds the A2A client proxy implementing the agent service interface.- Specified by:
buildin interfaceA2AClientBuilder<T>- Returns:
- the proxy instance
-
invoke
-
name
Description copied from interface:A2AClientBuilderSets the name of the agent, from which its id in the reports, in the agents list sent to a supervisor and in the error handler context is derived. When not set, a typed agent takes the name of the annotation of its agent method or, when that is not set either, the name of the method, and an untyped one gets a placeholder derived from the host, port and path of the A2A server URL, so that the name is known without fetching the agent card, which happens only on the first invocation. The name never changes once the agent is built, even after the card has been fetched.- Specified by:
namein interfaceA2AClientBuilder<T>- Parameters:
name- the name of the agent, ignored when null or blank- Returns:
- this builder for method chaining
-
description
Description copied from interface:A2AClientBuilderSets the description of the agent, used by the supervisor and the other planners to decide when to invoke it. When neither this method nor the annotation of the agent method set it, the description is read from the agent card, which is fetched on the first call toAgentInstance.description(): for a subagent of a supervisor this happens on the first invocation of the supervisor, which then depends on the availability of the remote agent, so an explicit description is recommended there.- Specified by:
descriptionin interfaceA2AClientBuilder<T>- Parameters:
description- the description of the agent, ignored when null or blank- Returns:
- this builder for method chaining
-
inputKeys
Description copied from interface:A2AClientBuilderSets the state keys whose values will be sent as message parts to the remote agent.- Specified by:
inputKeysin interfaceA2AClientBuilder<T>- Parameters:
inputKeys- the names of the input keys- Returns:
- this builder for method chaining
-
outputKey
Description copied from interface:A2AClientBuilderSets the state key under which the agent's response will be stored.- Specified by:
outputKeyin interfaceA2AClientBuilder<T>- Parameters:
outputKey- the name of the output key- Returns:
- this builder for method chaining
-
async
Description copied from interface:A2AClientBuilderSets whether the agent should be invoked asynchronously, allowing the workflow to continue without waiting for the agent's result. The result is awaited only where it is read: by another agent taking it as an argument, or by the output function or output key of the agentic system.When nothing reads the result, the call to the agentic system returns while the agent is still running, and the result or the failure of the agent is then reported only to its
AgentListener. The next call on the same memory id waits for these agents to complete before it starts.- Specified by:
asyncin interfaceA2AClientBuilder<T>- Parameters:
async-truefor asynchronous invocation- Returns:
- this builder for method chaining
-
listener
Description copied from interface:A2AClientBuilderSets anAgentListenerfor observing agent invocations.- Specified by:
listenerin interfaceA2AClientBuilder<T>- Parameters:
agentListener- the listener to attach- Returns:
- this builder for method chaining
-
activationCondition
public DefaultA2AClientBuilder<T> activationCondition(String description, Predicate<AgenticScope> activationCondition) Description copied from interface:A2AClientBuilderSets the condition under which the agent runs when it is invoked as a subagent of an agentic system. When the condition is false the remote agent is not called and the agent is skipped. It can be evaluated more than once, so it must be free of side effects.- Specified by:
activationConditionin interfaceA2AClientBuilder<T>- Parameters:
description- a human-readable description of the condition, used in logs, listeners and reportsactivationCondition- the predicate deciding whether the agent runs- Returns:
- this builder for method chaining
-
clientCustomizer
Description copied from interface:A2AClientBuilderSets a customizer that will be applied to the underlying a2a-java SDKClientBuilderbefore theClientis constructed.The wildcard type avoids a compile-time dependency on the a2a-java SDK in this module. At runtime the value must be a
Consumer<org.a2aproject.sdk.client.ClientBuilder>.- Specified by:
clientCustomizerin interfaceA2AClientBuilder<T>- Parameters:
clientCustomizer- aConsumer<ClientBuilder>from the a2a-java SDK- Returns:
- this builder for method chaining
-
agentCardHeaders
Description copied from interface:A2AClientBuilderSets the HTTP headers used to fetch the remote agent card, for example anAuthorizationheader. The supplier is called when the card is first needed, not when the agent is built, and again if a failed fetch is retried. A successfully fetched card is cached, so the supplier is not called on every invocation. It runs on the thread fetching the card, normally a thread of the LangChain4j executor.These headers apply only to agent card discovery. Configure authentication for A2A messages separately through
A2AClientBuilder.clientCustomizer(Consumer).- Specified by:
agentCardHeadersin interfaceA2AClientBuilder<T>- Parameters:
headers- the supplier of request headers;null, or a supplier returningnullor an empty map, sends no additional headers- Returns:
- this builder for method chaining
-
resolutionTimeout
Description copied from interface:A2AClientBuilderSets the time given to the fetch of the agent card, which happens the first time the card is needed, normally on the first invocation of the agent, on a thread of the LangChain4j executor. It does not limit the messages sent to the agent. When the card is not fetched within this time the fetch is interrupted and the invocation fails with anA2AAgentCardExceptioncaused by aTimeoutException. Concurrent first invocations wait on the same fetch, so none of them waits longer than this time, and they all fail when it fails. An invocation arriving before the interrupted fetch has ended fails at once with the same timeout, and the next one after that fetches the card again. The default is 30 seconds, and a time of zero removes the limit: the card is then fetched by the first invocation needing it, on its own thread, and the fetch takes as long as the server of the agent makes it take.- Specified by:
resolutionTimeoutin interfaceA2AClientBuilder<T>- Parameters:
resolutionTimeout- the time given to the fetch of the agent card,Duration.ZEROfor no limit, ornullfor the default- Returns:
- this builder for method chaining
-
streamingClientListener
Description copied from interface:A2AClientBuilderSets anA2AStreamingClientListenerfor observing updates received from the remote agent during streaming invocation.Like
DefaultA2AClientBuilder, which usesa2a-java, can be used with the following example:streamingClientListener((TaskUpdateEvent event) -> { // handle the streaming event });The listener is invoked with task update events received from the remote agent.
- Specified by:
streamingClientListenerin interfaceA2AClientBuilder<T>- Parameters:
clientListener- the listener to attach- Returns:
- this builder for method chaining
-
setParent
- Specified by:
setParentin interfaceInternalAgent
-
registerInheritedParentListener
- Specified by:
registerInheritedParentListenerin interfaceInternalAgent
-
appendId
- Specified by:
appendIdin interfaceInternalAgent
-
listener
- Specified by:
listenerin interfaceInternalAgent
-
type
- Specified by:
typein interfaceAgentInstance
-
plannerType
- Specified by:
plannerTypein interfaceAgentInstance
-
name
The name is always known locally, without fetching the agent card: it is the explicit one, else the one of the annotation of the agent method, else the name of that method for a typed agent, else a placeholder derived from the A2A server URL. It never changes afterwards, not even when the card is fetched, because the agent id is derived from it.- Specified by:
namein interfaceAgentInstance
-
agentId
- Specified by:
agentIdin interfaceAgentInstance
-
description
The explicit description, else the one of the agent card, which is fetched at this point if not yet done.- Specified by:
descriptionin interfaceAgentInstance
-
outputType
- Specified by:
outputTypein interfaceAgentInstance
-
outputKey
- Specified by:
outputKeyin interfaceAgentInstance
-
async
public boolean async()- Specified by:
asyncin interfaceAgentInstance
-
activationCondition
Description copied from interface:AgentInstanceThe condition under which this agent runs when it is invoked as a subagent, ornullwhen it always runs. When the condition is false, the agent is skipped: it is not invoked, it writes nothing to theAgenticScopeand its parent's planner is notified of the skip. The condition is ignored when the agent is invoked directly, as the root of an agentic system.The condition can be evaluated more than once for a single invocation, by the planner of the parent while selecting its next agents and again when the agent is invoked, so it must be cheap and free of side effects.
- Specified by:
activationConditionin interfaceAgentInstance
-
arguments
- Specified by:
argumentsin interfaceAgentInstance
-
parent
- Specified by:
parentin interfaceAgentInstance
-
subagents
- Specified by:
subagentsin interfaceAgentInstance
-
topology
- Specified by:
topologyin interfaceAgentInstance
-
tenant
Description copied from interface:A2AClientBuilderSets the tenant identifier that will be sent with every A2A message.- Specified by:
tenantin interfaceA2AClientBuilder<T>- Parameters:
tenant- the tenant identifier- Returns:
- this builder for method chaining
-