Deep Agents
The Deep Agents harness adapter connects HarnessAgent to
Deep Agents, a LangGraph-based agent
runtime. The adapter runs a Node bridge inside the sandbox that drives the
deepagents package and streams its streamEvents output back to the host over a
sandbox-exposed WebSocket.
Harness packages are experimental. Expect breaking changes between releases as this early API gets further refined.
Setup
$ pnpm add @ai-sdk/harness @ai-sdk/harness-deepagents @ai-sdk/sandbox-vercel
$ npm install @ai-sdk/harness @ai-sdk/harness-deepagents @ai-sdk/sandbox-vercel
$ yarn add @ai-sdk/harness @ai-sdk/harness-deepagents @ai-sdk/sandbox-vercel
$ bun add @ai-sdk/harness @ai-sdk/harness-deepagents @ai-sdk/sandbox-vercel
The adapter bootstraps the bridge's Node dependencies (the deepagents package
and LangChain) inside the sandbox via pnpm when the first session starts.
Import
deepAgents is equivalent to createDeepAgents() with its default
configuration.
Basic Usage
To use this agent, ensure environment variables include VERCEL_OIDC_TOKEN for
Vercel Sandbox, and one of the variables listed under
authentication for the model provider.
Adapter Settings
Use createDeepAgents() to configure the runtime:
Settings:
auth: authentication mode (auto,anthropic, orai-gateway) or an isolated authentication environment.credentialForwarding: optional synchronous or asynchronous callback that customizes each credential immediately before the harness adapter forwards it into a sandbox process. It receives the credential value that would otherwise be forwarded (either the real credential or a masked value) and the environment variable name used to expose it. This callback only controls the value forwarded into the sandbox process. It does not restrict which credentials the harness adapter can discover, read, or otherwise access in the host process.mcpServers: MCP server definitions keyed by server name.port: bridge port override.recursionLimit: maximum LangGraph super-steps per turn. When omitted, the Deep Agents default applies.startupTimeoutMs: maximum time to wait for the bridge to start.hostDisconnectTimeoutMs: aborts a running turn when the host disconnects and no host reconnects within this many milliseconds. A suspended turn is not aborted. When unset, a turn keeps running in the sandbox after its host disconnects, including when the host process is gone for good, until the turn finishes or the sandbox stops.reconnect: reconnect timing after an established bridge WebSocket connection drops.maxElapsedMscontrols the total retry window, including connection establishment and backoff delays, and defaults to 30 seconds.initialDelayMsdefaults to 50 milliseconds, andmaxDelayMsdefaults to 2 seconds. These retries use exponential backoff and are separate fromstartupTimeoutMs. They cannot recover when the sandbox, bridge process, or bridge endpoint is permanently unavailable.mintBridgeToken: synchronous function that receives the sandbox id and returns the bridge authentication token. By default, the adapter generates a random 32-byte token. Custom implementations must return a suitably secret token.
Structured Output
Deep Agents supports schema-backed HarnessAgent structured output.
The adapter applies a per-turn LangChain tool strategy and returns the graph's
validated structuredResponse as JSON text.
Authentication
Deep Agents always drives the Anthropic client. Non-Anthropic models reach it through AI Gateway's Anthropic-compatible endpoint, which translates to any model (Gemini, OpenAI, etc.), tool calls included.
The auth setting selects how credentials are resolved from the host
environment:
auto(default): use AI Gateway credentials when available, then fall back to Anthropic credentials.anthropic: use Anthropic credentials.ai-gateway: use AI Gateway credentials.
When the sandbox supports additive request transformations, the bridge receives placeholders and the adapter injects credentials into matching outbound requests. Sandboxes without that capability retain direct credential forwarding.
Supported environment variables:
AI_GATEWAY_API_KEYVERCEL_OIDC_TOKENAI_GATEWAY_BASE_URLANTHROPIC_API_KEYANTHROPIC_AUTH_TOKENANTHROPIC_BASE_URL
To run a non-Anthropic model, select ai-gateway:
Pass an authentication environment to use programmatically resolved
credentials without reading process.env:
The supplied record replaces the host environment for authentication discovery. Only recognized authentication variables are forwarded.
Sandbox
Deep Agents requires a network sandbox with at least one exposed port,
e.g. @ai-sdk/sandbox-vercel:
Skills
Skills passed to the session are materialized as native Deep Agents skill folders
(<name>/SKILL.md plus any attached files) under $HOME/.agents/skills/ in the
sandbox (outside the work dir, so they can't clash with cloned code), and loaded
via Deep Agents' skills option — so the agent loads them on demand and skill
file references resolve. Skills already present under <workDir>/.agents/skills/
(e.g. in a cloned repo) are also discovered.
Built-in Tools
The adapter exposes these Deep Agents built-ins through agent.tools:
readwriteeditdeletebashgrepgloblstaskwrite_todos
Built-in Tool Approvals
With permissionMode: 'allow-reads' or 'allow-edits', file reads are
automatically approved only within the session workdir or an active skill's
directory. allow-edits automatically approves file changes only within the
workdir. Paths outside those directories, including symlink targets, and paths
that cannot be resolved require host approval through Deep Agents' native
human-in-the-loop interrupts. Native absolute paths keep their original meaning.
allow-all remains unrestricted. These approval rules are not a filesystem
sandbox, and approved shell commands can access paths outside the workdir.
Known Limitations
- Resuming a stopped session's conversation is not supported — after
session.stop(), Deep Agents' in-memory conversation state (LangGraphMemorySaver) is gone; only the sandbox workspace persists via its snapshot. Usesession.detach()for cross-process handoff orsession.suspendTurn()for turn continuation while keeping the live bridge running. - Manual compaction is not supported.