ToolRegistry
Defined in: tools/registry.ts:43
A named collection of tools you build once and resolve from by name.
Remarks
Composition helper, NOT a loop dependency. runAgent still takes a plain
Tool[] and never sees a registry — the loop is untouched. You keep the
catalog here and feed the loop the array you want. Because it only produces a
Tool[], you can adopt it incrementally and drop it anytime without touching
the loop.
Why it exists: tools are authored as objects, but some callers only have names — config, a CLI flag, or a stored list that names the tools a given run may use. Those callers need a name → Tool resolver; that resolver is this registry.
Fail fast (per the project's error-handling rule): registering a duplicate name (ToolRegistry.register) or resolving an unknown one (ToolRegistry.resolve) throws a descriptive error rather than silently overwriting or dropping a tool — both are almost always wiring bugs.
See
Example
const registry = new ToolRegistry([searchTool(backend), shellTool(backend)]);
// every registered tool:
await runAgent({ ...opts, tools: registry.list() });
// or just a named subset for this run/step:
await runAgent({ ...opts, tools: registry.resolve(["search"]) });Constructors
Constructor
new ToolRegistry(tools?): ToolRegistry;Defined in: tools/registry.ts:57
Create a registry, optionally seeded with an initial set of tools.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
tools | Tool<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>[] | [] | Initial tools to register, in order. Defaults to empty. |
Returns
ToolRegistry
Remarks
Each seed tool is added via ToolRegistry.register, so the same duplicate-name rule applies.
Throws
Error If two seed tools share a name.
Methods
get()
get(name):
| Tool<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>
| undefined;Defined in: tools/registry.ts:97
Get the tool registered under a name.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The tool name to look up. |
Returns
| Tool<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>
| undefined
The registered tool, or undefined if there is none.
See
ToolRegistry.resolve for a throwing, multi-name variant.
has()
has(name): boolean;Defined in: tools/registry.ts:86
Report whether a tool with this name is registered.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The tool name to look up. |
Returns
boolean
true if a tool with this name is registered.
list()
list(): Tool<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>[];Defined in: tools/registry.ts:106
List every registered tool.
Returns
Tool<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>[]
All registered tools, in registration order.
names()
names(): string[];Defined in: tools/registry.ts:115
List every registered tool name.
Returns
string[]
All registered tool names, in registration order.
register()
register(tool): this;Defined in: tools/registry.ts:72
Add a tool, keyed by its name.
Parameters
| Parameter | Type | Description |
|---|---|---|
tool | Tool | The tool to register. |
Returns
this
this, so registrations can chain.
Remarks
Re-registration is treated as a wiring bug, not an update, so a duplicate name throws rather than overwriting.
Throws
Error If a tool with the same name is already registered.
resolve()
resolve(names): Tool<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>[];Defined in: tools/registry.ts:132
Resolve a list of names to their tools, in the order requested.
Parameters
| Parameter | Type | Description |
|---|---|---|
names | string[] | The tool names to resolve, in the order they should appear. |
Returns
Tool<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>[]
The matching tools, in the requested order.
Remarks
Throws on the first unknown name (listing what is available), so a caller that asks for a tool that was never registered fails loudly at wiring time instead of silently running without it.
Throws
Error On the first name that is not registered; the message lists the available names.
See
ToolRegistry.get for a non-throwing single-name lookup.