`LlmAgent` 类
java.lang.Object
com.google.adk.workflow.BaseNode
com.google.adk.agents.BaseAgent
com.google.adk.agents.LlmAgent
- All Implemented Interfaces:
Node
这个基于大型语言模型(LLM)的智能代理。
-
嵌套类概述
Nested ClassesModifier and TypeClassDescriptionstatic class“Builder for”是一个用于描述某种构建工具或框架的术语。它通常表示该工具/框架用于帮助开发者或系统管理员快速、高效地创建或构建特定类型的应用程序、系统或组件。例如:“Builder for Web Applications”(用于构建Web应用程序的工具)或“Builder for Cloud Services”(用于构建云服务的工具)。LlmAgent.static enum这是一个枚举类型(Enum),用于决定是否应在向底层大语言模型(LLM)发送的请求中包含之前事件的内容。 -
构造函数概述
Constructors -
方法概述
Modifier and TypeMethodDescriptionList<? extends Callbacks.AfterModelCallback> List<? extends Callbacks.AfterToolCallback> List<? extends Callbacks.BeforeModelCallback> List<? extends Callbacks.BeforeToolCallback> static LlmAgent.Builderbuilder()返回一个LlmAgent.BuilderforLlmAgent.List<? extends Callbacks.AfterModelCallback> `afterModelCallback` 字段的返回值是一个列表。List<? extends Callbacks.AfterToolCallback> `afterToolCallback` 字段的值被解析为一个列表。List<? extends Callbacks.BeforeModelCallback> `beforeModelCallback` 字段的解析结果以列表的形式返回。List<? extends Callbacks.BeforeToolCallback> `beforeToolCallback` 字段的解析结果以列表的形式返回。根据……为该代理构建全局文本指令。globalInstruction`field`。canonicalInstruction(ReadonlyContext context) 根据……为该代理构建文本指令。instruction`field`。List<? extends Callbacks.OnModelErrorCallback> `modelErrorCallback` 字段的值被解析为一个列表。List<? extends Callbacks.OnToolErrorCallback> `onToolErrorCallback` 字段的值被解析为一个列表。io.reactivex.rxjava3.core.Flowable<BaseTool> 根据……构建该代理所需的工具列表。tools()`field`。io.reactivex.rxjava3.core.Flowable<BaseTool> canonicalTools(@Nullable ReadonlyContext context) 根据……构建该代理所需的工具列表。tools()`field`。io.reactivex.rxjava3.core.Completableclose()关闭所有子代理(sub-agents)。protected BaseLlmFlowbooleanbooleanexecutor()static LlmAgentfromConfig(LlmAgentConfig config, String configAbsPath) 根据配置创建一个 LLMAgent,该 LLMAgent 支持完整的子代理功能(full subagent support)。Optional<com.google.genai.types.GenerateContentConfig> 返回已配置的历史记录设置。LlmAgent.IncludeContents.DEFAULT当该属性未被设置时(即其值为 `undefined` 时)。boolean返回一个布尔值,表示是否……LlmAgent.Builder.includeContents(IncludeContents)该值已被设置为 “a”。SINGLE_TURN工作流节点会使用该选项,而不是在没有任何记录(即“历史数据”)的情况下直接运行程序。Optional<com.google.genai.types.Schema> 返回该节点的输入数据必须匹配的规范(即数据结构或格式)。maxSteps()mode()该参数用于指示该代理在作为工作流节点运行时的对话方式;如果没有指定具体的对话模式,则返回空值。model()List<? extends Callbacks.OnModelErrorCallback> List<? extends Callbacks.OnToolErrorCallback> Optional<com.google.genai.types.Schema> 返回一个规范(schema),该规范要求节点的输出值必须符合这个规范的要求。booleanplanning()boolean返回值true这样,当工作流程重新使用该代理作为节点时,它就会再次执行该代理;同时,该代理的模型也会收到其长时间执行的请求所获得的响应结果。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)。io.reactivex.rxjava3.core.Flowable<Event> 将此代理作为工作流节点来运行。tools()toolsets()Methods inherited from class BaseAgent
afterAgentCallback, beforeAgentCallback, canonicalAfterAgentCallbacks, canonicalBeforeAgentCallbacks, findAgent, findSubAgent, fromConfig, parentAgent, parentAgent, rootAgent, runAsync, runLive, 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` 字段解析后的结果以列表形式返回。根据名称查找某个代理(该代理本身或其子代理)。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) 同步运行代理程序。当该代理被用作工具时,该方法会返回该工具的来源信息。Methods inherited from class BaseNode
config, description, name, stateSchema, validateOutgoingEdges, waitForOutputModifier and TypeMethodDescriptionconfig()返回该节点的重试策略(retry policy)和执行超时时间(execution timeout)。该函数会返回节点的具体功能或行为,这些信息既适用于人类用户,也适用于可能调用该节点的模型(即那些需要使用该节点功能的系统或应用程序)。final Stringname()返回用于标识该节点在其图中的名称。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如果该节点仅在所有前置节点都完成执行后才会被运行,并且会接收所有以节点名称为键的前置节点的输出结果(就像一个“扇入型”节点一样)。
-
构造函数详细信息
-
LlmAgent
-
-
方法详细信息(Method Details)
-
builder
返回一个LlmAgent.BuilderforLlmAgent. -
determineLlmFlow
-
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.
-
runNode
@Experimental public io.reactivex.rxjava3.core.Flowable<Event> runNode(Context context, @Nullable Object nodeInput) 将此代理作为工作流节点来运行。AgentMode.SINGLE_TURN代理无法查看任何历史记录(即没有相关的数据或信息),除非……LlmAgent.Builder.includeContents该节点被设置为“用户轮次”(即当前轮次由用户控制),会接收用户的输入作为输入数据,并将其生成的第一个最终模型结果作为输出结果。如果没有指定具体的“模式”(mode),该代理会以默认方式运行。BaseAgent.runNode(Context, Object)然后运行它。 -
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.
-
canonicalInstruction
public io.reactivex.rxjava3.core.Single<Map.Entry<String,Boolean>> canonicalInstruction(ReadonlyContext context) 根据……为该代理构建文本指令。instruction该字段还会返回一个布尔值,用于指示在构建相关指令时是否应跳过状态注入(state injection)操作。Instruction.Provider.此方法仅适用于代理开发工具包(Agent Development Kit)。
- Parameters:
context- The context to retrieve the session state.- Returns:
- The resolved instruction as a
Singlewrapped Map.Entry. The key is the instruction string and the value is a boolean indicating if state injection should be bypassed.
-
canonicalGlobalInstruction
public io.reactivex.rxjava3.core.Single<Map.Entry<String,Boolean>> canonicalGlobalInstruction(ReadonlyContext context) 根据……为该代理构建全局文本指令。globalInstruction该字段还会返回一个布尔值,用于指示在构建相关指令时是否应跳过状态注入(state injection)机制。Instruction.Provider.此方法仅适用于代理开发工具包(Agent Development Kit)。
- Parameters:
context- The context to retrieve the session state.- Returns:
- The resolved global instruction as a
Singlewrapped Map.Entry. The key is the instruction string and the value is a boolean indicating if state injection should be bypassed.
-
canonicalTools
-
canonicalTools
public io.reactivex.rxjava3.core.Flowable<BaseTool> canonicalTools(@Nullable ReadonlyContext context) 根据……构建该代理所需的工具列表。tools()`field`。- Parameters:
context- The context to retrieve the session state.- Returns:
- The resolved list of tools as a
Singlewrapped list ofBaseTool.
-
instruction
-
globalInstruction
-
model
-
planning
public boolean planning() -
maxSteps
-
generateContentConfig
-
includeContents
返回已配置的历史记录设置。LlmAgent.IncludeContents.DEFAULT当该属性未被设置时(即其值为 `undefined` 时),系统会使用默认值 “A”。SINGLE_TURN工作流节点会覆盖那些尚未被设置的属性/值;详情请参见……includeContentsExplicit(). -
includeContentsExplicit
返回一个布尔值,表示是否……LlmAgent.Builder.includeContents(IncludeContents)该值已被设置为 “a”。SINGLE_TURN工作流节点会使用该选项,而不是在没有任何记录(即“历史数据”)的情况下直接运行程序。此方法仅适用于代理开发工具包(Agent Development Kit)。
-
mode
该参数用于指示该代理在作为工作流节点运行时的对话方式;如果没有指定具体的对话模式,则返回空值。 -
tools
-
toolsUnion
-
toolsets
-
disallowTransferToParent
public boolean disallowTransferToParent() -
disallowTransferToPeers
public boolean disallowTransferToPeers() -
beforeModelCallback
-
afterModelCallback
-
beforeToolCallback
-
afterToolCallback
-
onModelErrorCallback
-
onToolErrorCallback
-
canonicalBeforeModelCallbacks
`beforeModelCallback` 字段的解析结果以列表的形式返回。此方法仅适用于代理开发工具包(Agent Development Kit)。
-
canonicalAfterModelCallbacks
`afterModelCallback` 字段的返回值是一个列表。此方法仅适用于代理开发工具包(Agent Development Kit)。
-
canonicalOnModelErrorCallbacks
`modelErrorCallback` 字段的值被解析为一个列表。此方法仅适用于代理开发工具包(Agent Development Kit)。
-
canonicalBeforeToolCallbacks
`beforeToolCallback` 字段的解析结果以列表的形式返回。此方法仅适用于代理开发工具包(Agent Development Kit)。
-
canonicalAfterToolCallbacks
`afterToolCallback` 字段的值被解析为一个列表。此方法仅适用于代理开发工具包(Agent Development Kit)。
-
canonicalOnToolErrorCallbacks
`onToolErrorCallback` 字段的值被解析为一个列表。此方法仅适用于代理开发工具包(Agent Development Kit)。
-
inputSchema
描述内容复制自接口文档:Node返回该节点的输入数据必须匹配的规范(即数据结构)。当某个边的源数据的输出规范中包含某个键或类型,而该节点不接受这些键或类型时,构建该边的操作将会失败。因此,像映射(map)这样的“开放型生产者”(即可以生成任意类型数据的生成器)在构建数据时可能会出现问题。FunctionNode在……的时候;当……的情况下Content`port` 检查边缘设备(edge device)与……之间的连接是否正常。Content在某种数据结构(或模式)中,如果一个节点要求其所有前置节点(predecessors)都必须满足某些条件,那么该节点会将其要求应用于每个前置节点的输出结果中,而不是应用于所有前置节点共同生成的最终结果(即“合并后的数据”)。- Specified by:
inputSchemain interfaceNode- Overrides:
inputSchemain classBaseNode
-
outputSchema
描述内容复制自接口文档:Node返回一个规范(schema),该规范规定了节点的输出值必须符合的要求。不过,作为输出的消息(message-as-output)的内容并不会被用来验证是否满足这个规范。- Specified by:
outputSchemain interfaceNode- Overrides:
outputSchemain classBaseNode
-
rerunOnResume
返回值true这样,当工作流程重新使用该代理作为节点时,它就会再次执行该代理;同时,该代理的模型也会收到其长时间执行的请求所获得的响应结果。- Specified by:
rerunOnResumein interfaceNode- Overrides:
rerunOnResumein classBaseNode
-
executor
-
outputKey
-
codeExecutor
-
resolvedModel
-
fromConfig
public static LlmAgent fromConfig(LlmAgentConfig config, String configAbsPath) throws ConfigAgentUtils.ConfigurationException 根据配置创建一个 LLMAgent,该 LLMAgent 支持完整的子代理功能(full subagent support)。- Parameters:
config- the agent configurationconfigAbsPath- The absolute path to the agent config file. This is needed for resolving relative paths for e.g. tools and subagents.- Returns:
- the configured LlmAgent
- Throws:
ConfigAgentUtils.ConfigurationException- if the configuration is invalid
-
close
-