Skip to content

@Tool & @BindTool

The @Tool class decorator (tools/*.tool.ts) defines a typed capability that an @Agent can invoke during its tool-calling loop, or that can be called directly via app.tool(ToolClass).invoke(input) or exposed over MCP via @McpExpose. Every @Tool declares its input and output DTO classes from @agboss/core/dto and implements ToolHandler<In, Out>. The companion @BindTool method decorator binds tool callbacks onto component methods.

Complete @Tool example with all capabilities

Section titled “Complete @Tool example with all capabilities”

What options do @Tool and @BindTool accept?

Section titled “What options do @Tool and @BindTool accept?”
Option Type Required Description
name string Yes Snake_case or kebab-case tool name exposed to the model ("refund_card").
description string Yes Concise description telling the model what the tool does.
input DtoClass Yes DTO class (@agboss/core/dto) validating the tool’s input arguments and generating its JSON Schema.
output DtoClass Yes DTO class validating the plain object returned by run(input).
deps readonly Token[] No Constructor dependencies (ExecutionContext, SpendRecorder, @Injectable services) verified against constructor parameters.
prompt / promptUrls string / readonly string[] No Detailed usage instructions for the tool appended to the agent’s tool guidance.
channel Class No @ChannelRole or @Channel class that gates tool execution on human or external approval.
toolInterceptors readonly Class[] No @ToolInterceptor classes attached directly to this tool (BeforeToolCall / AfterToolCall).
excludeToolInterceptors readonly Class[] No Inherited application, workflow, or agent @ToolInterceptor classes exempted for this tool.
timeout Milliseconds No Per-call timeout (seconds(15)); defaults to seconds(30) and aborts executionContext.signal when exceeded.
maxResultSize Bytes No Maximum UTF-8 result size (kilobytes(256)) shown to the model before truncation (kilobytes(128) by default).
Related Entity Import Path Purpose
ToolHandler<TInput, TOutput> "@agboss/core" Contract implemented by @Tool and @McpTool classes (run(input: TInput): Promise<TOutput>).
ExecutionContext "@agboss/core" Injected via deps: [ExecutionContext]; provides step.idempotencyKey, step.callId, signal, executionId, and ownerId.
SpendRecorder "@agboss/core" Injected via deps: [SpendRecorder]; records external API spend (spendRecorder.record({ service, cost })) against @Budget limits.
app.tool(ToolClass).invoke(input) "@agboss/core" Executes a registered tool directly inside its own isolated execution context.
testTool(ToolClass, options?) "@agboss/core/testing" Isolated unit runner that executes run(input) with DI overrides and returns { output, spend }.
mockTool(ToolClass) "@agboss/core/testing" Mocks or spies on a tool inside a testWith(Application) workflow test.