Skip to content

工具运行流程(Tool Loop)

适用版本:4.0.8.1+

本页对应“工具调用的整体运行过程”。

1) 总体流程

2) 规划阶段(PLAN)

默认规划器会调用一个独立 ModelRequest,输入结构:

  • .input({ user_input, user_extra_requirement, available_tools })
  • .info({ done_plans, last_round_result, round_index, max_rounds })
  • .instruct([...])
  • .output({ next_action, execution_commands[] })

其中 execution_commands[] 每项包含:

  • purpose
  • tool_name
  • tool_kwargs
  • todo_suggestion

3) instant 短路优化

默认规划器会监听 instant

这使得 next_action=response 可提前结束本轮规划等待。

4) 执行阶段(EXECUTE)

默认执行器行为:

  1. 读取 execution_commands
  2. tool.loop.concurrency 建立信号量(可并发)
  3. 调用 async_call_tool(tool_name, tool_kwargs)
  4. 生成标准执行记录:
    • purpose/tool_name/kwargs/todo_suggestion/success/result/error

5) 收敛与注入

当回路结束后:

  • 有执行记录:
    • to_action_results(records) -> prompt.action_results
    • prompt.extra_instruction 注入引用提醒
    • extra.tool_logs 写入广播结果
  • 无执行记录:不注入工具结果,直接回复

6) 关键控制参数

  • tool.loop.enabled
  • tool.loop.max_rounds
  • tool.loop.concurrency
  • tool.loop.timeout

下一步建议阅读:工具 Handlers(默认与替换)