({
agentDefinition,
promptMessages,
toolUseContext,
canUseTool,
isAsync,
canShowPermissionPrompts,
forkContextMessages,
querySource,
override,
model,
maxTurns,
preserveToolUseResults,
availableTools,
allowedTools,
onCacheSafeParams,
contentReplacementState,
useExactTools,
worktreePath,
description,
transcriptSubdir,
onQueryProgress,
}: {
agentDefinition: AgentDefinition
promptMessages: Message[]
toolUseContext: ToolUseContext
canUseTool: CanUseToolFn
isAsync: boolean
/** Whether this agent can show permission prompts. Defaults to !isAsync.
* Set to true for in-process teammates that run async but share the terminal. */
canShowPermissionPrompts?: boolean
forkContextMessages?: Message[]
querySource: QuerySource
override?: {
userContext?: { [k: string]: string }
systemContext?: { [k: string]: string }
systemPrompt?: SystemPrompt
abortController?: AbortController
agentId?: AgentId
}
model?: ModelAlias
maxTurns?: number
/** Preserve toolUseResult on messages for subagents with viewable transcripts */
preserveToolUseResults?: boolean
/** Precomputed tool pool for the worker agent. Computed by the caller
* (AgentTool.tsx) to avoid a circular dependency between runAgent and tools.ts.
* Always contains the full tool pool assembled with the worker's own permission
* mode, independent of the parent's tool restrictions. */
availableTools: Tools
/** Tool permission rules to add to the agent's session allow rules.
* When provided, replaces ALL allow rules so the agent only has what's
* explicitly listed (parent approvals don't leak through). */
allowedTools?: string[]
/** Optional callback invoked with CacheSafeParams after constructing the agent's
* system prompt, context, and tools. Used by background summarization to fork
* the agent's conversation for periodic progress summaries. */
onCacheSafeParams?: (params: CacheSafeParams) => void
/** Replacement state reconstructed from a resumed sidechain transcript so
* the same tool results are re-replaced (prompt cache stability). When
* omitted, createSubagentContext clones the parent's state. */
contentReplacementState?: ContentReplacementState
/** When true, use availableTools directly without filtering through
* resolveAgentTools(). Also inherits the parent's thinkingConfig and
* isNonInteractiveSession instead of overriding them. Used by the fork
* subagent path to produce byte-identical API request prefixes for
* prompt cache hits. */
useExactTools?: boolean
/** Worktree path if the agent was spawned with isolation: "worktree".
* Persisted to metadata so resume can restore the correct cwd. */
worktreePath?: string
/** Original task description from AgentTool input. Persisted to metadata
* so a resumed agent's notification can show the original description. */
description?: string
/** Optional subdirectory under subagents/ to group this agent's transcript
* with related ones (e.g. workflows/<runId> for workflow subagents). */
transcriptSubdir?: string
/** Optional callback fired on every message yielded by query() — including
* stream_event deltas that runAgent otherwise drops. Use to detect liveness
* during long single-block streams (e.g. thinking) where no assistant
* message is yielded for >60s. */
onQueryProgress?: () => void
})
| 246 | } |
| 247 | |
| 248 | export async function* runAgent({ |
| 249 | agentDefinition, |
| 250 | promptMessages, |
| 251 | toolUseContext, |
| 252 | canUseTool, |
| 253 | isAsync, |
| 254 | canShowPermissionPrompts, |
| 255 | forkContextMessages, |
| 256 | querySource, |
| 257 | override, |
| 258 | model, |
| 259 | maxTurns, |
| 260 | preserveToolUseResults, |
| 261 | availableTools, |
| 262 | allowedTools, |
| 263 | onCacheSafeParams, |
| 264 | contentReplacementState, |
| 265 | useExactTools, |
| 266 | worktreePath, |
| 267 | description, |
| 268 | transcriptSubdir, |
| 269 | onQueryProgress, |
| 270 | }: { |
| 271 | agentDefinition: AgentDefinition |
| 272 | promptMessages: Message[] |
| 273 | toolUseContext: ToolUseContext |
| 274 | canUseTool: CanUseToolFn |
| 275 | isAsync: boolean |
| 276 | /** Whether this agent can show permission prompts. Defaults to !isAsync. |
| 277 | * Set to true for in-process teammates that run async but share the terminal. */ |
| 278 | canShowPermissionPrompts?: boolean |
| 279 | forkContextMessages?: Message[] |
| 280 | querySource: QuerySource |
| 281 | override?: { |
| 282 | userContext?: { [k: string]: string } |
| 283 | systemContext?: { [k: string]: string } |
| 284 | systemPrompt?: SystemPrompt |
| 285 | abortController?: AbortController |
| 286 | agentId?: AgentId |
| 287 | } |
| 288 | model?: ModelAlias |
| 289 | maxTurns?: number |
| 290 | /** Preserve toolUseResult on messages for subagents with viewable transcripts */ |
| 291 | preserveToolUseResults?: boolean |
| 292 | /** Precomputed tool pool for the worker agent. Computed by the caller |
| 293 | * (AgentTool.tsx) to avoid a circular dependency between runAgent and tools.ts. |
| 294 | * Always contains the full tool pool assembled with the worker's own permission |
| 295 | * mode, independent of the parent's tool restrictions. */ |
| 296 | availableTools: Tools |
| 297 | /** Tool permission rules to add to the agent's session allow rules. |
| 298 | * When provided, replaces ALL allow rules so the agent only has what's |
| 299 | * explicitly listed (parent approvals don't leak through). */ |
| 300 | allowedTools?: string[] |
| 301 | /** Optional callback invoked with CacheSafeParams after constructing the agent's |
| 302 | * system prompt, context, and tools. Used by background summarization to fork |
| 303 | * the agent's conversation for periodic progress summaries. */ |
| 304 | onCacheSafeParams?: (params: CacheSafeParams) => void |
| 305 | /** Replacement state reconstructed from a resumed sidechain transcript so |
no test coverage detected