工具运行流程(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[] 每项包含:
purposetool_nametool_kwargstodo_suggestion
3) instant 短路优化
默认规划器会监听 instant:
这使得 next_action=response 可提前结束本轮规划等待。
4) 执行阶段(EXECUTE)
默认执行器行为:
- 读取
execution_commands - 按
tool.loop.concurrency建立信号量(可并发) - 调用
async_call_tool(tool_name, tool_kwargs) - 生成标准执行记录:
purpose/tool_name/kwargs/todo_suggestion/success/result/error
5) 收敛与注入
当回路结束后:
- 有执行记录:
to_action_results(records)->prompt.action_resultsprompt.extra_instruction注入引用提醒extra.tool_logs写入广播结果
- 无执行记录:不注入工具结果,直接回复
6) 关键控制参数
tool.loop.enabledtool.loop.max_roundstool.loop.concurrencytool.loop.timeout
下一步建议阅读:工具 Handlers(默认与替换)