(runtimeMode: RuntimeMode | undefined)
| 293 | } |
| 294 | |
| 295 | export function buildTaskToolDescription(runtimeMode: RuntimeMode | undefined): string { |
| 296 | const isolationGuidance = runtimeModeSupportsSharedTaskWorkspace(runtimeMode) |
| 297 | ? "\n\nWorkspace isolation: by default each sub-agent runs in a forked copy of this workspace. " + |
| 298 | 'On this runtime you may pass isolation: "none" to run the sub-agent directly in this workspace\'s ' + |
| 299 | "checkout (shared working tree, including uncommitted changes), skipping the fork + init overhead. " + |
| 300 | 'Reserve isolation: "none" for read-only analysis (e.g. the explore agent) or when you instruct the ' + |
| 301 | "sub-agent to avoid editing shared files, since concurrent edits to the same files are possible. " |
| 302 | : ""; |
| 303 | return ( |
| 304 | "Spawn a sub-agent task (child workspace). " + |
| 305 | "\n\nIMPORTANT: Whether a sub-agent can see uncommitted changes depends on the runtime. " + |
| 306 | `${getTaskRuntimeVisibilityGuidance(runtimeMode)} ` + |
| 307 | "\n\nProvide agentId (preferred) or subagent_type, prompt, title, run_in_background, and optional n or variants. " + |
| 308 | `Use n when you want several agents to try the same prompt independently. Use variants when you want several agents to run the same prompt template with a different ${TASK_VARIANT_PLACEHOLDER} substituted into each run. ` + |
| 309 | "Examples: solve GitHub issues 45, 32, and 69 with one shared issue-solving template; investigate a regression across commit windows like A..B and B..C with one shared investigation template; or split a review into frontend/backend/tests/docs lanes with one shared review template. " + |
| 310 | `For variants, keep the shared template in the prompt and put the per-lane difference into ${TASK_VARIANT_PLACEHOLDER}. ` + |
| 311 | "n and variants are mutually exclusive; omit both for a single task. Leave n and variants unset unless the developer explicitly asks for parallel sibling tasks, and prefer non-interfering sub-agents for grouped runs (for example read-only agents like explore). " + |
| 312 | "\n\nWhen the user explicitly asks for best-of-n work, the parent should begin with light preliminary analysis to extract shared context, constraints, or evaluation criteria that would otherwise be duplicated across children. " + |
| 313 | "Keep that pre-work lightweight: frame the task and provide useful starting points, but do not pre-solve the problem or over-constrain how the children reason about it. Then delegate the substantive analysis to the spawned sub-agents. " + |
| 314 | "Do not also do a full parallel analysis in the parent. Call task_await when you are ready to act on child output; do not await reflexively just because tasks are running. " + |
| 315 | "task_await returns as soon as the first awaited task completes by default (min_completed), so you can start dependent work on each result as it lands instead of blocking on the whole batch; for best-of-N synthesis that must compare every candidate, pass min_completed equal to the batch size (or use a foreground grouped spawn, below). " + |
| 316 | "\n\nWhen delegating, include a compact task brief (Task / Background / Scope / Starting points / Acceptance / Deliverables / Constraints). " + |
| 317 | "For now, persisted sub-agent goals are not supported; pass sub-agent objectives, success criteria, and deliverables directly in the prompt. " + |
| 318 | "Sub-agents observe the same system instructions as the parent (project/global AGENTS.md and custom instructions), so do not restate that shared context in the prompt; spend the prompt on task-specific information the sub-agent cannot infer from those instructions. " + |
| 319 | "Caveat: instruction files are read from the child's checkout, so uncommitted AGENTS.md edits in the parent follow the same runtime visibility rules above — commit them first or pass the relevant guidance in the prompt. " + |
| 320 | "Avoid telling the sub-agent to read your plan file; child workspaces do not automatically have access to it. " + |
| 321 | "\n\nIf run_in_background is false, waits for the sub-agent to finish and returns the completed report. When grouped sibling tasks are requested via n or variants, the completed result includes one report per spawned task. " + |
| 322 | "If the foreground wait times out, returns queued/starting/running task metadata with a note (the task continues running); use task_await to monitor progress. " + |
| 323 | "If run_in_background is true, returns immediately with queued/starting/running task metadata and the task runs non-blocking: you may end your turn without awaiting it, and Mux wakes this workspace when the task reaches a terminal state so you can integrate its result. Use task_await only when the current request depends on the output before you can answer, or to inspect progress. " + |
| 324 | "Prefer run_in_background: false when spawning a single task — it is equivalent to spawning background + immediately awaiting, but saves a round-trip. " + |
| 325 | "Use run_in_background: true when launching multiple tasks in parallel so you can act on each as it completes via task_await (which returns on the first completion by default); a foreground grouped spawn (run_in_background: false) instead blocks until every sibling finishes and returns all reports at once. " + |
| 326 | "Do not call task_await in the same parallel tool-call batch; wait for the returned task metadata first. " + |
| 327 | isolationGuidance + |
| 328 | "Use the bash tool to run shell commands." |
| 329 | ); |
| 330 | } |
| 331 | |
| 332 | const WorkspaceTaskKindSchema = z.enum(["subagent", "workspace"]); |
| 333 | const WorkspaceTaskModeSchema = z.enum(["new", "fork", "existing"]); |
no test coverage detected