`Class EventConverter`
java.lang.Object
com.google.adk.a2a.converters.EventConverter
该工具用于将 ADK 事件转换为 A2A 消息。
-
字段摘要
Fields -
方法概述
Modifier and TypeMethodDescriptionstatic com.google.common.collect.ImmutableList<io.a2a.spec.Part<?>> answerParts(List<Event> events) 返回用户回答中的相关部分,以便将这些部分发送给处理该用户呼叫的远程代理。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 EventfindUserFunctionCall(List<Event> events) 返回最后一个事件中第一个非凭据相关函数响应所对应的调用事件。static com.google.common.collect.ImmutableList<io.a2a.spec.Part<?>> messagePartsFromContext(InvocationContext context) 从上下文事件中提取出应该发送给代理(agent)的数据部分。static String从事件中返回任务 ID。
-
字段详情
-
ADK_TASK_ID_KEY
Deprecated.UseAdkMetadataKey.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.UseAdkMetadataKey.CONTEXT_ID.getType(), the key context IDs are recorded under.“Legacy context ID”键:仅适用于那些既没有特定“Event Type”(事件类型),也没有其他相关信息的事件;该键仅具有读取权限(read-only)。a2a:ID 键。- See Also:
-
-
方法详细信息(Method Details)
-
taskId
从事件中返回任务 ID。任务 ID 存储在事件的自定义元数据中(具体位置需根据实际情况确定)。
a2a:task_id……其中ResponseConverter“and ADK Python write it.” 这个事件既不属于前者(ADK),也不属于后者(Python)。a2a:task_idnora2a:context_id数据是从旧系统(legacy system)中读取的。adk_task_idkey.- Parameters:
event- The event to get the task ID from.- Returns:
- The task ID, or an empty string if not found.
-
contextId
从事件中返回上下文 ID(context ID)。上下文 ID(Context ID)存储在事件的自定义元数据中(位于该元数据的相应位置)。
a2a:context_id……其中ResponseConverter“and ADK Python write it.” 这个事件既不属于前者(ADK),也不属于后者(Python)。a2a:task_idnora2a:context_id数据是从旧系统(legacy system)中读取的。adk_context_idkey.- Parameters:
event- The event to get the context ID from.- Returns:
- The context ID, or an empty string if not found.
-
findUserFunctionCall
-
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.
-
AdkMetadataKey.CONTEXT_ID.getType()关键上下文 ID 被记录在下方。