Skip to main content

ToolExecutor

Struct ToolExecutor 

Source
pub struct ToolExecutor { /* private fields */ }
Expand description

Tool registry and executor with optional result caching.

Implementations§

Source§

impl ToolExecutor

Source

pub fn new() -> Self

Create a new executor with default config

Source

pub fn builder() -> ExecutorBuilder

Create an executor builder for fluent API

Source

pub fn clear_cache(&self)

Clear the cache

Source

pub fn invalidate_cache_for_tool(&self, tool_name: &str)

Invalidate cache for a specific tool

Source

pub fn cache_stats(&self) -> CacheStats

Get cache statistics

Source

pub fn add_dyn_tool(&self, tool: Box<dyn DynTool>) -> ToolResult<&Self>

Chain-friendly: add a dynamic tool, returns error if already registered

Source

pub fn unregister(&self, name: &str) -> ToolResult<()>

Unregister a tool

Source

pub fn input_schema(&self, name: &str) -> Option<Value>

Get input schema for a tool

Source

pub fn has_tool(&self, name: &str) -> bool

Check if tool exists

Source

pub fn tool_names(&self) -> Vec<String>

List tool names in deterministic lexicographic order.

Source

pub async fn execute( &self, tool_name: &str, input: Value, ) -> ToolResult<ExecutionResult>

Execute a tool with caching, timeout, and exponential backoff.

Tool-level failures are returned as Ok(ExecutionResult) with its success field set to false. Use ToolExecutor::execute_simple when failures should be returned as ToolError values instead.

Source

pub async fn execute_simple( &self, tool_name: &str, input: Value, ) -> ToolResult<Value>

Execute a tool and return its JSON value, converting an unsuccessful execution into a ToolError.

Source

pub fn add_functions_from_dir_with_registry( &self, dir: impl AsRef<Path>, handlers: &HashMap<String, ToolHandler>, strict: bool, ) -> ToolResult<Vec<String>>

Register function specifications loaded from .json files in dir.

Each file may contain a direct function object or an OpenAI-style { "type": "function", "function": ... } wrapper. handlers maps function names to implementations. When strict is false, files without a matching handler are skipped; otherwise they cause an error.

Returns the list of function names successfully registered.

Source

pub async fn execute_tool_calls_parallel( &self, calls: &[ToolCallMessage], ) -> Vec<TextMessage>

Execute tool calls concurrently, returning one tool message per call.

Results are returned in completion order; use Self::execute_tool_calls_ordered to restore input order.

Source

pub async fn execute_tool_calls_ordered( &self, calls: &[ToolCallMessage], ) -> Vec<TextMessage>

Execute tool calls concurrently and restore input order in the result.

At most eight handlers run concurrently. Invalid arguments, execution errors, and handler panics are isolated to their call and encoded as a tool-error message, so one failure does not discard other results.

Source

pub fn export_tool_as_function(&self, name: &str) -> Option<Tools>

Export one registered tool as an LLM function definition.

Source

pub fn export_all_tools_as_functions(&self) -> Vec<Tools>

Export all registered tools as function definitions sorted by name.

Source

pub fn export_tools_filtered<F>(&self, filter: F) -> Vec<Tools>
where F: FnMut(&ToolMetadata) -> bool,

Export enabled tools selected by a metadata predicate.

Source

pub fn config(&self) -> &ExecutionConfig

Get the executor’s ExecutionConfig.

Trait Implementations§

Source§

impl Clone for ToolExecutor

Source§

fn clone(&self) -> ToolExecutor

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ToolExecutor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ToolExecutor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more