pub struct ToolRegistry { /* private fields */ }Expand description
The tools an agent can call, by name (ToolRegistry).
Names are unique, and two names that differ only by - versus _ count as the same name.
Cloning is cheap: the tools are shared.
Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn with_tools(tools: impl Into<ToolSource>) -> Result<Self, Error>
pub fn with_tools(tools: impl Into<ToolSource>) -> Result<Self, Error>
Sourcepub fn add(&mut self, tools: impl Into<ToolSource>) -> Result<(), Error>
pub fn add(&mut self, tools: impl Into<ToolSource>) -> Result<(), Error>
Registers one tool or a list of tools (add). Tools before a failing one stay registered.
§Errors
ToolValidationError when a name or description is invalid, the name is already
registered (also under a -/_ variant), or tools holds an MCP client.
Sourcepub fn add_or_replace(
&mut self,
tools: impl Into<ToolSource>,
) -> Result<(), Error>
pub fn add_or_replace( &mut self, tools: impl Into<ToolSource>, ) -> Result<(), Error>
Registers tools, replacing tools of the same name.
§Errors
ToolValidationError when a name or description is invalid, a new name conflicts with
a -/_ variant of a registered one, or tools holds an MCP client.
Sourcepub fn get(&self, name: &str) -> Option<&Arc<dyn Tool>>
pub fn get(&self, name: &str) -> Option<&Arc<dyn Tool>>
The tool registered under exactly name (get).
Sourcepub fn resolve(&self, name: &str) -> Result<&Arc<dyn Tool>, Error>
pub fn resolve(&self, name: &str) -> Result<&Arc<dyn Tool>, Error>
Resolves a name the model used (resolve): an exact match, then a registered name whose
- become _ (my_tool finds my-tool), then a case-insensitive match.
§Errors
ToolNotFoundError when nothing matches.
Sourcepub fn remove(&mut self, name: &str)
pub fn remove(&mut self, name: &str)
Removes a tool by name; does nothing when it is not registered (remove).
Sourcepub fn tool_specs(&self) -> Vec<ToolSpec>
pub fn tool_specs(&self) -> Vec<ToolSpec>
The specs of every registered tool: sorted by name when
sort_tool_specs is set, otherwise in registration order
(toolSpecs).
Sourcepub fn sort_tool_specs(&self) -> bool
pub fn sort_tool_specs(&self) -> bool
Whether tool_specs sorts specs by name (sortToolSpecs). Defaults
to false, which keeps registration order.
Sourcepub fn set_sort_tool_specs(&mut self, sort: bool)
pub fn set_sort_tool_specs(&mut self, sort: bool)
Sets whether tool_specs sorts specs by name.
Trait Implementations§
Source§impl Clone for ToolRegistry
impl Clone for ToolRegistry
Source§impl Debug for ToolRegistry
impl Debug for ToolRegistry
Auto Trait Implementations§
impl !RefUnwindSafe for ToolRegistry
impl !UnwindSafe for ToolRegistry
impl Freeze for ToolRegistry
impl Send for ToolRegistry
impl Sync for ToolRegistry
impl Unpin for ToolRegistry
impl UnsafeUnpin for ToolRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more