Files
ars-backend/docs/tools-subrun.md
ROOG 59d4831f00 main: 增强工具调用与消息流程
- 支持 tool.call 和 tool.result 消息类型处理
- 引入 Tool 调度与执行逻辑,支持超时与结果截断
- 增加 ToolRegistry 和 ToolExecutor 管理工具定义与执行
- 更新上下文构建与消息映射逻辑,适配工具闭环处理
- 扩展配置与环境变量,支持 Tool 调用相关选项
- 增强单元测试覆盖工具调用与执行情景
- 更新文档和 OpenAPI,新增工具相关说明与模型定义
2025-12-22 12:36:59 +08:00

26 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 工具调用(子 Run 模式)最小闭环
本次改动新增 Tool 子系统,保持 RunLoop/Provider 的事件驱动模型不变,通过“子 Run”执行工具并把结果回灌到父 Run。
## 关键链路
- Provider 产生 `tool.call`Streaming 中的 `tool.delta` 聚合RunLoop 落库 `tool.call` 并生成子 Run `run:{parent}:{tool_call_id}`
- `ToolRunJob` 执行具体工具(当前内置 `get_time`),写入 `tool.result` 与子 Run 的 `run.status`
- 父 Run 轮询等待子 Run 结果(超时/失败即终止),将 `tool.result` 追加到上下文后再次调用 Provider直至产出最终 `agent.message`
- 幂等:`tool.call`、子 Run `run.status``tool.result` 均带 dedupe_key同一个 tool_call_id 只会执行一次。
## 消息/事件
- 新增消息类型:`tool.call`role=AGENTpayload 含 tool_call_id/name/arguments`tool.result`role=TOOLpayload 含 parent_run_id/run_id/status/result
- Provider 事件新增 `tool.delta`RunLoop 内部聚合后才触发子 Run`finish_reason=tool_calls` 会结束本轮流并进入工具执行。
## 配置要点
- `AGENT_TOOL_MAX_CALLS_PER_RUN`:单个父 Run 允许的工具调用次数(默认 1超过直接失败
- `AGENT_TOOL_WAIT_TIMEOUT_MS` / `AGENT_TOOL_WAIT_POLL_MS`:父 Run 等待子 Run 结果的超时与轮询间隔。
- `AGENT_TOOL_TIMEOUT_SECONDS` / `AGENT_TOOL_RESULT_MAX_BYTES`:工具执行超时标记与结果截断保护。
- `AGENT_TOOL_CHOICE`:传递给 OpenAI 的 tool_choice默认 auto
- ToolRunJob 队列参数:`AGENT_TOOL_JOB_TRIES` / `AGENT_TOOL_JOB_BACKOFF` / `AGENT_TOOL_JOB_TIMEOUT`
## 预留/限制
- 目前仅支持单工具调用闭环;多次调用的上限可调但仍是串行流程。
- 工具列表可通过 `ToolRegistry` 扩展(当前内置 `get_time` 纯函数)。
- 结果超时为父 Run 级别的软超时PHP 层未强制中断长耗时函数(后续可接入外部超时控制)。