Class PlannerAgent
java.lang.Object
com.google.adk.workflow.BaseNode
com.google.adk.agents.BaseAgent
com.google.adk.agents.PlannerAgent
- All Implemented Interfaces:
Node
一种将执行计划任务委托给其他系统的代理(agent)。
Planner strategy.
The PlannerAgent 拥有一组子代理(sub-agents)和一个规划器(planner)。在运行时,规划器会检查会话状态(session state),并决定接下来应该运行哪个(或哪些)子代理。这使得代理的协调过程变得动态且以目标为导向:执行流程是在运行时确定的,而不是在构建阶段就固定好的。
规划循环(Planning Loop):
- Planner 会根据上下文(context)以及可用的代理(available agents)进行初始化,之后就可以使用了。
- Planner 会通过某种方式返回下一步该执行的操作。
PlannerAction - 被选中的子代理(sub-agent)开始执行任务,并由此产生相应的事件(events)。
- 会话状态(即整个系统的状态)会根据发生的事件进行更新。
- 规划器会看到更新后的状态,并决定下一步该采取的行动。
- “重复执行该操作,直到……”
PlannerAction.Done或者 `maxIterations`
使用自定义计划器的示例:
PlannerAgent agent = PlannerAgent.builder()
.name("myAgent")
.subAgents(agentA, agentB, agentC)
.planner(new GoalOrientedPlanner("finalOutput", metadata))
.maxIterations(20)
.build();
-
嵌套类概述
Nested ClassesModifier and TypeClassDescriptionstatic class“Builder for”是一个用于描述某种构建工具或框架的术语。它通常表示该工具/框架用于帮助开发者或系统管理员快速、高效地创建或构建特定类型的应用程序、系统或组件。例如:“Builder for Web Applications”(用于构建Web应用程序的工具)或“Builder for Cloud Services”(用于构建云服务的工具)。PlannerAgent. -
方法概述
Modifier and TypeMethodDescriptionstatic PlannerAgent.Builderbuilder()返回一个新的对象。PlannerAgent.Builder用于创建(某些东西)PlannerAgentinstances.int返回规划迭代的最大次数。planner()返回该代理所使用的规划策略。protected io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext) 与特定代理(Agent)相关的异步逻辑(Agent-specific asynchronous logic)。protected io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext) 与特定代理相关的同步逻辑(Agent-specific synchronous logic)。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)
-
planner
返回该代理所使用的规划策略。 -
maxIterations
public int maxIterations()返回规划迭代的最大次数。 -
runAsyncImpl
protected io.reactivex.rxjava3.core.Flowable<Event> runAsyncImpl(InvocationContext invocationContext) 描述内容复制自相关类:BaseAgent与特定代理(Agent)相关的异步逻辑(Agent-specific asynchronous logic)。- Specified by:
runAsyncImplin classBaseAgent- Parameters:
invocationContext- Current invocation context.- Returns:
- stream of agent-generated events.
-
runLiveImpl
protected io.reactivex.rxjava3.core.Flowable<Event> runLiveImpl(InvocationContext invocationContext) 描述内容复制自相关类:BaseAgent与特定代理相关的同步逻辑(Agent-specific synchronous logic)。- Specified by:
runLiveImplin classBaseAgent- Parameters:
invocationContext- Current invocation context.- Returns:
- stream of agent-generated events.
-
builder
返回一个新的对象。PlannerAgent.Builder用于创建(某些东西)PlannerAgentinstances.
-