# 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`
  `ADK_CONTEXT_ID_KEY`
  `static final String`
  `ADK_TASK_ID_KEY`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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`
  `contextId(Event event)`
  Returns the context ID from the event.
  `static @Nullable Event`
  `findUserFunctionCall(List<Event> events)`
  Returns the last user function call event from the list of events.
  `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.
  `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

    public static final String ADK_TASK_ID_KEY
    See Also:
      - Constant Field Values

  - ### ADK_CONTEXT_ID_KEY

    public static final String ADK_CONTEXT_ID_KEY
    See Also:
      - Constant Field Values

- ## 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 with the key `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 with the key `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 last user function call event from the list of events.
    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.

  - ### 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.

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