Skip to main content

ToolRegistry

Struct ToolRegistry 

Source
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

Source

pub fn new() -> Self

Create an empty tool registry.

Source

pub fn register(&mut self, tool: ToolDefinition)

Register a tool that AI models are allowed to invoke.

Source

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.

Source

pub fn list_tools(&self) -> Vec<&ToolDefinition>

List all registered tools (for agent discovery).

Source

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

Check if a specific tool is registered.

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() -> ToolRegistry

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