pub struct ToolRegistry { /* private fields */ }Expand description
Registry of tools available to an agent.
Stores tools in a HashMap for O(1) lookup by name and supports aliases
(e.g., "bash_exec" → "exec") that are resolved transparently but not
exposed in definitions() or list().
Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn set_truncate_on_overflow(&mut self, enabled: bool)
pub fn set_truncate_on_overflow(&mut self, enabled: bool)
When true, oversized output is truncated instead of failing the tool
call. Default: false (fail with an error so the agent can retry).
Sourcepub fn register(&mut self, tool: Arc<dyn Tool>)
pub fn register(&mut self, tool: Arc<dyn Tool>)
Register a tool (replaces existing tool with same name).
Sourcepub fn remove(&mut self, name: &str) -> bool
pub fn remove(&mut self, name: &str) -> bool
Remove a tool by name. Returns true if the tool was present.
Sourcepub fn strip_prefixes(&mut self, prefixes: &[&str])
pub fn strip_prefixes(&mut self, prefixes: &[&str])
Remove every tool whose name starts with one of prefixes. Aliases
pointing at removed tools are also dropped.
Sourcepub fn alias(&mut self, alias: &str, target: &str)
pub fn alias(&mut self, alias: &str, target: &str)
Register an alias so that lookups for alias resolve to target.
Aliases are not exposed in definitions() or list().
Sourcepub fn get(&self, name: &str) -> Option<&Arc<dyn Tool>>
pub fn get(&self, name: &str) -> Option<&Arc<dyn Tool>>
Look up a tool by name (checks aliases if direct lookup fails). Always resolves any registered tool, even if not in the active set.
Sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Returns true if a tool with the given name is registered (without logging).
Sourcepub fn retain(&mut self, f: impl FnMut(&str) -> bool)
pub fn retain(&mut self, f: impl FnMut(&str) -> bool)
Keep only tools whose name satisfies the predicate.
Sourcepub fn list_with_descriptions(&self) -> Vec<(&str, &str)>
pub fn list_with_descriptions(&self) -> Vec<(&str, &str)>
List all registered tools with their names and descriptions (sorted by name).
Sourcepub async fn execute(
&self,
call: &ToolCall,
working_dir: Option<&PathBuf>,
cancel_token: &CancellationToken,
) -> ToolResult
pub async fn execute( &self, call: &ToolCall, working_dir: Option<&PathBuf>, cancel_token: &CancellationToken, ) -> ToolResult
Execute a tool call from the LLM.
Looks up the tool by name, builds a ToolContext, and runs it. Returns
a ToolResult::Failure if the tool is not found or if execution errors.
If the tool defines timeout_secs, the call is
wrapped in a timeout. Tools without a timeout are cancelled immediately
when cancel_token fires.
Sourcepub async fn execute_with_progress(
&self,
call: &ToolCall,
working_dir: Option<&PathBuf>,
cancel_token: &CancellationToken,
progress_tx: UnboundedSender<String>,
) -> ToolResult
pub async fn execute_with_progress( &self, call: &ToolCall, working_dir: Option<&PathBuf>, cancel_token: &CancellationToken, progress_tx: UnboundedSender<String>, ) -> ToolResult
Like Self::execute but attaches a progress channel so tools can stream
incremental output (e.g. stdout lines from bash).
Sourcepub async fn execute_in_context(
&self,
call: &ToolCall,
ctx: ToolContext<'_>,
) -> ToolResult
pub async fn execute_in_context( &self, call: &ToolCall, ctx: ToolContext<'_>, ) -> ToolResult
Execute with parent configuration and optional progress reporting.
Sourcepub fn is_concurrent(&self, call: &ToolCall) -> bool
pub fn is_concurrent(&self, call: &ToolCall) -> bool
Whether call may run alongside other calls. Unknown tools fail at
once, so they count as concurrent.
pub fn supports_background(&self, call: &ToolCall) -> bool
Sourcepub fn humanize(&self, call: &ToolCall) -> String
pub fn humanize(&self, call: &ToolCall) -> String
Human-readable summary of a tool call’s arguments.
Sourcepub fn definitions(&self) -> Vec<ToolDefinition>
pub fn definitions(&self) -> Vec<ToolDefinition>
Generate LLM tool definitions for all registered tools.