搜索文档

浏览 Awaken Agents 文档
Docs/Awaken Agentsv1.0.0-dev/内部机制/理解系统运行第一个 Tool
提示·你正在阅读发布前文档(v1.0.0-dev)。接口与行为在稳定发布前仍可能变化。

内部机制 · 理解系统

运行第一个 Tool

本页内容

让受检的 echo Tool 依次经过模型可见性、权限、执行与共享 step commit。

目标

运行一次由模型请求的 Tool,并在已提交 transcript 中找到它的结果。本页使用唯一维护的 direct_runtime 示例。实现新 Tool 由添加 Tool 负责;state command 由状态与快照模型 负责。

前置条件

  • 已完成创建第一份 Agent 配置
  • Awaken 源码 checkout 与页面版本横幅中的 revision 一致;
  • 终端位于仓库根目录。

示例使用 ScriptedLlm,因此可以离线、确定性地运行。

1. 运行受检 Tool 路径

cargo run -p awaken-runtime-examples --example direct_runtime

transcript 应包含 echoed: hello,run 应以 Ended(NaturalEnd) 结束。

2. 找到四处一致的声明

并排打开:

  • crates/devtools/awaken-runtime-examples/examples/direct_runtime.rs
  • crates/devtools/awaken-runtime-examples/src/lib.rs

沿着 echo 标识查看四个位置:

边界要找什么所有者
模型请求ScriptedLlm 发出 tool_id: "echo" 的调用本地 model double
模型可见契约snapshot 包含 echoToolDescriptorAgent publication
可执行实现Runtime::with_tool(Arc::new(EchoTool))进程 Runtime
授权permission rules 允许 echopermission gate

四处指向同一次 Tool 调用。不要增加第二个 dispatcher,也不要把动作实现写进 prompt。

3. 验证

cargo test -p awaken-runtime-examples --test direct_runtime

测试检查 run 到达 NaturalEnd,并且已提交 message 包含 echoed: hello

如果 Cargo 找不到 package,回到 workspace 根目录。如果本地修改后对应测试失败,逐项比较 上面的四处声明。Tool invocation error 会被转换成模型可见的错误结果,模型可以在下一次 调用中纠正;除非 run 最终给出需要修改配置或实现的明确结果,否则不要增加人工恢复流程。

Runtime 如何处理

flowchart LR
  call[Model ToolCall] --> identity[Canonical Tool id]
  identity --> gate[Permission gate]
  gate --> executor[唯一 ToolExecutor]
  executor --> output[ToolOutput]
  output --> commit[Step commit]
  commit --> next[下一次 model turn 或 terminal RunState]

Tool 不拥有 transcript 或 commit boundary。Runtime 把 Tool result 与 step 的其余内容一起 暂存。这样 replay、permission 与 state 始终走同一条执行路径。

下一步