Class EventConverter

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

public final class EventConverter extends Object
Converter for ADK Events to A2A Messages.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Deprecated.
    Use AdkMetadataKey.CONTEXT_ID.getType(), the key context IDs are recorded under.
    static final String
    Deprecated.
    Use AdkMetadataKey.TASK_ID.getType(), the key task IDs are recorded under.
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.google.common.collect.ImmutableList<io.a2a.spec.Part<?>>
    Returns the parts of the user's answer to send to the remote agent whose call it answers.
    static com.google.common.collect.ImmutableList<io.a2a.spec.Part<?>>
    contentToParts(Optional<com.google.genai.types.Content> content, boolean isPartial)
    Converts a GenAI Content object to a list of A2A Parts.
    static String
    Returns the context ID from the event.
    static @Nullable Event
    Returns the call event that the last event's first non-credential function response answers.
    static com.google.common.collect.ImmutableList<io.a2a.spec.Part<?>>
    Returns the parts from the context events that should be sent to the agent.
    static String
    taskId(Event event)
    Returns the task ID from the event.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ADK_TASK_ID_KEY

      @Deprecated public static final String ADK_TASK_ID_KEY
      Deprecated.
      Use AdkMetadataKey.TASK_ID.getType(), the key task IDs are recorded under.
      Legacy task ID key, read only for events with neither a2a: ID key.
      See Also:
    • ADK_CONTEXT_ID_KEY

      @Deprecated public static final String ADK_CONTEXT_ID_KEY
      Deprecated.
      Use AdkMetadataKey.CONTEXT_ID.getType(), the key context IDs are recorded under.
      Legacy context ID key, read only for events with neither a2a: ID key.
      See Also:
  • Method Details

    • taskId

      public static String taskId(Event event)
      Returns the task ID from the event.

      Task ID is stored in the event's custom metadata under a2a:task_id, where ResponseConverter and ADK Python write it. An event with neither a2a:task_id nor a2a:context_id is read from the legacy adk_task_id key.

      Parameters:
      event - The event to get the task ID from.
      Returns:
      The task ID, or an empty string if not found.
    • contextId

      public static String contextId(Event event)
      Returns the context ID from the event.

      Context ID is stored in the event's custom metadata under a2a:context_id, where ResponseConverter and ADK Python write it. An event with neither a2a:task_id nor a2a:context_id is read from the legacy adk_context_id key.

      Parameters:
      event - The event to get the context ID from.
      Returns:
      The context ID, or an empty string if not found.
    • findUserFunctionCall

      public static @Nullable Event findUserFunctionCall(List<Event> events)
      Returns the call event that the last event's first non-credential function response answers.
      Parameters:
      events - The list of events to find the user function call event from.
      Returns:
      The user function call event, or null if not found.
    • answerParts

      @Experimental public static com.google.common.collect.ImmutableList<io.a2a.spec.Part<?>> answerParts(List<Event> events)
      Returns the parts of the user's answer to send to the remote agent whose call it answers. Credential parts are never sent, nor is text beside a function response, which an ADK runner rejects.
      Parameters:
      events - The session events, ending with the user's answer; must not be empty.
      Returns:
      The answer's parts to send, possibly none.
    • contentToParts

      public static com.google.common.collect.ImmutableList<io.a2a.spec.Part<?>> contentToParts(Optional<com.google.genai.types.Content> content, boolean isPartial)
      Converts a GenAI Content object to a list of A2A Parts.
      Parameters:
      content - The GenAI Content object to convert.
      isPartial - Whether the content is partial.
      Returns:
      A list of A2A Parts.
    • messagePartsFromContext

      public static com.google.common.collect.ImmutableList<io.a2a.spec.Part<?>> messagePartsFromContext(InvocationContext context)
      Returns the parts from the context events that should be sent to the agent.

      All session events from the previous remote agent response (or the beginning of the session in case of the first agent invocation) are included into the A2A message. Events from other agents are presented as user messages and rephased as if a user was telling what happened in the session up to the point. Credential parts are left out.

      Parameters:
      context - The invocation context to get the parts from.
      Returns:
      A list of A2A Parts.