函数工具
Represents a tool that wraps a function annotated with com.google.adk.kt.annotations.Tool, whether KSP generates it at compile time or ReflectiveTools builds it at runtime on the JVM.
The optional confirmation gate (set via the requiresConfirmation constructor parameter) makes an invocation pause for human approval before the underlying function runs:
On the first call the tool records a confirmation request via ToolContext.requestConfirmation and returns a placeholder error response without invoking the underlying function.
Once the user supplies a com.google.adk.kt.events.ToolConfirmation, the tool is re-executed: if the user confirmed it runs normally; otherwise it returns a rejection error response.
The gate has two forms:
Per-call predicate (the primary constructor): a
(args) -> Booleanis invoked on every call with the function'sargsand decides whether to gate this invocation, e.g.requiresConfirmation = { args -> (args["amount"] as Int) > 1000 }. The default value{ false }disables the gate entirely.Boolean (the secondary constructor): a constant flag that gates either every invocation (
true) or none (false). It is a thin wrapper that lifts the Boolean into a constant predicate{ value }.
构造函数(Constructors)
布尔型对象的便捷构造函数:只需传递相应的参数即可创建对象。 true 为了对每一次调用(即程序的每次执行)进行控制或管理, false 这意味着可以完全跳过某个检查点(或“关卡”),相当于直接通过该检查点而不需要任何验证或处理。 { requiresConfirmation } 传递给主构造函数(primary constructor)。
属性(Properties)
在运行过程中,如何将该工具的信息传递给模型: Behavior.NON_BLOCKING 让模型在通话未完成期间继续维持对话的进行。 Behavior.BLOCKING 会使其等待响应的到来; null 或者 Behavior.UNSPECIFIED 保持工具声明的原有内容;需要覆盖该声明时,请使用相应的代码进行替换。 Behavior.NON_BLOCKING “on a tool whose”这个短语的意思是“在某个工具上;使用某个工具来进行某件事”。这里的“tool”可以指任何工具或设备,例如电脑、手机、工具箱等。整个短语用来描述使用某个工具来完成某个特定的任务或操作。 运行;执行 该方法返回一个名为 “Flow” 的工具;这个工具在开始实时运行之前会先完成自身的执行过程,之后才会开始读取模型中的下一条消息。 com.google.adk.kt.annotations.Tool 一个返回 `Flow` 对象的函数…… BasePublisherTool如果不进行相应的设置,该操作会被声明为“非阻塞”(即不会阻塞程序的执行)。
该工具的自定义元数据。
该工具的描述。
该工具的最终结果是否将通过非正式(即非官方)渠道进行交付?具体时间是什么时候? true该框架会将此调用标记为“长时间运行的操作”,并使用该工具返回的值作为函数的响应数据(即函数返回的结果)。 Unit “means ‘尚未收到任何响应’”:FR(Function Request)事件被抑制了,因此函数调用事件(该事件会携带调用 ID)也无法被正常处理。 longRunningToolIds 因此,这轮游戏的最终响应就是该轮的结束(即游戏流程的终止),此时模型不会被重新调用(即不会再次执行任何计算或处理任务)。Unit `return` – 包括一个显式的空值(即不返回任何内容)。 Map -- 会被视为一个真实的响应结果,并被发送出去。Unit 这种抑制机制与 Python 的实现方式一致;而 Java 则总是会发出相应的错误信息(或警告)。 {}.) The longRunningToolIds 该 ID 还用于控制“可恢复模式”(resumable-mode)下的暂停功能;这样,后续就可以通过用户提供的函数响应(function-response)来恢复该操作的执行。
这些功能被框架自动生成的工具所替代(这些工具具有反射性,并基于特定的“发布者”机制进行工作)。这些工具在程序运行时会实时生成相关数据,因此可以在程序运行前就将其设置为“非阻塞”模式(即不会阻塞程序的执行)。该功能仅适用于框架的使用;相关设置可能会随时更改,且无需提前通知用户。
函数
返回一个工作流节点,该节点会将此工具作为固定步骤来执行:前一个节点的输出会成为该工具的参数,而该工具的输出则会成为该节点的输出结果。
返回底层函数的声明信息。
使用提供的参数来执行该函数。 args(可选地使用……) 上下文(context).
在将 LLM 请求发送之前,会先对其进行处理。