pub struct ToolSet { /* private fields */ }Expand description
A collection of tools keyed by name.
This is what an agent is configured with and what the runtime loop
dispatches through: the model names a tool, the loop looks it up here and
calls it.
Tools are stored type-erased as Box<dyn DynTool>, so native
ToolHandlers and (later) MCP-backed tools live side by side.
Names are unique. Registering a second tool under a name already present is
a RegistryError, not a silent overwrite: a shadowed tool is a
configuration bug the caller should hear about, since the model would be
told about one tool and dispatched to another.
The backing map is a BTreeMap, so descriptors and
tools enumerate in a stable, name-sorted order. A
deterministic tool list is worth having for a runtime built on
deterministic replay: the order the model is shown its tools does not wobble
between runs.
Implementations§
Source§impl ToolSet
impl ToolSet
Sourcepub fn register<H: ToolHandler + 'static>(
&mut self,
handler: H,
) -> Result<(), RegistryError>
pub fn register<H: ToolHandler + 'static>( &mut self, handler: H, ) -> Result<(), RegistryError>
Registers a typed ToolHandler, wrapping it as a
DynTool automatically.
Returns RegistryError::DuplicateName if a tool is already registered
under this handler’s NAME; the existing tool
is left in place.
Sourcepub fn register_dyn(
&mut self,
tool: Box<dyn DynTool>,
) -> Result<(), RegistryError>
pub fn register_dyn( &mut self, tool: Box<dyn DynTool>, ) -> Result<(), RegistryError>
Sourcepub fn get(&self, name: &str) -> Option<&dyn DynTool>
pub fn get(&self, name: &str) -> Option<&dyn DynTool>
Looks up a tool by the name the model called it by.
Sourcepub fn tools(&self) -> impl Iterator<Item = &dyn DynTool>
pub fn tools(&self) -> impl Iterator<Item = &dyn DynTool>
Every registered tool, name-sorted, as dyn DynTool.
Sourcepub fn descriptors(&self) -> Vec<ToolDescriptor>
pub fn descriptors(&self) -> Vec<ToolDescriptor>
A ToolDescriptor for every registered tool, name-sorted.
This is the list handed to a model: each tool’s name, description, effect, and input schema.