Parent LLM ignores subagent isolation when using @agent references #3530

Closed
opened 2026-02-16 17:40:32 -05:00 by yindo · 6 comments
Owner

Originally created by @joshuadavidthomas on GitHub (Dec 13, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

When using @agent references (e.g., @oracle) multiple times in a session, the parent LLM sends prompts assuming the subagent remembers previous calls - "continue your analysis", "refine what you said earlier". Each @agent triggers the Task tool, which creates an isolated session. The parent LLM doesn't internalize this.

task.txt:21 says "Each agent invocation is stateless..." but this doesn't register. I've seen the parent LLM send follow-up prompts with "Updated Context" and "as previously thought" - phrases that only make sense if the subagent saw the prior request.

Might be minor - the subagent usually figures it out from context, but it sometimes causes confusion.

Suggested fix

Make the instruction more prominent in task.txt:

IMPORTANT: Each @agent call creates a NEW session with NO memory. Do NOT reference "previous analysis" or assume continuity - include ALL context every time.

OpenCode version

1.0.152

Steps to reproduce

  1. Start a session and ask the LLM to analyze something complex
  2. Use @agent to call a subagent
  3. Ask a follow-up that requires calling the same agent again
  4. Observe the parent LLM sending a prompt like "Updated Context" or referencing what the subagent "previously" found

Screenshot and/or share link

https://opncd.ai/share/1igWcU6U

Operating System

Linux

Terminal

Ghostty

Originally created by @joshuadavidthomas on GitHub (Dec 13, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description When using `@agent` references (e.g., @oracle) multiple times in a session, the parent LLM sends prompts assuming the subagent remembers previous calls - "continue your analysis", "refine what you said earlier". Each @agent triggers the Task tool, which creates an isolated session. The parent LLM doesn't internalize this. [task.txt:21](https://github.com/sst/opencode/blob/dev/packages/opencode/src/tool/task.txt#L21) says "Each agent invocation is stateless..." but this doesn't register. I've seen the parent LLM send follow-up prompts with "Updated Context" and "as previously thought" - phrases that only make sense if the subagent saw the prior request. Might be minor - the subagent usually figures it out from context, but it sometimes causes confusion. #### Suggested fix Make the instruction more prominent in `task.txt`: >IMPORTANT: Each @agent call creates a NEW session with NO memory. Do NOT reference "previous analysis" or assume continuity - include ALL context every time. ### OpenCode version 1.0.152 ### Steps to reproduce 1. Start a session and ask the LLM to analyze something complex 2. Use @agent to call a subagent 3. Ask a follow-up that requires calling the same agent again 4. Observe the parent LLM sending a prompt like "Updated Context" or referencing what the subagent "previously" found ### Screenshot and/or share link https://opncd.ai/share/1igWcU6U ### Operating System Linux ### Terminal Ghostty
yindo added the bug label 2026-02-16 17:40:32 -05:00
yindo closed this issue 2026-02-16 17:40:32 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 13, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #2390: Switching to a child session doesn't send subsequent messages to that session but to the parent one - describes the parent LLM continuing to interact with the parent session instead of the subagent
  • #4483: Subagents inappropriately inherit main agent instructions from CLAUDE.md/AGENTS.md - describes context pollution between parent and subagents
  • #4422: Primary agent responds in subagent view; delegated subagent views become inaccessible - related issue with parent/subagent context confusion

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Dec 13, 2025): This issue might be a duplicate of existing issues. Please check: - #2390: Switching to a child session doesn't send subsequent messages to that session but to the parent one - describes the parent LLM continuing to interact with the parent session instead of the subagent - #4483: Subagents inappropriately inherit main agent instructions from CLAUDE.md/AGENTS.md - describes context pollution between parent and subagents - #4422: Primary agent responds in subagent view; delegated subagent views become inaccessible - related issue with parent/subagent context confusion Feel free to ignore if none of these address your specific case.
Author
Owner

@joshuadavidthomas commented on GitHub (Dec 13, 2025):

Not a duplicate. Those issues are about UI routing (#2390, #4422) or config inheritance (#4483). This is about the parent LLM's understanding of subagent isolation - it generates prompts assuming continuity ("Updated Context", "as previously thought") when each subagent call is stateless.

@joshuadavidthomas commented on GitHub (Dec 13, 2025): Not a duplicate. Those issues are about UI routing (#2390, #4422) or config inheritance (#4483). This is about the parent LLM's understanding of subagent isolation - it generates prompts assuming continuity ("Updated Context", "as previously thought") when each subagent call is stateless.
Author
Owner

@rekram1-node commented on GitHub (Dec 13, 2025):

There is this part here so they aren't stateless in this case, perhaps we should reword it:

unless you provide a session_id.

@rekram1-node commented on GitHub (Dec 13, 2025): There is this part here so they aren't stateless in this case, perhaps we should reword it: > unless you provide a session_id.
Author
Owner

@joshuadavidthomas commented on GitHub (Dec 13, 2025):

There is this part here so they aren't stateless in this case, perhaps we should reword it:

unless you provide a session_id.

Yeah, I'm totally oblivious on the "art" of prompting given how fast things are changing these days -- but I would assume some **bold** or UPPERCASE callouts might help? I don't mind opening a PR to get the ball rolling, assuming there's interest in pursuing some sort of tweak to the wording.

@joshuadavidthomas commented on GitHub (Dec 13, 2025): > There is this part here so they aren't stateless in this case, perhaps we should reword it: > > > unless you provide a session_id. Yeah, I'm totally oblivious on the "art" of prompting given how fast things are changing these days -- but I would assume some `**bold**` or `UPPERCASE` callouts might help? I don't mind opening a PR to get the ball rolling, assuming there's interest in pursuing some sort of tweak to the wording.
Author
Owner

@rekram1-node commented on GitHub (Dec 13, 2025):

I guess some helpful info:

what model were u using?

can you share anything about your oracle agent?

can you share the session where this happened?

@rekram1-node commented on GitHub (Dec 13, 2025): I guess some helpful info: what model were u using? can you share anything about your oracle agent? can you share the session where this happened?
Author
Owner

@joshuadavidthomas commented on GitHub (Dec 14, 2025):

Sure! I was using a mixture of Sonnet 4.5 and Opus 4.5 -- though I think primarily Opus was the one calling the subagent.

The oracle agent basically straight lifted from the Amp Code agent of the same name. I found a prompt here and also saw a version of it in the Oh My OpenCode codebase. I used GPT-5.2 as the model for the subagent oracle.

I shared the session in my initial description, but for some reason the page is blank when I try to load it:

Screenshot and/or share link

opncd.ai/share/1igWcU6U

Looking in the console I see logs that show the actual chat.


After having a sleep on it, I think I'm just going to do some tinkering with overriding the task tool with a custom tool and see if anything comes from that. I'll go ahead and close this to reduce the issue noise in the repo. Thanks for taking the time to reply!

@joshuadavidthomas commented on GitHub (Dec 14, 2025): Sure! I was using a mixture of Sonnet 4.5 and Opus 4.5 -- though I think primarily Opus was the one calling the subagent. The oracle agent basically straight lifted from the Amp Code agent of the same name. I found a prompt [here](https://github.com/ben-vargas/ai-amp-cli/blob/main/amp-extractions/agents/oracle-system-prompt.md#full-system-prompt) and also saw a version of it in the [Oh My OpenCode](https://github.com/code-yeongyu/oh-my-opencode/blob/master/src/agents/oracle.ts) codebase. I used GPT-5.2 as the model for the subagent oracle. I shared the session in my initial description, but for some reason the page is blank when I try to load it: > ### Screenshot and/or share link > [opncd.ai/share/1igWcU6U](https://opncd.ai/share/1igWcU6U) Looking in the console I see logs that show the actual chat. --- After having a sleep on it, I think I'm just going to do some tinkering with overriding the task tool with a custom tool and see if anything comes from that. I'll go ahead and close this to reduce the issue noise in the repo. Thanks for taking the time to reply!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3530