opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Parent LLM ignores subagent isolation when using `@agent` references

Open joshuadavidthomas opened this issue 1 month ago • 5 comments

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

joshuadavidthomas avatar Dec 14 '25 01:12 joshuadavidthomas

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] avatar Dec 14 '25 01:12 github-actions[bot]

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 avatar Dec 14 '25 01:12 joshuadavidthomas

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 avatar Dec 14 '25 02:12 rekram1-node

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 avatar Dec 14 '25 02:12 joshuadavidthomas

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 avatar Dec 14 '25 03:12 rekram1-node

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 avatar Dec 14 '25 20:12 joshuadavidthomas