Skip to main content

ToolSet

Struct ToolSet 

pub struct ToolSet { /* private fields */ }
Expand description

An ordered group of tools, built once and handed to an agent.

Order is registration order and is what the model is shown. A set does not judge names: two tools with the same name are both kept, and LlmAgentBuilder::try_build is what rejects them.

use adam_llm_agent::{ToolCtx, ToolError, ToolOutput, ToolSet, Tool, tools};
use adam_model::ToolSpec;
use async_trait::async_trait;
use serde_json::{Value, json};

struct Clock;

#[async_trait]
impl Tool for Clock {
    fn spec(&self) -> ToolSpec {
        ToolSpec {
            name: "clock".into(),
            description: "What time is it?".into(),
            parameters: json!({"type": "object", "properties": {}}),
        }
    }
    async fn call(&self, _ctx: &ToolCtx, _args: Value) -> Result<ToolOutput, ToolError> {
        Ok(ToolOutput::text("12:00"))
    }
}

let set: ToolSet = tools![Clock];
assert_eq!(set.names(), ["clock"]);

Implementations§

§

impl ToolSet

pub fn new() -> ToolSet

An empty set.

pub fn tool(self, tool: impl Tool) -> ToolSet

Add a tool at the end.

pub fn dyn_tool(self, tool: Arc<dyn Tool>) -> ToolSet

Add an already shared tool at the end.

pub fn extend(self, other: ToolSet) -> ToolSet

Add every tool of other at the end.

pub fn wrap(self, f: impl FnMut(Arc<dyn Tool>) -> Arc<dyn Tool>) -> ToolSet

Replace every tool with what f makes of it: the place for middleware such as redaction or logging that wraps a tool in another tool.

use adam_llm_agent::{DynTool, ToolSet};

let set = ToolSet::new().wrap(|tool: DynTool| tool);
assert!(set.is_empty());

pub fn get(&self, name: &str) -> Option<&Arc<dyn Tool>>

The tool called name, if any (the first, when a name repeats).

pub fn names(&self) -> Vec<String>

The tools’ names, in order.

pub fn iter(&self) -> Iter<'_, Arc<dyn Tool>>

The tools, in order.

pub fn len(&self) -> usize

How many tools.

pub fn is_empty(&self) -> bool

Whether the set has no tools.

Trait Implementations§

§

impl Clone for ToolSet

§

fn clone(&self) -> ToolSet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
§

impl Debug for ToolSet

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for ToolSet

§

fn default() -> ToolSet

Returns the “default value” for a type. Read more
§

impl FromIterator<Arc<dyn Tool>> for ToolSet

§

fn from_iter<I>(iter: I) -> ToolSet
where I: IntoIterator<Item = Arc<dyn Tool>>,

Creates a value from an iterator. Read more
§

impl IntoIterator for ToolSet

§

type Item = Arc<dyn Tool>

The type of the elements being iterated over.
§

type IntoIter = IntoIter<Arc<dyn Tool>>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> <ToolSet as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

impl<'a> IntoIterator for &'a ToolSet

§

type Item = &'a Arc<dyn Tool>

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, Arc<dyn Tool>>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> <&'a ToolSet as IntoIterator>::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more