Skip to main content

dispatch_tools

Function dispatch_tools 

Source
pub async fn dispatch_tools(
    state: Arc<AgentToolState>,
    calls: Vec<ToolCall>,
) -> Vec<(String, String)>
Expand description

Resolve policy, handle approvals / dynamic interactions, and execute a batch of tool calls, returning (tool_call_id, result) pairs in call order.

Two passes so tool calls within one batch run in parallel where it is safe:

  1. Sequential resolution - dynamic interactions (ask_user_*), sub-agent tools, and ask approval prompts are inherently interactive and are resolved one at a time, in order (a user answers one prompt at a time, and a Session-scope approval must be visible to later calls in the batch). Each call ends up either fully resolved or queued for execution.
  2. Parallel execution - every queued call runs concurrently (join_all), then results are stitched back into the original call order.