Custom tools
Tools are how the model acts on the world. Beyond the built-in tools, tool() lets you define your own — a typed function the model can call — from a Zod schema. The schema validates every call before your code runs, so your handler only ever sees well-formed input. Custom tools are appended after the built-ins and go through the same permission gate and allowedTools / disallowedTools filtering.
Defining a tool
The tool() signature
ToolContext
The handler's second argument carries per-call services provided by the kernel:
Security metadata
opts.security declares what a tool can reach, typed as ToolSecurity:
Hosts can inspect this metadata when selecting tools and composing a permission policy. It is a declaration, not an isolation boundary: in-process JavaScript tools are trusted host code. See deployment composition.
See also
- Built-in tools — the tool set that ships with the SDK.
- Permissions — gate custom and built-in tools with allow / ask / deny rules.
- Agent SDK overview — where custom tools fit in the assembled agent.
- CLI example — a full agent wiring custom tools end to end.