ToolRegistry class final

A named collection of AgentTools with a ready-made executor for the agent loop.

The registry is mutable: tools can be registered and unregistered at any time, and executor always consults the live registry. The agent loop additionally checks tool existence against Context.tools, so a tool only executes when it is both registered here and listed in the agent state's tools for that run.

Constructors

ToolRegistry([Iterable<AgentTool> tools = const [], void onDuplicate(String note)?])
Creates a registry pre-populated with tools. Throws ConfigException on an empty tool name; a duplicate name replaces the earlier registration and is recorded in duplicateNotes (issue #862: replace-and-note — a wiring bug degrades loudly, a child never dies). onDuplicate fires for every duplicate registration (at construction AND later) so hosts can surface the wiring bug without polling.

Properties

agentTools → List<AgentTool>
All registered AgentTools. Unmodifiable snapshot.
no setter
duplicateNotes → List<String>
One note per duplicate-name registration, in order (issue #862): who replaced whom, so hosts can surface the wiring bug loudly.
no setter
executor → ToolExecutor
A ToolExecutor that validates arguments against the tool's schema and dispatches to the tool's AgentTool.execute.
no setter
hashCode → int
The hash code for this object.
no setterinherited
length → int
Number of registered tools.
no setter
names → List<String>
Names of all registered tools, in registration order.
no setter
onDuplicate ↔ void Function(String note)?
Called with each duplicate-registration note as it happens (issue #862 review: the note must surface, not silently accumulate).
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
tools → List<Tool>
All registered tools as provider-facing Tools, ready for Context.tools / AgentState.tools. Unmodifiable snapshot.
no setter

Methods

contains(String name) → bool
Whether a tool with name is registered.
lookup(String name) → AgentTool?
Looks up a tool by name; null when not registered.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
register(AgentTool tool) → void
Registers tool. Throws ConfigException if the name is empty. A duplicate name REPLACES the earlier registration and records a warning in duplicateNotes; the later registration wins (issue #862: never throw on a child's duplicate tool registration).
registerAll(Iterable<AgentTool> tools) → void
Registers every tool in tools.
toString() → String
A string representation of this object.
inherited
unregister(String name) → bool
Removes the tool with name; returns whether one was registered.

Operators

operator ==(Object other) → bool
The equality operator.
inherited
operator [](String name) → AgentTool
Looks up a tool by name, throwing ToolNotFoundException when missing.