Agent interface, so they work as drop-in replacements anywhere you would use an AI SDK agent — including in <Task> components.
The agents spawn the corresponding CLI process, pass the prompt via arguments or stdin, capture the output, and return it in the standard GenerateTextResult format.
Import
Prerequisites
Each agent requires its corresponding CLI tool installed and available in the system PATH:| Agent | CLI Required | Install |
|---|---|---|
ClaudeCodeAgent | claude | Claude Code CLI |
CodexAgent | codex | OpenAI Codex CLI |
GeminiAgent | gemini | Gemini CLI |
PiAgent | pi | PI Coding Agent |
Quick Start
Base Options
All CLI agent classes share a common set of base options:| Option | Default | Description |
|---|---|---|
id | Random UUID | Unique identifier for the agent instance |
model | undefined | Model name passed to the CLI’s --model flag |
systemPrompt | undefined | System-level instructions prepended to the prompt |
instructions | undefined | Alias for systemPrompt |
cwd | Tool context rootDir or process.cwd() | Working directory for the spawned process |
env | {} | Extra environment variables merged with process.env |
yolo | true | When true, configures the CLI to skip all interactive permission prompts |
timeoutMs | undefined | Kill the process after this many milliseconds |
maxOutputBytes | undefined | Truncate captured output to this size |
extraArgs | [] | Arbitrary additional CLI flags |
ClaudeCodeAgent
Wraps theclaude CLI with --print mode.
Claude-Specific Options
| Option | Description |
|---|---|
outputFormat | Output format from the CLI: "text", "json", or "stream-json" (default: "text") |
permissionMode | Permission handling: "bypassPermissions", "acceptEdits", "default", "delegate", "dontAsk", "plan" |
allowedTools | Whitelist of tool names the CLI may use |
disallowedTools | Blacklist of tool names |
maxBudgetUsd | Spending cap in USD |
mcpConfig | MCP server configuration files |
addDir | Additional directories to include in the context |
yolo is true (the default), the agent automatically passes --allow-dangerously-skip-permissions, --dangerously-skip-permissions, and --permission-mode bypassPermissions unless permissionMode is explicitly set.
CodexAgent
Wraps thecodex CLI using codex exec with stdin input.
Codex-Specific Options
| Option | Description |
|---|---|
sandbox | Sandbox level: "read-only", "workspace-write", or "danger-full-access" |
fullAuto | Enable full auto mode (no confirmations) |
config | Configuration overrides as key-value pairs or raw strings |
oss | Use open-source models |
localProvider | Local model provider URL |
outputLastMessage | File path to write the last message (auto-generated temp file if not set) |
yolo is true and fullAuto is not set, the agent passes --dangerously-bypass-approvals-and-sandbox. If fullAuto is true, it uses --full-auto instead.
Input handling: The prompt (with system prompt prepended) is passed via stdin using the - argument.
GeminiAgent
Wraps thegemini CLI.
Gemini-Specific Options
| Option | Description |
|---|---|
sandbox | Run in sandbox mode |
approvalMode | Approval handling: "default", "auto_edit", "yolo", or "plan" |
allowedTools | Whitelist of tool names |
extensions | Gemini CLI extensions to load |
includeDirectories | Additional directories to include |
outputFormat | Output format: "text", "json", or "stream-json" (default: "text") |
yolo is true and approvalMode is not set, the agent passes --yolo.
Input handling: The prompt (with system prompt prepended) is passed via --prompt.
PiAgent
Wraps thepi CLI.
PI-Specific Options
| Option | Description |
|---|---|
provider | PI provider name passed to --provider |
model | PI model passed to --model |
apiKey | Passed to --api-key (visible in process listings; prefer PI env/config when possible) |
mode | PI mode: text, json, or rpc |
print | Force print mode (--print) in text mode only |
continue / resume / session | Session continuation controls (--continue, --resume, --session) |
sessionDir | Custom session directory (--session-dir) |
models / listModels | Scoped model patterns and model listing (--models, --list-models) |
extension | Load extension path(s) |
skill | Load skill path(s) |
promptTemplate | Load prompt template path(s) |
theme | Load theme path(s) |
tools / noTools | Enable specific tools or disable built-ins |
export | Export session HTML (--export) |
files | File args passed as @path (text/json modes only) |
onExtensionUiRequest | RPC-only handler for extension UI requests |
noSession | Disable session persistence (defaults to true unless session flags are set) |
text/json modes, the prompt is passed as a positional PI message argument and files are emitted as @path arguments. In rpc mode, the prompt is sent as a JSON prompt command over stdin (file args are not supported). Text mode defaults to --print and omits --mode, while json/rpc modes set --mode and do not pass --print.
Agent Interface
All CLI agents implement the AI SDKAgent interface with two methods:
generate(options)
Runs the CLI synchronously and returns a GenerateTextResult:
- Extracts the prompt from
options.prompt(string) oroptions.messages(array). - Builds the CLI command with all configured flags.
- Spawns the process and captures stdout/stderr.
- If the output format is
jsonorstream-json, extracts text from the JSON payload. - Returns the result wrapped in a
GenerateTextResult.
stream(options)
Calls generate() internally and wraps the result as a StreamTextResult. This is a convenience adapter — the actual CLI execution is not truly streamed.
Message Handling
When called with messages (as Smithers does internally), the agents convert them to a text prompt:- System messages are extracted and prepended as a system prompt.
- User/assistant messages are formatted as
ROLE: contentand joined with double newlines. - The system prompt from messages is combined with any
systemPromptconfigured on the agent instance.