Skip to main content

ToolRegistry

Struct ToolRegistry 

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

Registry of available tools for the agent loop.

Implementations§

Source§

impl ToolRegistry

Source

pub fn new() -> Self

Create a new empty registry.

Source

pub fn with_cache(self, cache: Arc<dyn ToolCache>) -> Self

Attach a tool result cache.

Source

pub fn register(&mut self, spec: ToolSpec)

Register a tool. Overwrites any existing tool with the same name.

Source

pub fn register_tools(&mut self, specs: impl IntoIterator<Item = ToolSpec>)

Register multiple tools at once.

Equivalent to calling register for each spec in order. Duplicate names overwrite earlier entries.

Source

pub fn with_tool(self, spec: ToolSpec) -> Self

Fluent builder: register a tool and return self.

Allows chaining multiple registrations:

use llm_agent_runtime::agent::{ToolRegistry, ToolSpec};

let registry = ToolRegistry::new()
    .with_tool(ToolSpec::new("search", "Search", |args| args.clone()))
    .with_tool(ToolSpec::new("calc", "Calculate", |args| args.clone()));
Source

pub async fn call( &self, name: &str, args: Value, ) -> Result<Value, AgentRuntimeError>

Call a tool by name.

§Errors
  • AgentRuntimeError::AgentLoop — tool not found, required field missing, or custom validator rejected the arguments
  • AgentRuntimeError::CircuitOpen — the tool’s circuit breaker is open (only possible when the orchestrator feature is enabled)
Source

pub fn get(&self, name: &str) -> Option<&ToolSpec>

Look up a registered tool by name. Returns None if not registered.

Source

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

Return true if a tool with the given name is registered.

Source

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

Remove a tool by name. Returns true if the tool was registered.

Source

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

Return the list of registered tool names.

Source

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

Return all registered tool names as owned Strings.

Unlike tool_names this does not borrow self, making the result usable after the registry is moved or mutated.

Source

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

Return all registered tool names sorted alphabetically.

Useful for deterministic output in help text, diagnostics, or tests.

Source

pub fn tool_specs(&self) -> Vec<&ToolSpec>

Return references to all registered ToolSpecs.

Source

pub fn filter_tools<F: Fn(&ToolSpec) -> bool>(&self, pred: F) -> Vec<&ToolSpec>

Return references to all ToolSpecs that satisfy the given predicate.

§Example
let registry = ToolRegistry::new();
let long_desc: Vec<_> = registry.filter_tools(|s| s.description.len() > 20);
Source

pub fn rename_tool( &mut self, old_name: &str, new_name: impl Into<String>, ) -> bool

Rename a registered tool from old_name to new_name.

The tool’s name field and its registry key are both updated. Returns true if the tool was found and renamed, false if old_name is not registered. If new_name is already registered, it is overwritten.

Source

pub fn tool_count(&self) -> usize

Return the number of registered tools.

Source

pub fn is_empty(&self) -> bool

Return true if no tools are registered.

Source

pub fn clear(&mut self)

Remove all registered tools.

Useful for resetting the registry between test runs or for dynamic agent reconfiguration.

Source

pub fn remove(&mut self, name: &str) -> Option<ToolSpec>

Remove a tool from the registry by name.

Returns Some(spec) if the tool was registered, None if not found.

Source

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

Return true if a tool with the given name is registered.

Source

pub fn descriptions(&self) -> Vec<(&str, &str)>

Return (name, description) pairs for all registered tools, sorted by name.

Useful for generating help text or logging the tool set at startup.

Source

pub fn find_by_description_keyword(&self, keyword: &str) -> Vec<&ToolSpec>

Return references to all tool specs whose description contains keyword (case-insensitive).

Source

pub fn tool_count_with_required_fields(&self) -> usize

Return the number of tools that have at least one required field.

Source

pub fn names(&self) -> Vec<&str>

Return the names of all registered tools, sorted alphabetically.

Source

pub fn tool_names_starting_with(&self, prefix: &str) -> Vec<&str>

Return the names of all registered tools whose name starts with prefix, sorted alphabetically.

Source

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

Return the description of the tool with the given name, or None if no such tool is registered.

Source

pub fn count_with_description_containing(&self, keyword: &str) -> usize

Return the count of tools whose description contains keyword (case-insensitive).

Source

pub fn unregister_all(&mut self)

Remove all registered tools.

Source

pub fn names_containing(&self, substring: &str) -> Vec<&str>

Return a sorted list of tool names that contain substring (case-insensitive).

Source

pub fn shortest_description(&self) -> Option<&str>

Return the description of the tool with the shortest description string.

Returns None if the registry is empty.

Source

pub fn longest_description(&self) -> Option<&str>

Return the description of the tool with the longest description string.

Returns None if the registry is empty.

Source

pub fn all_descriptions(&self) -> Vec<&str>

Return a sorted list of all tool descriptions.

Source

pub fn tool_names_with_keyword(&self, keyword: &str) -> Vec<&str>

Return the names of tools whose description contains keyword (case-insensitive).

Source

pub fn avg_description_length(&self) -> f64

Return the mean byte length of all tool descriptions.

Returns 0.0 if the registry is empty.

Source

pub fn tool_names_sorted(&self) -> Vec<&str>

Return all registered tool names in ascending sorted order.

Source

pub fn description_contains_count(&self, keyword: &str) -> usize

Return the count of tools whose description contains keyword (case-insensitive).

Trait Implementations§

Source§

impl Debug for ToolRegistry

Source§

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

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

impl Default for ToolRegistry

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<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, 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<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