Skip to main content

codetether_agent/agent/tooling/
registry_access.rs

1//! Tool registry accessors for agents.
2//!
3//! This module keeps simple tool-registry convenience methods out of the main
4//! dispatch file.
5//!
6//! # Examples
7//!
8//! ```ignore
9//! let ids = agent.list_tools();
10//! ```
11
12use crate::agent::Agent;
13use crate::tool::Tool;
14use std::sync::Arc;
15
16impl Agent {
17    /// Returns a registered tool by name when it exists.
18    ///
19    /// # Examples
20    ///
21    /// ```ignore
22    /// let bash = agent.get_tool("bash");
23    /// ```
24    pub fn get_tool(&self, name: &str) -> Option<Arc<dyn Tool>> {
25        self.tools.get(name)
26    }
27
28    /// Registers a tool with the agent's tool registry.
29    ///
30    /// # Examples
31    ///
32    /// ```ignore
33    /// agent.register_tool(tool);
34    /// ```
35    pub fn register_tool(&mut self, tool: Arc<dyn Tool>) {
36        self.tools.register(tool);
37    }
38
39    /// Lists all tool identifiers currently available to the agent.
40    ///
41    /// # Examples
42    ///
43    /// ```ignore
44    /// let ids = agent.list_tools();
45    /// ```
46    pub fn list_tools(&self) -> Vec<&str> {
47        self.tools.list()
48    }
49
50    /// Returns whether a tool id is available to the agent.
51    ///
52    /// # Examples
53    ///
54    /// ```ignore
55    /// assert!(agent.has_tool("bash") || !agent.has_tool("bash"));
56    /// ```
57    pub fn has_tool(&self, name: &str) -> bool {
58        self.tools.get(name).is_some()
59    }
60}