From 58ec56234cb6d6d9f18c2e06a3fc6b8864be5bc1 Mon Sep 17 00:00:00 2001 From: Jiang Bohan Date: Wed, 11 Feb 2026 17:10:05 +0800 Subject: [PATCH] feat(subagent): improve system prompts for error reporting and timeout Add error reporting rule to subagent system prompt: subagents must explicitly report tool failures and missing credentials in their final message. Add timeout guidelines to parent system prompt with recommended values by task complexity (10-30 min). Co-Authored-By: Claude Opus 4.6 --- .../core/src/agent/system-prompt/sections.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/core/src/agent/system-prompt/sections.ts b/packages/core/src/agent/system-prompt/sections.ts index f0db6e33..4d2bf1cd 100644 --- a/packages/core/src/agent/system-prompt/sections.ts +++ b/packages/core/src/agent/system-prompt/sections.ts @@ -260,9 +260,19 @@ export function buildConditionalToolSections( lines.push( "## Sub-Agents", "If a task is complex or long-running, spawn a sub-agent. It will do the work and report back when done.", - "You can check on running sub-agents at any time.", + "IMPORTANT: After spawning sub-agents, do NOT immediately check on them with sessions_list. " + + "Results are delivered directly into your context automatically when the sub-agent finishes. " + + "Continue with other tasks or finish your turn and wait for the results to arrive.", + "You may use sessions_list to check on sub-agents only if a long time has passed or the user explicitly asks about their status.", "Sub-agents cannot spawn nested sub-agents.", "", + "### Timeout Guidelines", + "Set timeoutSeconds generously — a sub-agent that times out loses all its work.", + "- Simple tasks (search, read, summarize): 600 (10 min, the default)", + "- Moderate tasks (multi-step research, file downloads + analysis): 900–1200 (15–20 min)", + "- Complex tasks (code generation, PDF creation, multi-file operations): 1200–1800 (20–30 min)", + "When in doubt, use a longer timeout. It is always better to wait longer than to lose completed work.", + "", ); } @@ -364,6 +374,10 @@ export function buildSubagentSection( "## Subagent Rules", "- Stay focused on the assigned task below.", "- Complete the task thoroughly and report your findings.", + "- If you encounter errors (missing API keys, permission denied, tool failures, etc.), " + + "you MUST explicitly report them in your final message. " + + "State exactly what failed and what is needed to fix it — " + + "the parent agent relies on your final message to understand what happened.", "- Do NOT initiate side actions unrelated to the task.", "- Do NOT attempt to communicate with the user directly.", "- Do NOT spawn nested subagents.",