ToolRegistry

Struct ToolRegistry 

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

Registry for discovering and managing tools

The ToolRegistry maintains a registry of all available tools and provides methods to discover tools by ID and invoke them. Tools can be registered at startup or dynamically at runtime.

§Examples

use ricecoder_agents::ToolRegistry;

let mut registry = ToolRegistry::new();
// Register tools...

// Find a tool
let tool = registry.find_tool("webfetch");

Implementations§

Source§

impl ToolRegistry

Source

pub fn new() -> Self

Create a new tool registry

§Returns

A new empty ToolRegistry

Source

pub fn register(&mut self, tool: Arc<dyn ToolInvoker>)

Register a tool

Registers a tool with the registry, making it available for agent invocation.

§Arguments
  • tool - The tool invoker to register
Source

pub fn find_tool(&self, tool_id: &str) -> Option<Arc<dyn ToolInvoker>>

Find a tool by ID

§Arguments
  • tool_id - The ID of the tool to find
§Returns

An Option containing the tool if found

Source

pub fn all_tools(&self) -> Vec<Arc<dyn ToolInvoker>>

Get all registered tools

§Returns

A vector of all registered tools

Source

pub fn tool_count(&self) -> usize

Get the number of registered tools

§Returns

The total number of registered tools

Source

pub fn get_tool_metadata(&self, tool_id: &str) -> Option<ToolMetadata>

Get metadata for a specific tool

§Arguments
  • tool_id - The ID of the tool
§Returns

An Option containing the tool metadata if found

Source

pub fn all_tool_metadata(&self) -> Vec<ToolMetadata>

Get metadata for all registered tools

§Returns

A vector of metadata for all registered tools

Source

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

Check if a tool is registered

§Arguments
  • tool_id - The ID of the tool to check
§Returns

true if the tool is registered, false otherwise

Source

pub async fn invoke_tool( &self, tool_id: &str, input: Value, ) -> Result<Value, String>

Invoke a tool

§Arguments
  • tool_id - The ID of the tool to invoke
  • input - The input to the tool as JSON
§Returns

The tool output as JSON or an error

Source

pub fn discover_builtin_tools(&mut self) -> Result<(), String>

Discover built-in tools at startup

This method initializes the registry with built-in tools from ricecoder-tools. It registers webfetch, patch, todowrite, todoread, and websearch tools.

Source

pub fn load_configuration( &mut self, config: HashMap<String, Value>, ) -> Result<(), String>

Load tool configuration from project settings

This method loads tool configuration from a configuration source. The configuration can be used to enable/disable tools or customize their behavior.

Source

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

Get all available tool IDs

§Returns

A vector of all registered tool IDs

Trait Implementations§

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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, 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