Skip to main content

Module tool

Module tool 

Source
Expand description

§katu_core::tool

§职责

定义工具系统的数据类型与执行契约。

§设计原则

  • Provider 无关 — 参数使用 JSON Schema(serde_json::Value),适配所有 LLM provider
  • Serde 友好 — 数据类型可序列化/反序列化
  • 最小 traitTool trait 只含必要方法,扩展能力留给上层

§对外接口

  • ToolDefinition — 发送给 LLM 的工具 schema(name + description + parameters JSON Schema)
  • ToolOutput — 工具执行结果(content + metadata + is_error)
  • ToolChoice — 工具选择策略(auto / none / required / specific)
  • Tool — 工具执行 trait(definition + validate + execute + concurrency_mode)
  • ToolCallContext — 执行上下文(call_id + cancellation + extra)
  • CancellationToken — 取消令牌(re-export tokio_util::sync::CancellationToken
  • ConcurrencyMode — 并发调度标记

§调用者

  • katu-llmLlmRequest 持有 Vec<ToolDefinition> + ToolChoice
  • katu-agent (future) — Agent loop 通过 Tool trait 调用工具
  • katu-core::eventStreamEvent::ToolResult 可从 ToolOutput 构造

Structs§

CancellationToken
取消令牌 — re-export tokio_util::sync::CancellationToken
ToolCallContext
工具执行上下文 — Agent loop 构造后传入 Tool::execute
ToolDefinition
工具定义 — 发送给 LLM 的 schema。
ToolOutput
工具执行结果 — 返回给 agent loop 的输出。

Enums§

ConcurrencyMode
工具并发模式 — Agent loop 调度同批次 tool_call 时的行为。
ToolChoice
工具选择策略 — 控制 LLM 是否以及如何使用工具。

Traits§

Tool
工具执行 trait — 所有可被 Agent 调用的工具必须实现此 trait。