-
Notifications
You must be signed in to change notification settings - Fork 3k
fix: prevent agents from duplicating delegated subagent work #2400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+445
−10
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /// <reference types="bun-types" /> | ||
|
|
||
| import { describe, it, expect } from "bun:test" | ||
| import { buildAntiDuplicationSection } from "./dynamic-agent-prompt-builder" | ||
|
|
||
| describe("buildAntiDuplicationSection", () => { | ||
| it("#given no arguments #when building anti-duplication section #then returns comprehensive rule section", () => { | ||
| //#given: no special configuration needed | ||
|
|
||
| //#when: building the anti-duplication section | ||
| const result = buildAntiDuplicationSection() | ||
|
|
||
| //#then: should contain the anti-duplication rule with all key concepts | ||
| expect(result).toContain("Anti-Duplication Rule") | ||
| expect(result).toContain("CRITICAL") | ||
| expect(result).toContain("DO NOT perform the same search yourself") | ||
| }) | ||
|
|
||
| it("#given no arguments #when building #then explicitly forbids manual re-search after delegation", () => { | ||
| //#given: no special configuration | ||
|
|
||
| //#when: building the section | ||
| const result = buildAntiDuplicationSection() | ||
|
|
||
| //#then: should explicitly list forbidden behaviors | ||
| expect(result).toContain("FORBIDDEN") | ||
| expect(result).toContain("manually grep/search for the same information") | ||
| expect(result).toContain("Re-doing the research") | ||
| }) | ||
|
|
||
| it("#given no arguments #when building #then allows non-overlapping work", () => { | ||
| //#given: no special configuration | ||
|
|
||
| //#when: building the section | ||
| const result = buildAntiDuplicationSection() | ||
|
|
||
| //#then: should explicitly allow non-overlapping work | ||
| expect(result).toContain("ALLOWED") | ||
| expect(result).toContain("non-overlapping work") | ||
| expect(result).toContain("work that doesn't depend on the delegated research") | ||
| }) | ||
|
|
||
| it("#given no arguments #when building #then includes wait-for-results instructions", () => { | ||
| //#given: no special configuration | ||
|
|
||
| //#when: building the section | ||
| const result = buildAntiDuplicationSection() | ||
|
|
||
| //#then: should include instructions for waiting properly | ||
| expect(result).toContain("Wait for Results Properly") | ||
| expect(result).toContain("End your response") | ||
| expect(result).toContain("Wait for the completion notification") | ||
| expect(result).toContain("background_output") | ||
| }) | ||
|
|
||
| it("#given no arguments #when building #then explains why this matters", () => { | ||
| //#given: no special configuration | ||
|
|
||
| //#when: building the section | ||
| const result = buildAntiDuplicationSection() | ||
|
|
||
| //#then: should explain the purpose | ||
| expect(result).toContain("Why This Matters") | ||
| expect(result).toContain("Wasted tokens") | ||
| expect(result).toContain("Confusion") | ||
| expect(result).toContain("Efficiency") | ||
| }) | ||
|
|
||
| it("#given no arguments #when building #then provides code examples", () => { | ||
| //#given: no special configuration | ||
|
|
||
| //#when: building the section | ||
| const result = buildAntiDuplicationSection() | ||
|
|
||
| //#then: should include examples | ||
| expect(result).toContain("Example") | ||
| expect(result).toContain("WRONG") | ||
| expect(result).toContain("CORRECT") | ||
| expect(result).toContain("task(subagent_type=") | ||
| }) | ||
|
|
||
| it("#given no arguments #when building #then uses proper markdown formatting", () => { | ||
| //#given: no special configuration | ||
|
|
||
| //#when: building the section | ||
| const result = buildAntiDuplicationSection() | ||
|
|
||
| //#then: should be wrapped in Anti_Duplication tag | ||
| expect(result).toContain("<Anti_Duplication>") | ||
| expect(result).toContain("</Anti_Duplication>") | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import { describe, test, expect } from "bun:test" | ||
| import { ATLAS_SYSTEM_PROMPT } from "./default" | ||
| import { ATLAS_GPT_SYSTEM_PROMPT } from "./gpt" | ||
| import { ATLAS_GEMINI_SYSTEM_PROMPT } from "./gemini" | ||
|
|
||
| describe("Atlas prompts auto-continue policy", () => { | ||
| test("default variant should forbid asking user for continuation confirmation", () => { | ||
| // given | ||
| const prompt = ATLAS_SYSTEM_PROMPT | ||
|
|
||
| // when | ||
| const lowerPrompt = prompt.toLowerCase() | ||
|
|
||
| // then | ||
| expect(lowerPrompt).toContain("auto-continue policy") | ||
| expect(lowerPrompt).toContain("never ask the user") | ||
| expect(lowerPrompt).toContain("should i continue") | ||
| expect(lowerPrompt).toContain("proceed to next task") | ||
| expect(lowerPrompt).toContain("approval-style") | ||
| expect(lowerPrompt).toContain("auto-continue immediately") | ||
| }) | ||
|
|
||
| test("gpt variant should forbid asking user for continuation confirmation", () => { | ||
| // given | ||
| const prompt = ATLAS_GPT_SYSTEM_PROMPT | ||
|
|
||
| // when | ||
| const lowerPrompt = prompt.toLowerCase() | ||
|
|
||
| // then | ||
| expect(lowerPrompt).toContain("auto-continue policy") | ||
| expect(lowerPrompt).toContain("never ask the user") | ||
| expect(lowerPrompt).toContain("should i continue") | ||
| expect(lowerPrompt).toContain("proceed to next task") | ||
| expect(lowerPrompt).toContain("approval-style") | ||
| expect(lowerPrompt).toContain("auto-continue immediately") | ||
| }) | ||
|
|
||
| test("gemini variant should forbid asking user for continuation confirmation", () => { | ||
| // given | ||
| const prompt = ATLAS_GEMINI_SYSTEM_PROMPT | ||
|
|
||
| // when | ||
| const lowerPrompt = prompt.toLowerCase() | ||
|
|
||
| // then | ||
| expect(lowerPrompt).toContain("auto-continue policy") | ||
| expect(lowerPrompt).toContain("never ask the user") | ||
| expect(lowerPrompt).toContain("should i continue") | ||
| expect(lowerPrompt).toContain("proceed to next task") | ||
| expect(lowerPrompt).toContain("approval-style") | ||
| expect(lowerPrompt).toContain("auto-continue immediately") | ||
| }) | ||
|
|
||
| test("all variants should require immediate continuation after verification passes", () => { | ||
| // given | ||
| const prompts = [ATLAS_SYSTEM_PROMPT, ATLAS_GPT_SYSTEM_PROMPT, ATLAS_GEMINI_SYSTEM_PROMPT] | ||
|
|
||
| // when / then | ||
| for (const prompt of prompts) { | ||
| const lowerPrompt = prompt.toLowerCase() | ||
| expect(lowerPrompt).toMatch(/auto-continue immediately after verification/) | ||
| expect(lowerPrompt).toMatch(/immediately delegate next task/) | ||
| } | ||
| }) | ||
|
|
||
| test("all variants should define when user interaction is actually needed", () => { | ||
| // given | ||
| const prompts = [ATLAS_SYSTEM_PROMPT, ATLAS_GPT_SYSTEM_PROMPT, ATLAS_GEMINI_SYSTEM_PROMPT] | ||
|
|
||
| // when / then | ||
| for (const prompt of prompts) { | ||
| const lowerPrompt = prompt.toLowerCase() | ||
| expect(lowerPrompt).toMatch(/only pause.*truly blocked/) | ||
| expect(lowerPrompt).toMatch(/plan needs clarification|blocked by external/) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| describe("Atlas prompts plan path consistency", () => { | ||
| test("default variant should use .sisyphus/plans/{plan-name}.md path", () => { | ||
| // given | ||
| const prompt = ATLAS_SYSTEM_PROMPT | ||
|
|
||
| // when / then | ||
| expect(prompt).toContain(".sisyphus/plans/{plan-name}.md") | ||
| expect(prompt).not.toContain(".sisyphus/tasks/{plan-name}.yaml") | ||
| expect(prompt).not.toContain(".sisyphus/tasks/") | ||
| }) | ||
|
|
||
| test("gpt variant should use .sisyphus/plans/{plan-name}.md path", () => { | ||
| // given | ||
| const prompt = ATLAS_GPT_SYSTEM_PROMPT | ||
|
|
||
| // when / then | ||
| expect(prompt).toContain(".sisyphus/plans/{plan-name}.md") | ||
| expect(prompt).not.toContain(".sisyphus/tasks/") | ||
| }) | ||
|
|
||
| test("gemini variant should use .sisyphus/plans/{plan-name}.md path", () => { | ||
| // given | ||
| const prompt = ATLAS_GEMINI_SYSTEM_PROMPT | ||
|
|
||
| // when / then | ||
| expect(prompt).toContain(".sisyphus/plans/{plan-name}.md") | ||
| expect(prompt).not.toContain(".sisyphus/tasks/") | ||
| }) | ||
|
|
||
| test("all variants should read plan file after verification", () => { | ||
| // given | ||
| const prompts = [ATLAS_SYSTEM_PROMPT, ATLAS_GPT_SYSTEM_PROMPT, ATLAS_GEMINI_SYSTEM_PROMPT] | ||
|
|
||
| // when / then | ||
| for (const prompt of prompts) { | ||
| expect(prompt).toMatch(/read[\s\S]*?\.sisyphus\/plans\//) | ||
| } | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Custom agent: Opencode Compatibility
To maintain compatibility with Opencode's native plan tooling and permissions, plans should be stored in
.opencode/plans/rather than.sisyphus/plans/. Opencode explicitly whitelists.opencode/plans/*.mdfor plan-related operations.Prompt for AI agents