ITool: a name, a description, an optional input schema, and a handler. The agent loop exposes the tool to the model, validates the arguments the model supplies against your schema, runs your handler, and feeds the result back into the conversation.
Defining a tool
ImplementITool<P, R>, where P is the validated input and R is the handler’s return type. Register the class with decorator.tool():
getTools, or pass it per request:
The ITool contract
A clear
getDescription and a precise getInputSchema are what make a tool reliable, because the model decides whether and how to call the tool entirely from those two. Describe the input fields in the schema and the tool’s purpose in the description.Validated input
WhengetInputSchema is present, the agent loop validates the model’s arguments against it before your handler runs. Inside handler, the input already matches the schema, so there are no manual checks to write. The schema is an ArkType assertion built with Assert from @talosjs/validation:
getInputSchema for a tool that takes no arguments.
Call hooks
A tool can observe or gate its own invocation with two optional hooks. When any tool on a run declares either hook, the agent loop bridges them onto the run automatically.onBeforeCall
Runs before the handler. Return a decision to allow, modify, or block the call, which is useful for permission checks or argument rewriting:
onAfterCall
Runs after the handler returns, for logging, metrics, or auditing:
ChatMiddlewareContext as their first argument, so they can read ctx.context, the runtime context passed to the call.