/** * Deep agents: agents for long, multi-step work — a plan, a workspace, helpers to delegate to, skills * to load when needed, and a context that stays small however long the work runs. * * A preset, not an engine: `createDeepAgent()` composes `createAgent()` with its tools and middleware, * and returns the same compiled graph, with the same checkpoints, approvals, events, and server * support as any agent. */ import { type AgentGraph, type AgentMiddleware, type CreateAgentOptions } from '../agent/create-agent.js'; import { type Interpreter } from '../agent/interpreter.js'; import { type ContextEditorOptions } from '../agent/middleware/context-editor.js'; import { type ContextOffloadOptions } from '../agent/middleware/filesystem.js'; import { type ToolSelectorOptions } from '../agent/middleware/tool-selector.js'; import { type PermissionPolicyLike } from '../agent/permissions.js'; import { type Sandbox } from '../agent/sandbox.js'; import { type Workspace } from '../agent/workspace.js'; import { type DeepHelperLimits, type DeepRemoteHelper } from './helpers.js'; export type { DeepHelperLimits, DeepRemoteHelper, DeepRemoteRunResult } from './helpers.js'; /** A helper the deep agent can hand a self-contained piece of work to, with a fresh context. */ export interface DeepSubagent { /** Its name, as the agent delegates to it. */ name: string; /** What it is for, written for the model that decides when to delegate. */ description: string; /** Its own instructions. */ instructions: string; /** * The tools it may use, by name, from the deep agent's own. Defaults to all of them except * `delegate`, so a helper cannot delegate in turn. A tool named in `interruptOn` is never a * helper's: a helper keeps no checkpoints, so it could not pause for the approval. */ tools?: readonly string[]; /** Its model. Defaults to the deep agent's. */ model?: string; /** Model calls it may make. Defaults to 20. */ maxIterations?: number; /** * Runs it on another agent server instead, such as `createRemoteGraph()` reaches: it is sent its * `instructions` and the task, and its run's output is its answer. The run is leased to the * server's worker that runs it, so another worker takes it over when that one stops, and the agent * finds the same run again by the call that started it. `tools`, `model`, and `maxIterations` are * the remote assistant's own. */ remote?: DeepRemoteHelper; } /** Instructions the agent loads only when a task needs them: a procedure, a checklist, a house style. */ export interface DeepSkill { /** Its name, as the agent asks for it. */ name: string; /** When it applies, written for the model. Only this is in the agent's context until it is loaded. */ description: string; /** The instructions themselves. */ instructions?: string; /** A file in the workspace that holds them, read when the skill is loaded, instead of `instructions`. */ file?: string; } /** Options for `createDeepAgent()`. Everything `createAgent()` takes, and the parts of a deep agent. */ export interface DeepAgentOptions extends Omit { /** What this agent is for. Placed before the deep agent's own working instructions. */ instructions?: string; /** * Where the agent's files live: what it reads, writes, searches, and edits, its skills' files, its * `include` files, and the results it offloads, mounted at `/workspace`. Any `Workspace`: in * memory, on disk, in a store, a sandbox, or a composite of several. Defaults to the sandbox; * without either, the agent has no files and no offloading. */ workspace?: Workspace; /** * Where the agent runs commands, through `run_command`. Without `workspace`, it is also where the * agent's files live, so its commands see them; with both, its commands see the sandbox's own * files, unless the sandbox is mounted in the workspace. */ sandbox?: Sandbox; /** * Commands the agent may run in the sandbox, as prefixes a permission policy grants: `node`, * `npm test`, `git status`. Without any, or without a sandbox, there is no `run_command` tool. */ commands?: readonly string[]; /** Records a plan with `write_todos` and keeps it current. Defaults to true. */ planning?: boolean; /** * Runs the model's code with the agent's own tools callable from it, as `run_code`, so many calls * take one step. Every call the code makes is decided by the agent's policy, and a tool that needs * approval cannot be called from code. Given one, the default policy grants `code`. */ interpreter?: Interpreter; /** * Helpers the agent can delegate to through one `delegate` tool. The agent waits for a helper's * answer, or sets `background` and collects it later with `collect_helper`. */ subagents?: readonly DeepSubagent[]; /** * Lets the agent create helpers during a run, from instructions it writes, within these limits. * Off unless given. */ createHelpers?: DeepHelperLimits; /** How many helpers may work in the background in one thread at once. Defaults to 4. */ maxBackgroundHelpers?: number; /** Skills the agent can load through `load_skill`. */ skills?: readonly DeepSkill[]; /** Instruction files from the workspace the model sees on every call. Defaults to `AGENTS.md`. */ include?: readonly string[]; /** * Writes tool results longer than the limit to `.context/` in the workspace, leaving a preview and the * path. Defaults to results over 20,000 characters; `false` keeps them whole. */ offload?: ContextOffloadOptions | false; /** * Clears old tool results from what the model is sent once the request grows. Defaults to past * 60,000 estimated tokens, never clearing the plan; `false` turns it off. */ contextEditing?: ContextEditorOptions | false; /** * Sends the model only the tools relevant to the turn, for an agent with many. The deep agent's own * tools are always sent. Off unless given. */ toolSelection?: ToolSelectorOptions; /** * Decides every tool call. Defaults to a policy that grants the workspace, the `commands`, the plan, * delegation, and skills, and denies everything else, so a tool of your own needs a grant here or * its own policy. `false` runs every call. */ permissions?: PermissionPolicyLike | false; /** Middleware run after the deep agent's own. */ middleware?: AgentMiddleware[]; } /** * Builds a deep agent: `createAgent()` with a plan, a sandboxed workspace, subagents, skills, context * offloading, optional tool selection, and a permission policy. * * ```ts * const agent = createDeepAgent({ * client: ai, * model: 'claude-sonnet-5-5', * instructions: 'You maintain this repository.', * sandbox, * commands: ['node', 'npm test', 'git diff'], * subagents: [{ name: 'reviewer', description: 'Reviews a change', instructions: 'Review the diff for bugs.' }], * skills: [{ name: 'release-notes', description: 'Writing release notes', file: 'skills/release-notes.md' }], * checkpointer, * }); * const run = await agent.invoke(agentInput('Fix the failing test'), { threadId }); * ``` */ export declare function createDeepAgent(options: DeepAgentOptions): AgentGraph;