Tool

interface Tool<Args : ToolArgs>(source)

实现此接口并打上 @AutoService(Tool::class) 来注册成为 agent 的一个工具。

AutoTweaker 的一个插件内部,或插件直接可以互相访问,故工具可以拿到来自适配器以及其他插件的能力。

AutoTweaker 会为每个 agent 实例构造不同的 Tool 实例,在这个 agent 的生命周期中,始终使用同一个 Tool 实例。

ToolArgs 是工具的调用参数,应该由插件生成,AutoTweaker 使用 kotlin 的序列化器处理 LLM 的工具调用参数来代替手动 Json 解析,同时提供类型安全的参数读取。

See also

Types

Link copied to clipboard
sealed interface ResolveResult

预处理的结果,决定直接生成工具响应还是等待用户审批调用。

Link copied to clipboard
data class RuntimeOutput(val content: String, val type: Tool.RuntimeOutput.OutputType)

工具的实时输出,如命令的实时响应,这些信息不会传递给 LLM,只给用户看。

Link copied to clipboard
data class ToolOutput(val result: String, val presentation: ToolPresentation, val data: JsonElement?, val success: Boolean)

工具响应,result 给 LLM 看,success / presentation 给用户看,data 给程序读。

Functions

Link copied to clipboard
abstract suspend fun execute(request: JsonElement, cwd: Path, outputChannel: SendChannel<Tool.RuntimeOutput>): Tool.ToolOutput

调用工具,已经经过用户或审批系统确认,不必考虑安全问题。

Link copied to clipboard
abstract suspend fun meta(): Pair<ToolMeta, KSerializer<Args>>

应该委托给插件生成的 builder 来构造 Pair<ToolMeta, KSerializer<Args>>

Link copied to clipboard
abstract suspend fun resolve(args: Args, cwd: Path): Tool.ResolveResult

解析 LLM 的调用请求,在不执行任何实际操作的情况下对请求进行预处理,并在有必要时提前返回错误消息而不是等到用户批准之后。