类:SequentialAgent
java.lang.Object
com.google.adk.workflow.BaseNode
com.google.adk.agents.BaseAgent
com.google.adk.agents.SequentialAgent
- All Implemented Interfaces:
Node
一个依次运行其子代理的代理程序。
与……的组合(或搭配) LlmAgents: a SequentialAgent 不会将控制权返回给父进程(或父对象)。 LlmAgent将其作为根节点(root node)或被传输给代理的节点(agent node),并在此节点上放置任何后续操作(follow-up actions)。 LlmAgent 作为下一个“成员”(即下一个被处理的元素),上游系统会通过相应的渠道进行数据发布。 outputKey 以及
通过下游读取(data) {key} 其指令中的占位符(placeholders in its instruction):
var draft =
LlmAgent.builder()
.name("draft")
.model("gemini-flash-latest")
.instruction("Draft a summary.")
.outputKey("draft")
.build();
var reviewer =
LlmAgent.builder()
.name("reviewer")
.model("gemini-flash-latest")
.instruction("Polish the draft: {draft}")
.build();
var pipeline =
SequentialAgent.builder().name("pipeline").subAgents(draft, reviewer).build();
-
嵌套类概述
Nested ClassesModifier and TypeClassDescriptionstatic class“Builder for”是一个用于描述某种构建工具或框架的术语。它通常表示该工具/框架用于帮助开发者或系统管理员快速、高效地创建或构建特定类型的应用程序、系统或组件。例如:“Builder for Web Applications”(用于构建Web应用程序的工具)或“Builder for Cloud Services”(用于构建云服务的工具)。SequentialAgent. -
方法概述
Modifier and TypeMethodDescriptionstatic SequentialAgent.Builderbuilder()static SequentialAgentfromConfig(SequentialAgentConfig config, String configAbsPath) 根据配置创建一个 SequentialAgent 对象。protected io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext) 按顺序运行子代理(sub-agents)。protected io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext) 在实时模式下,按顺序依次运行子代理(sub-agents)。Methods inherited from class BaseAgent
afterAgentCallback, beforeAgentCallback, canonicalAfterAgentCallbacks, canonicalBeforeAgentCallbacks, close, findAgent, findSubAgent, fromConfig, parentAgent, parentAgent, rootAgent, runAsync, runLive, runNode, subAgents, toolOriginModifier and TypeMethodDescriptioncom.google.common.collect.ImmutableList<? extends Callbacks.AfterAgentCallback> com.google.common.collect.ImmutableList<? extends Callbacks.BeforeAgentCallback> com.google.common.collect.ImmutableList<? extends Callbacks.AfterAgentCallback> `afterAgentCallback` 字段的返回值是一个列表。com.google.common.collect.ImmutableList<? extends Callbacks.BeforeAgentCallback> `beforeAgentCallback` 字段解析后的结果以列表形式返回。io.reactivex.rxjava3.core.Completableclose()关闭所有子代理(sub-agents)。根据名称查找某个代理(该代理本身或其子代理)。findSubAgent(String name) 通过名称递归地搜索子代理(sub-agent)。static BaseAgentfromConfig(BaseAgentConfig config, String configAbsPath) 根据一个配置对象创建一个新的代理实例。从代理树中检索父代理。protected voidparentAgent(BaseAgent parentAgent) 用于设置父代理(即负责管理其他代理的代理)。通过向上遍历父代理链,返回该代理的根代理。io.reactivex.rxjava3.core.Flowable<Event> runAsync(InvocationContext parentContext) 异步运行代理程序。io.reactivex.rxjava3.core.Flowable<Event> runLive(InvocationContext parentContext) 同步运行代理程序。io.reactivex.rxjava3.core.Flowable<Event> 将该代理作为工作流中的一个节点来运行,并将其部署在该节点的分支上;这样,后续的节点就能够接收到该代理产生的事件(即数据或信号)。当该代理被用作工具时,该方法会返回该工具的来源信息。Methods inherited from class BaseNode
config, description, inputSchema, name, outputSchema, rerunOnResume, stateSchema, validateOutgoingEdges, waitForOutputModifier and TypeMethodDescriptionconfig()返回该节点的重试策略(retry policy)和执行超时时间(execution timeout)。该函数会返回节点的具体功能或行为,这些信息既适用于人类用户,也适用于可能调用该节点的模型(即那些需要使用该节点功能的系统或应用程序)。Optional<com.google.genai.types.Schema> 返回该节点的输入数据必须匹配的规范(即数据结构或格式)。final Stringname()返回用于标识该节点在其图中的名称。Optional<com.google.genai.types.Schema> 返回一个规范(schema),该规范要求节点的输出值必须符合这个规范的要求。boolean返回值true如果一个被恢复的节点重新从头开始运行,那么它并不会输出“恢复成功”的结果,而是会继续执行之前的操作。Optional<com.google.genai.types.Schema> 返回用于描述该节点所使用的状态键(state keys)的架构(schema)。protected voidvalidateOutgoingEdges(Collection<Edge> edges) 抛出异常(或错误)GraphValidationException如果这个节点无法提供服务(即无法完成其预定的功能或任务),那么就需要寻找其他节点来替代它。edges这些因素会“留下”某些东西(例如:用于生成某种路径的边缘信息),但这些路径实际上永远不会被真正生成(即:这些边缘信息永远不会被用于实际的路由计算中)。boolean返回值true如果某个节点在产生输出或确定路由之前仍然可以被重新触发(即可以继续被执行),那么它就不会在自身执行完成后立即停止运行。Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Node
requiresAllPredecessorsModifier and TypeMethodDescriptiondefault boolean返回值true如果该节点仅在所有前置节点都完成执行后才会被运行,并且会接收所有以节点名称为键的前置节点的输出结果(就像一个“扇入型”节点一样)。
-
方法详细信息(Method Details)
-
builder
-
runAsyncImpl
protected io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext) 按顺序运行子代理(sub-agents)。共有三种模式: 1. **支持恢复功能**:当该功能启用时,系统会快速将执行流程恢复到之前设置的检查点(即子代理的暂停位置);对于长时间运行的任务,系统会在暂停处继续执行。 2. **使用已弃用的“shim”机制**:虽然该机制仍能实现类似的功能,但恢复点会从历史记录中重新计算,且不会自动保存任何检查点数据。 3. **不使用任何恢复/暂停机制**:在这种情况下,子代理会按顺序依次执行。
- Specified by:
runAsyncImplin classBaseAgent- Parameters:
invocationContext- Invocation context.- Returns:
- Flowable emitting events from sub-agents.
-
runLiveImpl
protected io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext) 在实时模式下,按顺序依次运行子代理(sub-agents)。- Specified by:
runLiveImplin classBaseAgent- Parameters:
invocationContext- Invocation context.- Returns:
- Flowable emitting events from sub-agents in live mode.
-
fromConfig
public static SequentialAgent fromConfig(SequentialAgentConfig config, String configAbsPath) throws ConfigAgentUtils.ConfigurationException 根据配置创建一个 SequentialAgent 对象。- Parameters:
config- the agent configurationconfigAbsPath- The absolute path to the agent config file.- Returns:
- the configured SequentialAgent
- Throws:
ConfigAgentUtils.ConfigurationException- if the configuration is invalid
-