Class ResponseConverter

java.lang.Object
com.google.adk.a2a.converters.ResponseConverter

public final class ResponseConverter extends Object
Utility for converting ADK events to A2A spec messages (and back).

Unparseable ADK metadata and unconvertible parts from a remote agent are logged and dropped; the rest of the event is still converted.

  • Method Details

    • clientEventToEvent

      public static Optional<Event> clientEventToEvent(io.a2a.client.ClientEvent event, InvocationContext invocationContext)
      Converts a A2A ClientEvent to an ADK Event, based on the event type. Returns an empty optional if the event should be ignored (e.g. if the event is not a final update for TaskArtifactUpdateEvent, if the message is empty for TaskStatusUpdateEvent, or if no part could be converted from a message or from the message of a status update that does not end the turn).
      Throws:
      IllegalArgumentException - if the event type is not supported.
    • artifactToEvent

      public static Event artifactToEvent(io.a2a.spec.Artifact artifact, InvocationContext invocationContext)
      Converts an artifact to an ADK event.
    • messageToFailedEvent

      public static Event messageToFailedEvent(io.a2a.spec.Message message, InvocationContext invocationContext)
      Converts an A2A message for a failed task to ADK event filling in the error message.
    • messageToEvent

      public static Event messageToEvent(io.a2a.spec.Message message, InvocationContext invocationContext)
      Converts an A2A message back to ADK events.
    • messageToEvent

      public static Event messageToEvent(io.a2a.spec.Message message, InvocationContext invocationContext, boolean isPending)
      Converts an A2A message back to ADK events. For streaming task in pending state it sets the thought field to true, to mark them as thought updates.
    • taskToEvent

      public static Event taskToEvent(io.a2a.spec.Task task, InvocationContext invocationContext)
      Converts an A2A Task to an ADK Event. If the artifacts are present, the last artifact is used. If not, the status message is used. If not, the last history message is used. If none of these are present, an empty event is returned.