Skip to content

工具运行流程(Tool Loop)

当你已经会注册工具后,下一步要理解的是:Agently 到底怎么决定调不调工具、调几个、结果又是怎么回灌给模型的。

适合什么时候读

  • 你已经看过 工具快速开始
  • 你在调试工具规划或工具日志
  • 你想理解一轮 Tool Loop 的内部状态

你会学到什么

  • Tool Loop 的标准回路
  • execution_commands 和回合状态的意义
  • 工具结果是怎么注入回最终回答的

总体流程

这张图放在正文里,是为了说明:Tool Loop 不是黑盒 while 循环,而是一个有阶段、有状态的标准回路。

回合状态

text
round_state = {
  "done_plans": [...],
  "last_round_records": [...],
  "round_index": 0,
}

规划阶段在做什么

规划器会综合:

  • 用户输入
  • 可见工具
  • 已执行记录
  • 当前轮次

然后生成:

python
{
    "next_action": "execute" | "response",
    "execution_commands": [
        {
            "purpose": str,
            "tool_name": str,
            "tool_kwargs": dict,
            "todo_suggestion": str,
        }
    ],
}

执行阶段在做什么

执行器会并发或串行调用工具,并把结果归一化成 ToolExecutionRecord

你最终最常看的其实是:

  • tool_name
  • purpose
  • success
  • result
  • error

工具结果最后怎么回到回答里

如果循环中真的执行了工具,框架会把记录转成:

  • prompt.action_results
  • extra.tool_logs

这样模型的最终回答并不是“凭空接着说”,而是建立在工具证据之上。

常见误区

  • 以为模型会直接决定并执行工具。
  • 调试时只看最终回答,不看 execution_commandstool_logs
  • 明明只是工具描述问题,却误以为是 Tool Loop 框架本身出了问题。

下一步去哪

  • agently-agent-extensions