pub struct ToolExecutor { /* private fields */ }Expand description
Dispatches tool calls against a registry, in parallel.
Typical use in a ReAct tools node: take the assistant message’s
tool_calls, execute_batch them, and append the resulting tool
messages to the messages channel via the AddMessages reducer.
Attach a MiddlewareChain via ToolExecutor::with_middleware to run
every dispatched call through the chain’s tool hooks (Middleware /
Interceptor SDK): a layer may mutate the call, reject it (surfacing as an
ERROR: tool message under the same failure-isolation contract below),
or short-circuit it with a substitute result.
Implementations§
Source§impl ToolExecutor
impl ToolExecutor
Sourcepub fn new(registry: ToolRegistry) -> Self
pub fn new(registry: ToolRegistry) -> Self
An executor over registry.
Sourcepub fn registry(&self) -> &ToolRegistry
pub fn registry(&self) -> &ToolRegistry
The underlying registry.
Sourcepub fn with_middleware(self, chain: MiddlewareChain) -> Self
pub fn with_middleware(self, chain: MiddlewareChain) -> Self
Builder-style: run every dispatched call through chain’s tool
hooks. Typically handed the chain from
crate::node::NodeContext::middleware.
Sourcepub fn with_effect_admission(self, context: EffectAdmissionContext) -> Self
pub fn with_effect_admission(self, context: EffectAdmissionContext) -> Self
Builder-style: enforce the run-scoped effect boundary on every tool body this executor dispatches.
Sourcepub fn with_call_context(
self,
thread_id: impl Into<String>,
node: impl Into<String>,
) -> Self
pub fn with_call_context( self, thread_id: impl Into<String>, node: impl Into<String>, ) -> Self
Builder-style: label dispatched calls with the thread and node they
originate from (flowing into the ToolInvocation context).
Sourcepub fn middleware(&self) -> &MiddlewareChain
pub fn middleware(&self) -> &MiddlewareChain
The attached middleware chain (empty when none was added).
Sourcepub fn effect_admission(&self) -> Option<&EffectAdmissionContext>
pub fn effect_admission(&self) -> Option<&EffectAdmissionContext>
The attached effect boundary, if enforcement is enabled.
Sourcepub async fn execute_batch(&self, calls: &[ToolCall]) -> Vec<ChatMessage>
pub async fn execute_batch(&self, calls: &[ToolCall]) -> Vec<ChatMessage>
Execute a batch of tool calls concurrently.
Returns one ChatMessage::tool_result per call, in the same
order as calls (order stability matters for conversation
reconstruction). Individual failures do not abort the batch: a failed
call yields a tool message whose content is the error description
(prefixed with ERROR:), so the model can observe and recover from
tool failures — matching ToolNode’s default handle_tool_errors
behavior. A panicking tool is contained the same way: the unwind is
caught and reported as an ERROR: tool message instead of taking
down the batch (and the executor task driving it).