From 2f06f2c3b92494b8c91360db38a86f636d440099 Mon Sep 17 00:00:00 2001 From: mrosnerr Date: Thu, 5 Mar 2026 12:57:39 -0500 Subject: [PATCH 1/2] fix(agents): prevent orchestrator from rushing ahead of background agents Tighten Background Result Collection instructions so the model waits for explore/librarian results instead of duplicating their work and delivering premature answers. - Remove 'Continue working immediately' which models interpreted as 'do ALL work yourself, ignore agents' - Clarify step 2: only do DIFFERENT independent work while waiting - Add explicit step 3: end response when no other work remains - Add 'not for files you already know' to explore section header Fixes #2124, fixes #1967 --- src/agents/dynamic-agent-prompt-builder.ts | 2 +- src/agents/sisyphus.ts | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/agents/dynamic-agent-prompt-builder.ts b/src/agents/dynamic-agent-prompt-builder.ts index 1a65a120c..c08b3c120 100644 --- a/src/agents/dynamic-agent-prompt-builder.ts +++ b/src/agents/dynamic-agent-prompt-builder.ts @@ -116,7 +116,7 @@ export function buildExploreSection(agents: AvailableAgent[]): string { return `### Explore Agent = Contextual Grep -Use it as a **peer tool**, not a fallback. Fire liberally. +Use it as a **peer tool**, not a fallback. Fire liberally for discovery, not for files you already know. **Use Direct Tools when:** ${avoidWhen.map((w) => `- ${w}`).join("\n")} diff --git a/src/agents/sisyphus.ts b/src/agents/sisyphus.ts index 5e6bb7c8e..088c86b2b 100644 --- a/src/agents/sisyphus.ts +++ b/src/agents/sisyphus.ts @@ -225,18 +225,17 @@ task(subagent_type="explore", run_in_background=true, load_skills=[], descriptio // Reference Grep (external) task(subagent_type="librarian", run_in_background=true, load_skills=[], description="Find JWT security docs", prompt="I'm implementing JWT auth and need current security best practices to choose token storage (httpOnly cookies vs localStorage) and set expiration policy. Find: OWASP auth guidelines, recommended token lifetimes, refresh token rotation strategies, common JWT vulnerabilities. Skip 'what is JWT' tutorials — production security guidance only.") task(subagent_type="librarian", run_in_background=true, load_skills=[], description="Find Express auth patterns", prompt="I'm building Express auth middleware and need production-quality patterns to structure my middleware chain. Find how established Express apps (1000+ stars) handle: middleware ordering, token refresh, role-based access control, auth error propagation. Skip basic tutorials — I need battle-tested patterns with proper error handling.") -// Continue working immediately. System notifies on completion — collect with background_output then. - // WRONG: Sequential or blocking result = task(..., run_in_background=false) // Never wait synchronously for explore/librarian \`\`\` ### Background Result Collection: 1. Launch parallel agents \u2192 receive task_ids -2. Continue immediate work -3. System sends \`\` on each task completion — then call \`background_output(task_id="...")\` -4. Need results not yet ready? **End your response.** The notification will trigger your next turn. -5. Cleanup: Cancel disposable tasks individually via \`background_cancel(taskId="...")\` +2. If you have DIFFERENT independent work \u2192 do it now +3. Otherwise \u2192 **END YOUR RESPONSE.** +4. System sends \`\` on completion \u2192 triggers your next turn +5. Collect via \`background_output(task_id="...")\` +6. Cleanup: Cancel disposable tasks individually via \`background_cancel(taskId="...")\` ### Search Stop Conditions From f1f682c3abcde867b60c189dfcd83a721eae1ed9 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 9 Mar 2026 13:10:57 +0900 Subject: [PATCH 2/2] fix(agents): apply background agent result prompt update to all sisyphus variants The prompt update from sisyphus.ts was not applied to the gpt-5-4 and default variant files. This aligns all three sisyphus prompt variants to use the updated background result handling guidance. --- src/agents/sisyphus/default.ts | 9 +++++---- src/agents/sisyphus/gpt-5-4.ts | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/agents/sisyphus/default.ts b/src/agents/sisyphus/default.ts index b776ec00c..043d4adf9 100644 --- a/src/agents/sisyphus/default.ts +++ b/src/agents/sisyphus/default.ts @@ -327,10 +327,11 @@ result = task(..., run_in_background=false) // Never wait synchronously for exp ### Background Result Collection: 1. Launch parallel agents → receive task_ids -2. Continue immediate work -3. System sends \`\` on each task completion — then call \`background_output(task_id="...")\` -4. Need results not yet ready? **End your response.** The notification will trigger your next turn. -5. Cleanup: Cancel disposable tasks individually via \`background_cancel(taskId="...")\` +2. If you have DIFFERENT independent work → do it now +3. Otherwise → **END YOUR RESPONSE.** +4. System sends \`\` on completion → triggers your next turn +5. Collect via \`background_output(task_id="...")\` +6. Cleanup: Cancel disposable tasks individually via \`background_cancel(taskId="...")\` ### Search Stop Conditions diff --git a/src/agents/sisyphus/gpt-5-4.ts b/src/agents/sisyphus/gpt-5-4.ts index 38dca0eb7..05e85a3ac 100644 --- a/src/agents/sisyphus/gpt-5-4.ts +++ b/src/agents/sisyphus/gpt-5-4.ts @@ -246,10 +246,11 @@ Each agent prompt should include: Background result collection: 1. Launch parallel agents → receive task_ids -2. Continue immediate work -3. System sends \`\` on completion → call \`background_output(task_id="...")\` -4. If results aren't ready: end your response. The notification triggers your next turn. -5. Cancel disposable tasks individually via \`background_cancel(taskId="...")\` +2. If you have DIFFERENT independent work → do it now +3. Otherwise → **END YOUR RESPONSE.** +4. System sends \`\` on completion → triggers your next turn +5. Collect via \`background_output(task_id="...")\` +6. Cancel disposable tasks individually via \`background_cancel(taskId="...")\` Stop searching when: you have enough context, same info repeating, 2 iterations with no new data, or direct answer found. `;