Skip to main content

ToolRegistry

Struct ToolRegistry 

Source
pub struct ToolRegistry { /* private fields */ }
Expand description

Registry of named tools for the LLM dispatch loop.

§Construction

max_iterations is required at construction — there is no zero-arg constructor and no way to create an unbounded loop (SC#5, D-12). Suggested default: 10.

let registry = ToolRegistry::new(10);
// or equivalently:
let registry = ToolRegistry::with_default_iterations();

§Dispatch

ToolRegistry::dispatch loops until the LLM returns a text response or the iteration cap is reached. At iteration 5 a warning is logged; at the cap an error is logged and Error::ToolIterationLimit is returned.

Implementations§

Source§

impl ToolRegistry

Source

pub fn new(max_iterations: u32) -> Self

Create a new registry with an explicit iteration cap.

There is no Default impl and no zero-arg new(). Every ToolRegistry must carry an explicit max_iterations to prevent unbounded loops (SC#5).

Source

pub fn with_default_iterations() -> Self

Convenience constructor with max_iterations = 10.

Source

pub fn register(&mut self, tool: ToolDef)

Register a tool definition.

If a tool with the same name is already registered, it is replaced.

Source

pub async fn dispatch( &self, messages: Vec<Message>, client: &dyn LlmClient, ) -> Result<Vec<Message>, Error>

Dispatch a tool-calling conversation loop.

Calls client.complete_with_tools repeatedly until the LLM returns a text response or max_iterations is reached. Each ToolUse response dispatches registered handlers and appends results before the next iteration.

§Iteration limits (SC#5, T-166-01)
  • At iteration 5: tracing::warn! (advisory — loop still continues).
  • At max_iterations: tracing::error! + Err(Error::ToolIterationLimit). This is a hard cap with no override path.
§Error surfacing (SC#6, T-166-02)

Handler Err(ToolError { message }) is sent to the LLM as a tool_result message carrying only message. Unknown tool names are also surfaced to the LLM as model-recoverable error strings (not Error::ToolNotFound) so the model can adapt its tool selection.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> PolicyExt for T
where T: ?Sized,

Source§

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

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, 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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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