`Class EventConverter`

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

public final class EventConverter extends Object
该工具用于将 ADK 事件转换为 A2A 消息。
  • 字段摘要

    Fields
    Modifier and Type
    Field
    Description
    static final String
    已弃用(Deprecated)。
    使用 AdkMetadataKey.CONTEXT_ID.getType()关键上下文 ID 被记录在下方。
    static final String
    已弃用(Deprecated)。
    使用 AdkMetadataKey.TASK_ID.getType()关键任务 ID 被记录在下方。
  • 方法概述

    Modifier and Type
    Method
    Description
    static com.google.common.collect.ImmutableList<io.a2a.spec.Part<?>>
    返回用户回答中的相关部分,以便将这些部分发送给处理该用户呼叫的远程代理。
    static com.google.common.collect.ImmutableList<io.a2a.spec.Part<?>>
    contentToParts(Optional<com.google.genai.types.Content> content, boolean isPartial)
    将一个 GenAI 内容对象转换为 A2A 部件(Parts)的列表。
    static String
    从事件中返回上下文 ID(context ID)。
    static @Nullable Event
    返回最后一个事件中第一个非凭据相关函数响应所对应的调用事件。
    static com.google.common.collect.ImmutableList<io.a2a.spec.Part<?>>
    从上下文事件中提取出应该发送给代理(agent)的数据部分。
    static String
    taskId(Event event)
    从事件中返回任务 ID。

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详情

    • 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”键:仅用于那些既没有“start_time”也没有“end_time”字段的事件;该键仅具有读取权限(read-only)。 a2a: ID 键。
      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”键:仅适用于那些既没有特定“Event Type”(事件类型),也没有其他相关信息的事件;该键仅具有读取权限(read-only)。 a2a: ID 键。
      See Also:
  • 方法详细信息(Method Details)

    • taskId

      public static String taskId(Event event)
      从事件中返回任务 ID。

      任务 ID 存储在事件的自定义元数据中(具体位置需根据实际情况确定)。 a2a:task_id……其中 ResponseConverter “and ADK Python write it.” 这个事件既不属于前者(ADK),也不属于后者(Python)。 a2a:task_id nor a2a:context_id 数据是从旧系统(legacy system)中读取的。 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)
      从事件中返回上下文 ID(context ID)。

      上下文 ID(Context ID)存储在事件的自定义元数据中(位于该元数据的相应位置)。 a2a:context_id……其中 ResponseConverter “and ADK Python write it.” 这个事件既不属于前者(ADK),也不属于后者(Python)。 a2a:task_id nor a2a:context_id 数据是从旧系统(legacy system)中读取的。 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)
      返回最后一个事件中第一个非凭据相关函数响应所对应的调用事件。
      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)
      该函数会返回用户回答中的部分内容,以便将这些内容发送给处理该用户请求的远程代理。 用户的凭证信息(如用户名、密码等)永远不会被发送;同时,函数响应中包含的任何文本也不会被发送——因为 ADK 运行器会拒绝接收这些文本。
      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)
      将一个 GenAI 内容对象转换为 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)
      从上下文事件中提取出应该发送给代理(agent)的数据部分。

      所有来自上一个远程代理的会话事件(或者,在首次调用代理的情况下,从会话开始时的事件)都会被包含在 A2A 消息中。其他代理产生的事件则会被视为用户消息,并以用户正在描述会话中发生的事情的形式呈现出来;不过这些消息中的身份验证信息(即凭证数据)会被省略掉。

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