pub fn dispatch_tools(
agents: Query<'_, '_, (Entity, &AgentState, &StageInference, &InferenceResult, &mut ContextWindow, Option<&ToolResultRoutingComponent>, Option<&ToolSensitivities>, Option<&mut TaintGate>, Option<&GateResolved>, Option<&GateAutoApprove>, Option<&InFlightWork>), With<ReadyForTools>>,
service: Res<'_, ToolServiceRes>,
stage: Res<'_, ToolStage>,
policy: Option<Res<'_, PolicyGate>>,
script_rules: Option<Res<'_, GateScriptRules>>,
hub: Option<Res<'_, InteractionHub>>,
gate_stage: Option<Res<'_, GatePromptStage>>,
commands: Commands<'_, '_>,
)Expand description
Tool-dispatch system: for each ReadyForTools agent, apply its context_*
tool calls inline (they mutate the ECS window) and hand the rest to the
sequential tool lane, moving it to AwaitingTools. If a batch is all
context tools there is nothing for the lane, so the results are applied
immediately and the agent loops straight back to ReadyToInfer. The lane
serializes execution, so there is no permit gate - every ready agent is
enqueued in turn.