pub struct ToolRegistry { /* private fields */ }Expand description
A registry for dynamically managing agent tools.
Tools are registered under their AgentTool::name and can be retrieved,
listed, or have their inputs validated against their parameter schemas.
Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn register(&mut self, tool: Arc<dyn AgentTool>)
pub fn register(&mut self, tool: Arc<dyn AgentTool>)
Registers a tool in the registry, replacing any existing tool with the same name.
This historical unchecked API remains temporarily source-compatible
during I158 migration. New product composition should use
register_contribution.
Sourcepub fn register_contribution(
&mut self,
contribution: ToolContribution,
) -> Result<(), ToolRegistrationError>
pub fn register_contribution( &mut self, contribution: ToolContribution, ) -> Result<(), ToolRegistrationError>
Registers one explicitly sourced contribution without replacing an existing tool.
A duplicate returns both source identities and leaves the current registry entry unchanged.
Sourcepub fn register_contributions(
&mut self,
contributions: impl IntoIterator<Item = ToolContribution>,
) -> Result<(), ToolRegistrationError>
pub fn register_contributions( &mut self, contributions: impl IntoIterator<Item = ToolContribution>, ) -> Result<(), ToolRegistrationError>
Registers a contribution batch transactionally.
The complete batch is checked against the current registry and against earlier entries in the same iteration order before any tool is inserted. On the first duplicate, the registry remains unchanged.
Sourcepub fn get(&self, name: &str) -> Option<&dyn AgentTool>
pub fn get(&self, name: &str) -> Option<&dyn AgentTool>
Retrieves a tool by name, or None if not registered.
Sourcepub fn validate_input(&self, name: &str, input: &Value) -> Result<(), ToolError>
pub fn validate_input(&self, name: &str, input: &Value) -> Result<(), ToolError>
Validates that the given input conforms to the tool’s parameter schema.
Returns Ok(()) if the tool exists and the input is an object, or
Err(ToolError) if the tool is not found or the input is invalid.
This performs a basic structural check (input must be a JSON object).
Full JSON Schema validation can be added later via the jsonschema crate.