Skip to main content

ToolCollection

Struct ToolCollection 

Source
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>

Source

pub fn new() -> ToolCollection<M>

Source

pub fn builder() -> CollectionBuilder<M>

Create a CollectionBuilder for constructing a collection with shared context and/or custom configuration.

Source

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.

Source

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.

Source

pub async fn call( &self, call: FunctionCall, ) -> Result<FunctionResponse, ToolError>

Source

pub fn unregister(&mut self, name: &str) -> Result<(), ToolError>

Source

pub fn get(&self, name: &str) -> Option<&ToolEntry<M>>

Source

pub fn meta(&self, name: &str) -> Option<&M>

Source

pub fn iter(&self) -> impl Iterator<Item = (&'static str, &ToolEntry<M>)>

Source

pub fn descriptions(&self) -> impl Iterator<Item = (&'static str, &'static str)>

Source

pub fn json(&self) -> Result<Value, ToolError>

Source§

impl<M> ToolCollection<M>

Source

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,

Source§

fn clone(&self) -> ToolCollection<M>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M> Default for ToolCollection<M>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<M> MetaArg<M> for M

Source§

fn into_meta(self) -> M

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.