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
impl ToolRegistry
Sourcepub fn new(max_iterations: u32) -> Self
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).
Sourcepub fn with_default_iterations() -> Self
pub fn with_default_iterations() -> Self
Convenience constructor with max_iterations = 10.
Sourcepub fn register(&mut self, tool: ToolDef)
pub fn register(&mut self, tool: ToolDef)
Register a tool definition.
If a tool with the same name is already registered, it is replaced.
Sourcepub async fn dispatch(
&self,
messages: Vec<Message>,
client: &dyn LlmClient,
) -> Result<Vec<Message>, Error>
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.