Skip to main content

Module tool_bridge

Module tool_bridge 

Source
Expand description

The async worker side of the ECS tool stage - the sync-ECS ↔ async-I/O bridge for tool execution.

When the pipeline decides an agent’s response has tool calls to run, the tool-dispatch system builds a ToolJob (the agent plus a boxed async closure that executes that agent’s batch of calls against its own tool registry / workdir / policy) and sends it to the tool lane. Each tool_worker pulls jobs and reports each ToolOutcome back on the results channel, waking the tick loop; the tool-collect system applies the results on a later tick.

Concurrency: the lane is a pool - spawn_tool_pool runs N workers off one shared job channel (Arc<Mutex<Receiver>>). A worker holds the receiver lock only across recv(), then releases it and runs exec().await, so up to N agents’ tool batches execute concurrently (the receive is serialized; the execution is not). This is the tool-lane counterpart of the inference pool’s per-model concurrency cap. The dispatch/collect systems are unchanged.

Structs§

ToolJob
A batch of tool calls to execute for one agent.
ToolOutcome
The result of a ToolJob, applied on a later tick by the tool-collect system.

Functions§

spawn_tool_pool
Spawn a pool of workers tool_worker tasks off one shared job channel and return their handles. workers is clamped to at least 1. This is the tool-lane concurrency cap - the number of agents whose tool batches may run at once.
tool_worker
One tool worker: pulls ToolJobs from the shared channel and runs them, reporting each outcome and waking the tick loop. Holds the receiver lock only across recv() (so sibling workers can run their exec().await in parallel), then releases it before executing. Returns when the job channel is closed (all senders dropped - i.e. the world is shutting down).

Type Aliases§

BoxedToolExec
A boxed, per-agent tool-execution closure. Built by the dispatch system so it captures that agent’s own tool registry, workdir, and policy; run once by the tool worker.
SharedJobRx
A shared, multi-consumer job receiver: several tool_workers pull from the same channel by taking the lock only long enough to recv().
ToolExecFuture
The future produced by a boxed tool-execution closure: resolves to (tool_call_id, result) pairs - the same shape the engine’s tool executors already return.