Class ResponseConverter
java.lang.Object
com.google.adk.a2a.converters.ResponseConverter
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 Summary
Modifier and TypeMethodDescriptionstatic EventartifactToEvent(io.a2a.spec.Artifact artifact, InvocationContext invocationContext) Converts an artifact to an ADK event.clientEventToEvent(io.a2a.client.ClientEvent event, InvocationContext invocationContext) Converts a A2AClientEventto an ADKEvent, based on the event type.static EventmessageToEvent(io.a2a.spec.Message message, InvocationContext invocationContext) Converts an A2A message back to ADK events.static EventmessageToEvent(io.a2a.spec.Message message, InvocationContext invocationContext, boolean isPending) Converts an A2A message back to ADK events.static EventmessageToFailedEvent(io.a2a.spec.Message message, InvocationContext invocationContext) Converts an A2A message for a failed task to ADK event filling in the error message.static EventtaskToEvent(io.a2a.spec.Task task, InvocationContext invocationContext) Converts an A2ATaskto an ADKEventwith the parts of its artifacts and status message.
-
Method Details
-
clientEventToEvent
public static Optional<Event> clientEventToEvent(io.a2a.client.ClientEvent event, InvocationContext invocationContext) Converts a A2AClientEventto an ADKEvent, based on the event type. Returns an empty optional if the event should be ignored: a TaskArtifactUpdateEvent that is not a final update, a TaskStatusUpdateEvent with an empty message or none of whose parts convert and that does not end the turn, or a message none of whose parts convert and that reports no error code.- 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
Converts an A2ATaskto an ADKEventwith the parts of its artifacts and status message. Its metadata comes from the first artifact, then the status message, that has an event field, with keys missing there taken from the task's own metadata. A pending task with no parts gives an empty event.
-