fix(opencode): forward parent attachments to subagents - #32302
Conversation
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
@rekram1-node This is a something that is needed in opencode right now. Right now it strips out the path, it's annoying to be working with agents that need the whole path for image reading. Can you take a look at this? |
|
Hi, this issue also affects me on Windows CLI (opencode TUI). I'm using @Vision subagent with attached images and the images never get forwarded. The parent model can't process images and the vision subagent receives text-only context. |
|
This PR's approach matches what I independently arrived at — extract image/file parts from the triggering parent message and forward them into the child subagent prompt. Confirming it's the right fix and adding two notes that may help it land: 1. Source of parts —
|
|
This is solid. Can we please get this merged? |
Issue for this PR
Closes #25553
Type of change
What does this PR do?
This fixes the attachment handoff for
@mentionsubagents in thetaskpath.In the failing
#25553flow, the parent agent could spawn the subagent, butTaskToolonly rebuilt child prompt parts fromparams.prompt, so the image attached to the parent user message never reached the child session.This change forwards file parts from the triggering parent user message into the child prompt, but only when that parent message explicitly targets the same subagent. That keeps the fix scoped to the actual handoff boundary and lets multimodal subagents receive the attached image once they are spawned.
This does not try to solve cases where the parent LLM does not choose to call
taskat all. That routing decision is upstream model behavior, not something this patch can make deterministic.sequenceDiagram participant U as User participant P as Parent session participant B as build model participant T as TaskTool participant V as Child subagent U->>P: text + @vision + image P->>B: parent message B->>T: call task(subagent, prompt) T->>V: child prompt from params.prompt only Note over V: image missingsequenceDiagram participant U as User participant P as Parent session participant B as build model participant T as TaskTool participant V as Child subagent U->>P: text + @vision + image P->>B: parent message B->>T: call task(subagent, prompt) T->>T: collect file parts from the triggering parent user message T->>V: child prompt + forwarded image V-->>P: image analysis resultHow did you verify your code works?
POST /session/:id/messagerequest withtext + agent + filepartsGET /session/:id/messagethat the session stored the@visionmention and the image attachmentagent=visionagent=visionandmode=subagentbun typecheckfrompackages/opencodebun test --timeout 15000 test/tool/task.test.tsfrompackages/opencodeScreenshots / recordings
POST request with

text + agent + fileparts:Stored session message with
@visionand image attachment:Child session creation for the subagent:

Child subagent stream:

Regression test passing:

Checklist