pub struct ToolRegistry { /* private fields */ }Expand description
Registry for dynamically registered tools.
The registry provides:
- O(1) tool lookup by name
- Collision detection (no duplicate names)
- Bulk operations (list, export)
- Format conversion for OpenAI/Anthropic
§Thread Safety
The registry itself is not thread-safe. Wrap in Arc<RwLock<ToolRegistry>>
if you need concurrent access. Tools within the registry are Arc<dyn Tool>.
§Example
ⓘ
let mut registry = ToolRegistry::new();
registry.register(Arc::new(MyCalculatorTool::new()));
if let Some(tool) = registry.get("calculator") {
let result = tool.execute(json!({"expr": "2+2"})).await?;
}Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn register_replace(&mut self, tool: Arc<dyn Tool>)
pub fn register_replace(&mut self, tool: Arc<dyn Tool>)
Register a tool, replacing any existing tool with the same name.
§Security Warning
Use with caution — this can replace trusted tools with untrusted ones.
Sourcepub fn definitions(&self) -> Vec<&ToolDefinition>
pub fn definitions(&self) -> Vec<&ToolDefinition>
List all tool definitions
Sourcepub fn to_openai_format(&self) -> Vec<Value>
pub fn to_openai_format(&self) -> Vec<Value>
Generate OpenAI-compatible tool list
Sourcepub fn to_anthropic_format(&self) -> Vec<Value>
pub fn to_anthropic_format(&self) -> Vec<Value>
Generate Anthropic Claude-compatible tool list
Trait Implementations§
Source§impl Debug for ToolRegistry
impl Debug for ToolRegistry
Source§impl Default for ToolRegistry
impl Default for ToolRegistry
Source§fn default() -> ToolRegistry
fn default() -> ToolRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ToolRegistry
impl !RefUnwindSafe for ToolRegistry
impl Send for ToolRegistry
impl Sync for ToolRegistry
impl Unpin for ToolRegistry
impl !UnwindSafe for ToolRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more