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() -> Self
Sourcepub fn register<A, I, O, F, Fut>(
&mut self,
name: &'static str,
desc: &'static str,
func: F,
meta: A,
) -> Result<&mut Self, 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 Self, 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: DeserializeOwned> ToolCollection<M>
impl<M: DeserializeOwned> ToolCollection<M>
Sourcepub fn collect_tools() -> Result<Self, ToolError>
pub fn collect_tools() -> Result<Self, 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> Clone for ToolCollection<M>
impl<M: Clone> Clone for ToolCollection<M>
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