執行期

工具執行器

按順序或在安全時並行執行模型請求的工具的執行層。

工具執行器

這是什麼

按順序或在安全時並行執行模型請求的工具的執行層。

白話解釋

想像一個施工團隊,每個工人都可以同時在不同的牆上敲釘子而不互相干擾,但如果兩個工人同時去拿同一把梯子,其中一個就得等一下。工具執行器就是替模型做出同樣的判斷:獨立的工具請求可以同時執行,而針對同一檔案的兩次編輯則需要排隊依次進行,而不是互相競爭。

為什麼重要

當模型的一次回應要求同時執行多個工具呼叫時,必須有人決定它們是否可以並行或者需要逐一執行——檔案寫入和網路搜尋可以重疊,但對同一檔案的兩次編輯則不行。這個決定防止多工具輪次悄悄損壞狀態或自我競爭。Agent 團隊委派依賴同一個執行層來讓並行的子 agent 不會互相踩到對方的變更。

How it works

Before anything runs, _should_parallelize_tool_batch (agent/tool_dispatch_helpers.py) inspects the whole batch of requested tool calls: it forces sequential execution if any tool is on a fixed never-parallel list, if arguments fail to parse, or if two path-scoped calls like read_file, write_file, or patch target overlapping paths; a fixed set of read-only tools such as web_search and vision_analyze are always cleared to run together. AIAgent._execute_tool_calls (run_agent.py) reads that verdict and dispatches to either execute_tool_calls_concurrent or execute_tool_calls_sequential (agent/tool_executor.py), the concurrent path using a thread pool capped at 8 workers. Concurrent results are collected back in the original call order before being appended to the message list, so the model sees them exactly as it requested them.

A concrete example

A model responds with three parallel tool calls: web_search for a competitor’s pricing, read_file on a local notes file, and write_file to update a todo list.

  1. _should_parallelize_tool_batch checks that none of these tools are on the exclude list and that the two file operations touch different paths.
  2. All three execute concurrently, with the web search running in a thread alongside the two file operations.
  3. Results are collected in the original call order and presented to the model as if they ran sequentially, but the total wall-clock time is closer to the slowest single operation than the sum of all three.