Interface A2AClientBuilder<T>

Type Parameters:
T - the agent service interface type
All Known Implementing Classes:
DefaultA2AClientBuilder

public interface A2AClientBuilder<T>
Builder for creating A2A client proxies that communicate with remote agents over the Agent-to-Agent (A2A) protocol.
  • Method Details

    • name

      default A2AClientBuilder<T> name(String name)
      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. 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.
      Parameters:
      name - the name of the agent, ignored when null or blank
      Returns:
      this builder for method chaining
    • description

      default A2AClientBuilder<T> description(String description)
      Sets 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 to AgentInstance.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.
      Parameters:
      description - the description of the agent, ignored when null or blank
      Returns:
      this builder for method chaining
    • inputKeys

      A2AClientBuilder<T> inputKeys(String... inputKeys)
      Sets the state keys whose values will be sent as message parts to the remote agent.
      Parameters:
      inputKeys - the names of the input keys
      Returns:
      this builder for method chaining
    • outputKey

      A2AClientBuilder<T> outputKey(String outputKey)
      Sets the state key under which the agent's response will be stored.
      Parameters:
      outputKey - the name of the output key
      Returns:
      this builder for method chaining
    • async

      A2AClientBuilder<T> async(boolean async)
      Sets 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.

      Parameters:
      async - true for asynchronous invocation
      Returns:
      this builder for method chaining
    • listener

      A2AClientBuilder<T> listener(AgentListener agentListener)
      Sets an AgentListener for observing agent invocations.
      Parameters:
      agentListener - the listener to attach
      Returns:
      this builder for method chaining
    • activationCondition

      default A2AClientBuilder<T> activationCondition(Predicate<AgenticScope> activationCondition)
      Sets 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.
      Parameters:
      activationCondition - the predicate deciding whether the agent runs
      Returns:
      this builder for method chaining
    • activationCondition

      A2AClientBuilder<T> 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. 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.
      Parameters:
      description - a human-readable description of the condition, used in logs, listeners and reports
      activationCondition - the predicate deciding whether the agent runs
      Returns:
      this builder for method chaining
    • clientCustomizer

      A2AClientBuilder<T> clientCustomizer(Consumer<?> clientCustomizer)
      Sets a customizer that will be applied to the underlying a2a-java SDK ClientBuilder before the Client is 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>.

      Parameters:
      clientCustomizer - a Consumer<ClientBuilder> from the a2a-java SDK
      Returns:
      this builder for method chaining
    • streamingClientListener

      A2AClientBuilder<T> streamingClientListener(A2AStreamingClientListener<?> clientListener)
      Sets an A2AStreamingClientListener for observing updates received from the remote agent during streaming invocation.

      Like DefaultA2AClientBuilder, which uses a2a-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.

      Parameters:
      clientListener - the listener to attach
      Returns:
      this builder for method chaining
    • tenant

      default A2AClientBuilder<T> tenant(String tenant)
      Sets the tenant identifier that will be sent with every A2A message.
      Parameters:
      tenant - the tenant identifier
      Returns:
      this builder for method chaining
    • resolutionTimeout

      default A2AClientBuilder<T> 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. 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 an A2AAgentCardException caused by a TimeoutException. 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.
      Parameters:
      resolutionTimeout - the time given to the fetch of the agent card, Duration.ZERO for no limit, or null for the default
      Returns:
      this builder for method chaining
      Throws:
      IllegalArgumentException - if the time is negative
      Since:
      1.24.0
    • build

      T build()
      Builds the A2A client proxy implementing the agent service interface.
      Returns:
      the proxy instance