`Class Context`
java.lang.Object
com.google.adk.agents.ReadonlyContext
com.google.adk.agents.Context
- Direct Known Subclasses:
CallbackContext
在调用过程中,相关上下文信息会被传递给回调函数、工具以及工作流节点。
代理(Agent)和模型(Model)的回调函数会接收到某些数据或信息。 CallbackContext以及工具和工具回调函数(a)
ToolContext;这两个类都继承自同一个基类,因此可以创建一个能够同时为这两个类提供帮助的辅助工具(helper),或者是一个能够为这两个类提供功能支持的函数(function tool)。 toolContext 该参数可以接受一个值(即参数可以有一个输入)。 Context. requestConfirmation() 需要一个函数调用 ID(Function Call ID),而这个 ID 只存在于工具调用(Tool Call)中。 requireNodeState() 其他工作流节点的方法需要工作流节点的上下文信息(即该节点所处的工作流环境及其相关数据)。
-
字段摘要
FieldsFields inherited from class ReadonlyContext
invocationContext -
构造函数概述
ConstructorsConstructorDescriptionContext(InvocationContext invocationContext, NodeExecutionState nodeState) 创建工作流节点运行的上下文环境;该节点的状态为(此处应填写具体的状态信息)。nodeState. -
方法概述
Modifier and TypeMethodDescriptionactions()返回相同的结果。EventActionsaseventActions().final int返回该工作流节点当前所处的尝试次数(从 1 开始计数);每次重试都会使尝试次数增加 1。final void发送event从这个工作流节点的……FunctionNode在之前的调用之后、以及输出结果之前,该内容会被显示在 `body` 部分中。final voidemit(com.google.genai.types.Content message) 发送message作为一个没有输出结果的事件……emit(Event)does.返回EventActions与这个上下文相关联。final String返回此工作流节点所触发事件的作者信息;如果未找到相关作者信息,则返回空字符串(此时可以使用该节点的名称作为默认显示内容)。final voideventAuthor(String eventAuthor) 用于设置此工作流节点所生成的事件的作者信息。eventId()返回与此上下文相关联的事件的 ID;如果不存在此类事件,则返回 null。如果存在的话,该函数会返回调用当前工具的函数调用的 ID。voidfunctionCallId(@Nullable String functionCallId) 设置调用当前工具的函数调用的 ID;如果该 ID 为 `null`,则将其清除。列出当前会话中附加的所有工件的文件名。io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part> loadArtifact(String filename) 从服务中加载该“工件”(artifact)的最新版本。io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part> loadArtifact(String filename, int version) 从服务中加载某个特定版本的工件(artifact)。output()返回此工作流节点的输出结果;该输出结果实际上是由该节点内部执行的操作所产生的最终结果。useAsOutput如果该子对象包含某个值,则返回该值;如果该子对象不包含任何值,则返回空字符串(即 “”)。void请求确认当前的函数调用是否成功(即是否已经执行完毕)。voidrequestConfirmation(@Nullable String hint) 请求确认当前的函数调用是否成功(即是否已经执行完毕)。voidrequestConfirmation(@Nullable String hint, @Nullable Object payload) 请求确认当前的函数调用是否成功(即是否已经执行完毕)。final NodeExecutionState返回该工作流节点所处的状态;该节点属于当前上下文(context)所管理的流程。返回用户对该工作流节点或其子节点在之前阶段发出的输入请求以及长时间运行的调用的响应结果;这些响应结果是根据中断 ID 进行分类的。routes()返回此工作流节点所选择的路由;如果没有做出任何路由决策,则返回空值。final void选择该工作流节点的路由(即决定数据应通过哪些路径进行传输),从而取代之前的所有路由设置。final io.reactivex.rxjava3.core.Maybe<Object> 运行node作为这个工作流节点的“子节点”(即没有输入参数的节点),其行为如下:runNode(Node, Object, RunNodeConfig)这与默认设置有关。RunNodeConfig.final io.reactivex.rxjava3.core.Maybe<Object> 运行node作为该工作流节点的“子节点”(即该节点所依赖的另一个节点),runNode(Node, Object, RunNodeConfig)这与默认设置有关。RunNodeConfig.final io.reactivex.rxjava3.core.Maybe<Object> runNode(Node node, @Nullable Object nodeInput, RunNodeConfig config) 返回一个Maybe也就是说,一旦用户订阅了该服务,相关程序就会自动运行。node作为该工作流程的一部分(即作为该流程中的一个节点),该节点会输出该节点自身的处理结果;如果该节点没有任何需要处理的数据或任务,那么它将输出空内容(即没有任何输出)。io.reactivex.rxjava3.core.CompletablesaveArtifact(String filename, com.google.genai.types.Part artifact) 保存一个“工件”(artifact),并将其记录为当前会话的变更数据(即“差异信息”或“delta”)。io.reactivex.rxjava3.core.Single<SearchMemoryResponse> searchMemory(String query) 搜索当前用户的内存数据。state()返回当前上下文的“delta-aware”(即能够感知变化)状态。如果当前工具调用成功(即产生了预期的结果),则返回相应的确认信息。voidtoolConfirmation(@Nullable ToolConfirmation toolConfirmation) 用于设置当前工具调用的确认状态;如果该值为 `null`,则会清除确认状态。Methods inherited from class ReadonlyContext
agentName, branch, events, invocationContext, invocationId, sessionId, userContent, userId
-
字段详情
-
eventActions
用于记录该上下文变化的事件操作(event actions)。
-
-
构造函数详细信息
-
Context
创建工作流节点运行的上下文环境;该节点的状态为(此处应填写具体的状态信息)。nodeState只有工作流运行时(workflow runtime)才会创建节点状态(node state)。
-
-
方法详细信息(Method Details)
-
state
-
eventActions
返回EventActions与这个上下文相关联。 -
actions
返回相同的结果。EventActionsaseventActions(). -
eventId
返回与此上下文相关联的事件的 ID;如果不存在此类事件,则返回 null。 -
functionCallId
-
functionCallId
设置调用当前工具的函数调用的 ID;如果该 ID 为 `null`,则将其清除。 -
toolConfirmation
如果当前工具调用成功(即产生了预期的结果),则返回相应的确认信息。 -
toolConfirmation
用于设置当前工具调用的确认状态;如果该值为 `null`,则会清除确认状态。 -
listArtifacts
-
loadArtifact
从服务中加载该“工件”(artifact)的最新版本。 -
loadArtifact
public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part> loadArtifact(String filename, int version) 从服务中加载某个特定版本的工件(artifact)。 -
saveArtifact
public io.reactivex.rxjava3.core.Completable saveArtifact(String filename, com.google.genai.types.Part artifact) 保存一个“工件”(artifact),并将其记录为当前会话的变更数据(即“差异信息”或“delta”)。- Parameters:
filename- Artifact file name.artifact- Artifact content to save.- Returns:
- a
Completablethat completes when the artifact is saved. - Throws:
IllegalStateException- if the artifact service is not initialized.
-
requestConfirmation
请求确认当前的函数调用是否成功(即是否已经执行完毕)。- Parameters:
hint- A hint to the user on how to confirm the tool call.payload- The payload used to confirm the tool call.- Throws:
IllegalStateException- if this context has no function call ID.
-
requestConfirmation
请求确认当前的函数调用是否成功(即是否已经执行完毕)。- Parameters:
hint- A hint to the user on how to confirm the tool call.- Throws:
IllegalStateException- if this context has no function call ID.
-
requestConfirmation
public void requestConfirmation()请求确认当前的函数调用是否成功(即是否已经执行完毕)。- Throws:
IllegalStateException- if this context has no function call ID.
-
searchMemory
搜索当前用户的内存数据。 -
requireNodeState
返回该工作流节点所处的状态;该节点属于当前上下文(context)所管理的流程。- Throws:
IllegalStateException- if this is not the context of a workflow node.
-
eventAuthor
返回此工作流节点所触发事件的作者信息;如果未找到相关作者信息,则返回空字符串(此时可以使用该节点的名称作为默认显示内容)。- Throws:
IllegalStateException- if this is not the context of a workflow node.
-
eventAuthor
用于设置此工作流节点所生成的事件的作者信息。- Throws:
IllegalStateException- if this is not the context of a workflow node.
-
output
返回此工作流节点的输出结果;该输出结果实际上是由该节点内部执行的操作所产生的最终结果。useAsOutput如果该子对象包含某个值,则返回该值;如果该子对象不包含任何值,则返回空字符串(即 “”)。- Throws:
IllegalStateException- if this is not the context of a workflow node.
-
routes
返回此工作流节点所选择的路由;如果没有做出任何路由选择,则返回空列表。空列表表示“未选择任何路由”的状态。- Throws:
IllegalStateException- if this is not the context of a workflow node.
-
routes
选择该工作流节点的路由(即决定数据应通过哪些路径进行传输),从而取代之前的所有路由设置。- Throws:
IllegalStateException- if this is not the context of a workflow node.
-
resumeInputs
该函数返回用户对该工作流节点或其子节点在之前阶段发出的输入请求以及长时间运行的调用的响应结果,这些响应结果是根据中断 ID 进行分类的。当工作流节点重新启动(即进入 “resume” 状态)时,会读取这些响应数据。如果某个请求没有收到任何响应,那么在映射(map)中对应的值将为 `null`。- Throws:
IllegalStateException- if this is not the context of a workflow node.
-
attemptCount
返回该工作流节点当前所处的尝试次数(从 1 开始计数);每次重试都会使尝试次数增加 1。- Throws:
IllegalStateException- if this is not the context of a workflow node.
-
emit
发送event从这个工作流节点的……FunctionNode`body`:在之前的调用事件之后、输出结果之前执行。当程序运行完成并已将相关事件数据存储起来并传递给调用者时,`body` 会被执行一次;`body` 中的任何线程都可以调用该函数。Runner那个负责执行任务的节点需要被设置为 `inline` 类型。FunctionNode.Builder#scheduler那些不符合要求的选项(例如……)。Schedulers.io(). TheFunctionNode文档中规定了状态(state)、线程(threads)、事件(events)、取消操作(cancellation)以及恢复操作(resumes)的相关规则。- Throws:
IllegalArgumentException- ifeventhas an output, or has the ID of an event anotheremitcall still waits onIllegalStateException- if noFunctionNodebody of this node is runningCancellationException- if the node is canceled, or the calling thread is interrupted while this call waits; the thread stays interrupted
-
emit
发送message作为一个没有输出结果的事件……emit(Event)does. -
runNode
运行node作为这个工作流节点的“子节点”(即没有输入参数的节点),其行为如下:runNode(Node, Object, RunNodeConfig)这与默认设置有关。RunNodeConfig. -
runNode
@Experimental public final io.reactivex.rxjava3.core.Maybe<Object> runNode(Node node, @Nullable Object nodeInput) 运行node作为该工作流节点的“子节点”(即该节点所依赖的另一个节点),runNode(Node, Object, RunNodeConfig)这与默认设置有关。RunNodeConfig.- Throws:
IllegalArgumentException- ifnodeInputis aRunNodeConfig, which belongs in the three-argument overload.
-
runNode
@Experimental public final io.reactivex.rxjava3.core.Maybe<Object> runNode(Node node, @Nullable Object nodeInput, RunNodeConfig config) 返回一个Maybe也就是说,一旦用户订阅了该服务,相关程序就会自动运行。node作为该工作流程中的一个子节点,该节点会输出子节点的处理结果;如果子节点没有输出结果,则会返回空值。请将该节点包含在主节点的 `run` 配置中。当子节点正在等待处理结果时,主节点也会继续执行其自身的任务。Maybe由于内部错误而失败。Error这样一来,这个节点也会等待(即它的执行会被延迟)。catch (Exception e)虽然可以“通过”(即允许某些东西通过),但实际上……catch (Throwable t)以及 Rx 错误处理程序(如……)onErrorResumeNextstop.这个操作会失败(即无法完成预期的任务)。
DynamicNodeFailedException如果孩子失败了……IllegalStateException如果这不是工作流节点的上下文(即如果当前上下文不属于该工作流节点),那么……Node.rerunOnResume()如果该值为 `false`,或者……config该节点会将其已经拥有的输出结果,或者已经委托给其他节点的输出结果,再次委托出去;同时……IllegalArgumentException如果孩子的名字无法构成一个节点路径(即无法被用于表示文件或目录的路径),则……
-