pub struct ToolCollection<M = NoMeta> { /* private fields */ }Expand description
Collection of registered tools, parameterized by a metadata type M.
M defaults to NoMeta — an empty struct that swallows any
#[tool(...)] attributes a tool declared. Opt into typed metadata by
setting M explicitly:
ⓘ
let tools = ToolCollection::<MyPolicy>::collect_tools()?;
if tools.meta("delete_file").unwrap().requires_approval { ... }Implementations§
Source§impl<M> ToolCollection<M>
impl<M> ToolCollection<M>
pub fn new() -> ToolCollection<M>
Sourcepub fn register<A, I, O, F, Fut>(
&mut self,
name: &'static str,
desc: &'static str,
func: F,
meta: A,
) -> Result<&mut ToolCollection<M>, ToolError>where
A: MetaArg<M>,
I: 'static + DeserializeOwned + Serialize + Send + ToolSchema,
O: 'static + Serialize + Send + ToolSchema,
F: Fn(I) -> Fut + Send + Sync + 'static,
Fut: Future<Output = O> + Send + 'static,
pub fn register<A, I, O, F, Fut>(
&mut self,
name: &'static str,
desc: &'static str,
func: F,
meta: A,
) -> Result<&mut ToolCollection<M>, ToolError>where
A: MetaArg<M>,
I: 'static + DeserializeOwned + Serialize + Send + ToolSchema,
O: 'static + Serialize + Send + ToolSchema,
F: Fn(I) -> Fut + Send + Sync + 'static,
Fut: Future<Output = O> + Send + 'static,
Register a tool programmatically. Pass () as meta for
ToolCollection<NoMeta>; pass an M for typed collections.
Passing () to a typed collection is a compile error.
pub async fn call( &self, call: FunctionCall, ) -> Result<FunctionResponse, ToolError>
pub fn unregister(&mut self, name: &str) -> Result<(), ToolError>
pub fn get(&self, name: &str) -> Option<&ToolEntry<M>>
pub fn meta(&self, name: &str) -> Option<&M>
pub fn iter(&self) -> impl Iterator<Item = (&'static str, &ToolEntry<M>)>
pub fn descriptions(&self) -> impl Iterator<Item = (&'static str, &'static str)>
pub fn json(&self) -> Result<Value, ToolError>
Source§impl<M> ToolCollection<M>where
M: DeserializeOwned,
impl<M> ToolCollection<M>where
M: DeserializeOwned,
Sourcepub fn collect_tools() -> Result<ToolCollection<M>, ToolError>
pub fn collect_tools() -> Result<ToolCollection<M>, ToolError>
Collect every tool registered via #[tool]. Fails fast on the first
tool whose meta_json blob does not deserialize into M.
For accumulated, CI-friendly validation use validate_tool_attrs.
Trait Implementations§
Source§impl<M> Clone for ToolCollection<M>where
M: Clone,
impl<M> Clone for ToolCollection<M>where
M: Clone,
Source§fn clone(&self) -> ToolCollection<M>
fn clone(&self) -> ToolCollection<M>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<M> Default for ToolCollection<M>
impl<M> Default for ToolCollection<M>
Source§fn default() -> ToolCollection<M>
fn default() -> ToolCollection<M>
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl<M> Freeze for ToolCollection<M>
impl<M = NoMeta> !RefUnwindSafe for ToolCollection<M>
impl<M> Send for ToolCollection<M>where
M: Send,
impl<M> Sync for ToolCollection<M>where
M: Sync,
impl<M> Unpin for ToolCollection<M>where
M: Unpin,
impl<M> UnsafeUnpin for ToolCollection<M>
impl<M = NoMeta> !UnwindSafe for ToolCollection<M>
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
Mutably borrows from an owned value. Read more