pub struct ToolRegistry { /* private fields */ }Expand description
Registry of allowed AI tools with validation.
This is the policy enforcement layer. AI models can only invoke tools that are registered here, and their arguments must conform to the registered schema.
§Example
use extro_core::*;
let mut registry = ToolRegistry::new();
registry.register(ToolDefinition {
name: "summarize".into(),
description: "Summarize page content".into(),
parameters_schema: serde_json::json!({"type": "object"}),
});
let call = AIToolCall {
tool_name: "summarize".into(),
arguments: serde_json::json!({}),
};
assert!(registry.validate(&call).is_ok());
let bad_call = AIToolCall {
tool_name: "delete_everything".into(),
arguments: serde_json::json!({}),
};
assert!(registry.validate(&bad_call).is_err());Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn register(&mut self, tool: ToolDefinition)
pub fn register(&mut self, tool: ToolDefinition)
Register a tool that AI models are allowed to invoke.
Sourcepub fn validate(&self, call: &AIToolCall) -> Result<&ToolDefinition, CoreError>
pub fn validate(&self, call: &AIToolCall) -> Result<&ToolDefinition, CoreError>
Validate an AI tool call against the registry.
Returns Ok(()) if the tool exists and is registered.
Returns Err(CoreError::ToolNotRegistered) if the tool is not allowed.
Sourcepub fn list_tools(&self) -> Vec<&ToolDefinition>
pub fn list_tools(&self) -> Vec<&ToolDefinition>
List all registered tools (for agent discovery).
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 UnsafeUnpin 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