defineTool
wraps one with Smithers runtime context: a deterministic idempotency key,
side-effect metadata, and the side-effect snapshot hook. The five built-in
tools (read, write, edit, grep, bash) are themselves defineTool
results and run inside the task’s sandbox.
defineTool
Wrap a Zod-validatedexecute function into a durable AI SDK tool. Pass the
result to an agent’s tools or a <Task>’s tools prop.
Tool name surfaced to the agent and stamped onto
ctx.toolName. Also the
default description.Human-readable description the agent sees. Defaults to
name.Zod schema for the tool’s input. Validated by the AI SDK before
execute
runs; execute receives the parsed args.Marks the tool as mutating external state. Opts the tool into Smithers
side-effect tracking and runs the durability snapshot hook after
execute.Whether re-running with the same input is safe. Defaults to
true when
sideEffect is false. With sideEffect: true, idempotent: false, retries
inject a warning that the tool was already called so the agent can verify
external state first.Runs the tool.
args is the parsed input; ctx is the tool context. If
sideEffect: true, idempotent: false and execute omits the second ctx
parameter, Smithers logs a startup warning, since you almost certainly need
ctx.idempotencyKey to handle retries safely.An AI SDK tool with attached Smithers metadata. Read the metadata with
getDefinedToolMetadata.sideEffect / idempotent pair drives retry behavior:
sideEffect | idempotent | Behavior |
|---|---|---|
false | true | Pure read. Replayed freely. No warnings. |
true | true | Mutates, but replay-safe (e.g. an upsert or PUT). No warnings. |
true | false | Mutates and not replay-safe (e.g. send email, charge payment). Retry warns the agent and supplies a stable ctx.idempotencyKey. |
git reset, mark it sideEffect: true.
Source defineTool.js · context.js · Tests tools-unit.test.js, define-tool-durability.test.js · See also Built-in Tools, SDK agents
getDefinedToolMetadata
Read the Smithers metadata attached bydefineTool. Returns null for plain
AI SDK tools or non-objects.
A tool (or any value). Inspected for the
Symbol.for("smithers.tool.metadata")
property.defineTool.js · Tests tools-unit.test.js · See also defineTool
Built-in tools
FivedefineTool results, all sandboxed to ctx.rootDir (the workflow
directory by default). Paths resolve against the root; symlink escapes are
rejected. Output is truncated to ctx.maxOutputBytes (200KB). Import them
individually or as the tools bundle:
| Tool | sideEffect | idempotent |
|---|---|---|
read | false | true |
grep | false | true |
write | true | false |
edit | true | false |
bash | true | false |
read
Read a UTF-8 file from the sandbox.File path, relative to
rootDir or absolute within it.maxOutputBytes.
write
Write content to a file, creating parent directories as needed.Destination path, relative to
rootDir or absolute within it.File contents.
"ok". Throws TOOL_CONTENT_TOO_LARGE if content exceeds
maxOutputBytes; only the content’s byte size and SHA-256 hash are logged,
never the content itself.
edit
Apply a unified-diff patch to an existing file.File to patch. Must already exist.
A unified diff. Applied against the current contents.
"ok". Throws TOOL_PATCH_TOO_LARGE (patch over maxOutputBytes) or
TOOL_PATCH_FAILED (the patch context does not match the file).
grep
Search for a pattern withripgrep (rg -n). Requires rg on PATH.
Regex to search for.
Directory or file to search, relative to
rootDir.file:line:text. No matches returns an empty
string; an rg error (exit code 2) throws TOOL_GREP_FAILED.
bash
Run an executable with arguments. There is no shell parsing: pass arguments viaargs, and for pipes or redirects invoke a shell explicitly, e.g.
{ cmd: "sh", args: ["-lc", "..."] }.
Executable name or path. Up to 8,192 characters.
Arguments. Up to 128 entries, each up to 8,192 characters.
cwd sets the working directory (sandboxed under rootDir). Defaults to
rootDir.maxOutputBytes. A non-zero
exit code throws TOOL_COMMAND_FAILED. The process is killed with SIGKILL
after ctx.timeoutMs (default 60s; the hard cap is one hour).
Network is blocked unless
allowNetwork is enabled (via RunOptions,
--allow-network, or server config). When blocked, Smithers rejects commands
whose executable basename is curl, wget, npm, bun, or pip, any token
beginning with http:// or https://, and git together with a push,
pull, fetch, clone, or remote token (throwing TOOL_NETWORK_DISABLED
or TOOL_GIT_REMOTE_DISABLED). Local git commands such as git status are
allowed. On macOS, a blocked bash additionally runs under sandbox-exec with
a network-deny profile when available.tools/index.js · bash.js, read.js, write.js, edit.js, grep.js · Tests tools-unit.test.js · See also Built-in Tools, Common External Tools, SDK agents