vercel/ai · error · Error
Deep Agents runtime was not initialized
Error message
Deep Agents runtime was not initialized
What it means
`runTurn` reads the module-level `agent` variable after a possible rebuild and throws if it is still undefined. Since `rebuildAgent` is true whenever `agent == null`, reaching this throw means agent creation silently failed to assign the variable or the code path was bypassed. It is a defensive invariant check that the Deep Agents runtime exists before streaming.
Source
Thrown at packages/harness-deepagents/src/bridge/index.ts:296
agent = createDeepAgent({
tools: [...mcpTools, ...hostTools],
backend: createLocalShellBackend({ rootDir: workdir }),
systemPrompt: start.instructions
? { suffix: start.instructions }
: undefined,
// Native skills loaded from the source dirs ($HOME-materialized + <workDir> for repo-provided skills).
...(start.skillsPaths?.length ? { skills: start.skillsPaths } : {}),
...(middleware.length > 0 ? { middleware } : {}),
// Gate built-in tools behind HITL approval when the permission mode requires it.
...(interruptOn ? { interruptOn } : {}),
// Real instance (LangGraph rejects `true` for root graphs); gives multi-turn memory.
checkpointer,
});
agentConfigurationSignature = nextAgentConfigurationSignature;
}
const activeAgent = agent;
if (activeAgent == null) {
throw new Error('Deep Agents runtime was not initialized');
}
const hostToolNames = new Set((start.tools ?? []).map(t => t.name));
const streamEventState = createDeepAgentsStreamEventState();
const emitStreamEvent = createEmitStreamEvent({
state: streamEventState,
configuredModel: activeModel,
hostToolNames,
mcpToolNames,
structuredOutputToolNames: new Set(
currentResponseFormat?.map(format => format.name) ?? [],
),
emit,
});
// After a stream segment ends, return the tool calls paused by HITL interrupts (empty when the turn is truly done).
const readPendingApprovals = async () => {
try {View on GitHub (pinned to 69428b1f8b)
Solutions
- Restart the bridge process (start a fresh harness session) so the agent is rebuilt from the start message.
- Check logs above this error for a swallowed exception during `createDeepAgent` (e.g. MCP tool loading or middleware creation failures).
- Avoid running turns concurrently against the same bridge process; turns share the module-level `agent`.
- If reproducible, file a bug — this throw is an invariant guard and should be unreachable in normal operation.
Defensive patterns
Strategy: retry
Try / catch
try {
await runTurn(start);
} catch (error) {
if (error instanceof Error && error.message.includes('runtime was not initialized')) {
// restart the bridge process and retry once
}
throw error;
} Prevention
- Restart the bridge on initialization errors
- Run one turn at a time per bridge process
- Watch logs for swallowed createDeepAgent failures
When it happens
Trigger: `runTurn` reaching the streaming phase with `agent` still undefined — practically only if agent construction (`createDeepAgent`) was skipped or an exception path left the variable unset while execution continued.
Common situations: A corrupted bridge process state after a failed rebuild; race between concurrent turns mutating the module-level `agent`; a bug where the rebuild branch was not entered despite a null agent.
Related errors
- no active turn
- Invalid argument for parameter requests: requests must not b
- Invalid argument for parameter requests: request IDs must no
- Invalid argument for parameter requests: request IDs must be
- Invalid argument for parameter batch: batch must be a suppor
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/3b9fb5468a6902b1.
Report an issue: GitHub.