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 builder() -> CollectionBuilder<M>
pub fn builder() -> CollectionBuilder<M>
Create a CollectionBuilder for constructing a collection with
shared context and/or custom configuration.
Sourcepub fn register_raw<A>(
&mut self,
name: &'static str,
description: &'static str,
parameters: Value,
func: impl Fn(Value) -> Pin<Box<dyn Future<Output = Result<Value, ToolError>> + Send>> + Send + Sync + 'static,
meta: A,
) -> Result<&mut ToolCollection<M>, ToolError>where
A: MetaArg<M>,
pub fn register_raw<A>(
&mut self,
name: &'static str,
description: &'static str,
parameters: Value,
func: impl Fn(Value) -> Pin<Box<dyn Future<Output = Result<Value, ToolError>> + Send>> + Send + Sync + 'static,
meta: A,
) -> Result<&mut ToolCollection<M>, ToolError>where
A: MetaArg<M>,
Register a tool from a pre-built JSON schema and a raw async closure.
Unlike register, this bypasses ToolSchema
derivation — the caller supplies the JSON schema directly. The
closure receives only the JSON arguments (no context). This is the
foundation for FFI adapters that register tools from scripting
languages.
Pass () as meta for ToolCollection<NoMeta>; pass an M for
typed collections.
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>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more