API Reference

Built-in Tools

Exhaustive API reference for all 8 built-in tools — Read, Grep, List, Write, Edit, Bash, Skill, and JavaScript.

Use activeTools to restrict which tools are available per-agent or per-session. Use needsApproval to require human approval before specific tools execute.

import { agent } from "experimental-agent";

agent("my-agent", { activeTools: ["Read", "Grep", "List"] });

const session = myAgent.session(id, { activeTools: ["Read", "Grep", "List", "MyCustomTool"] });

Read

Read files with optional pagination. For files over 200 lines, automatically shows first 100 lines unless a specific line range is provided.

Input

ParameterTypeRequiredDescription
labelstringYesLabel describing the action.
pathstringYesPath to file relative to workspace root.
startLinenumberNoStarting line (1-indexed). With endLine, reads exact range.
endLinenumberNoEnding line (1-indexed, inclusive). With startLine, reads exact range.

Output

FieldTypeDescription
contentstringFile content (or requested range).
metadata.totalLinesnumberTotal lines in file.
metadata.linesShownnumberLines included in response.
metadata.startLinenumberFirst line shown (1-indexed).
metadata.endLinenumberLast line shown (1-indexed).
metadata.isPaginatedbooleanWhether this is a partial view.
metadata.fileSizestringHuman-readable size (e.g. "2.5K", "1.2M").
metadata.pathstringPath to file.

Notes: Auto-paginates files over 200 lines (shows first 100). Use startLine and endLine for exact ranges on large files.


Grep

Search files with ripgrep. Find code patterns, function definitions, imports, etc.

Input

ParameterTypeRequiredDefaultDescription
labelstringYesLabel describing the action.
patternstringYesRegex pattern (ripgrep syntax).
pathstringNo"."Path to search (file or directory).
fileTypestringNoFilter by type (e.g. "ts", "js", "py", "md").
globstringNoGlob filter (e.g. "*.tsx", "src/**/*.ts").
caseSensitivebooleanNotrueCase-sensitive search.
contextLinesnumberNoLines before/after each match.
maxCountnumberNoMax matches per file.
filesWithMatchesbooleanNofalseOnly show file paths, not matching lines.

Output

FieldTypeDescription
matchesstringSearch results with paths, line numbers, content.
summary.matchCountnumberNumber of matches.
summary.fileCountnumberFiles containing matches.
summary.searchPathstringPath searched.
summary.patternstringPattern searched.

Notes: Output truncated at ~50k chars. Use more specific pattern or path for large result sets.


List

Recursively list directory contents. Control depth for overview vs. detail.

Input

ParameterTypeRequiredDefaultDescription
labelstringYesLabel describing the action.
pathstringNo"."Path to list.
depthnumberNoMax depth (1–2 overview, 3–4 detailed, 5+ comprehensive).
includeHiddenbooleanNofalseInclude hidden files (starting with .).
filesOnlybooleanNofalseOnly files, not directories.
patternstringNoGlob filter (e.g. "*.ts", "*test*").

Output

FieldTypeDescription
listingstringDirectory tree, paths relative to search root.
summary.totalItemsnumberTotal items found.
summary.totalFilesnumberTotal files.
summary.totalDirsnumberTotal directories.
summary.searchPathstringPath listed.
summary.depthnumberMax depth used (if specified).

Write

Write content to a file. Creates parent directories. Overwrites existing files.

Input

ParameterTypeRequiredDescription
labelstringYesLabel describing the action.
pathstringYesPath relative to workspace root.
contentstringYesContent to write.

Output

FieldTypeDescription
successbooleanWhether write succeeded.
pathstringPath written.
bytesWrittennumberBytes written.
errorstringError message if failed.

Edit

Edit a file by exact string replacement. Fails if old_string is not found or appears multiple times.

Input

ParameterTypeRequiredDescription
labelstringYesLabel describing the action.
pathstringYesPath relative to workspace root.
old_stringstringYesExact string to find and replace (must be unique).
new_stringstringYesReplacement string.

Output

FieldTypeDescription
successbooleanWhether edit succeeded.
pathstringPath edited.
errorstringError message if failed.

Notes: Include enough surrounding context to make old_string unique. For multiple replacements, call the tool multiple times.


Bash

Execute bash commands. Returns stdout and stderr. Use waitUntil to control how long to wait.

Input

ParameterTypeRequiredDefaultDescription
labelstringYesLabel describing the action.
commandstringYesShell command to execute.
waitUntilnumberNo2000Max ms to wait. Use 0 to return immediately; process keeps running.

Output

FieldTypeDescription
commandIdstringUse to reference or kill the process.
stdoutstringCommand stdout. Tail-truncated if large.
stderrstringCommand stderr. Tail-truncated if large.
exitCodenumberExit code (-1 if still running).
status"running" | "completed" | "failed"Process status.
outputDirstringPath to output dir with stdout.txt, stderr.txt, metadata.json. Empty if still running.

Notes: waitUntil=0 returns immediately; process continues in sandbox. Large outputs truncated (~50k stdout, ~10k stderr); full content in outputDir.


Skill

Load a skill's full instructions by name. Call before following a skill. Only available when skills is configured.

Input

ParameterTypeRequiredDescription
labelstringYesLabel describing the action.
namestringYesSkill name from Available Skills list.

Output

FieldTypeDescription
namestringSkill name.
descriptionstringSkill description.
contentstringFull SKILL.md content (body after frontmatter).
pathstringPath to skill directory in sandbox.

Notes: Tool is omitted when skills is not set. Throws if skill not found.


JavaScript

Execute JavaScript code dynamically. Code runs as async function body with ctx in scope. Must return to produce output. Can call other tools as sub-tools via ctx.tools.

Input

ParameterTypeRequiredDescription
labelstringYesLabel describing the action.
codestringYesJavaScript async function body. ctx is in scope. Must use return to produce output.

Output

Returns whatever the code returns. undefined or missing return yields null.

Notes: Code runs in sandbox via Node.js. ctx has tools (call other tools), session, sandbox, storage, context. Execution timeout: 5 minutes. Can invoke Read, Write, Edit, Grep, List, Bash, and custom tools as sub-tools.


activeTools

Restrict which tools are available at agent or session level:

agent("my-agent", {
  activeTools: ["Read", "Grep", "List"],
});

const session = myAgent.session(id, {
  activeTools: ["Read", "Grep", "List", "Deploy"],
});

Session-level activeTools overrides agent-level. Include both built-in and custom tool names.

builtinToolNames

Use for type-safe tool references:

import { builtinToolNames } from "experimental-agent";

builtinToolNames.Read;   // "Read"
builtinToolNames.Bash;   // "Bash"
builtinToolNames.Write;  // "Write"

See also