[PR #12567] feat(task): pass variant to subagent so it inherits parent's thinking level #14273

Open
opened 2026-02-16 18:19:05 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12567

State: open
Merged: No


What does this PR do?

When a user sets a thinking variant (e.g. "high") on their main session, subagents spawned via the Task tool don't inherit it — they always run at default thinking. This means if you're using Claude with extended thinking or any model with reasoning variants, your subagents silently drop that setting.

This PR fixes that by reading the parent user message's variant in task.ts and forwarding it to the child session's SessionPrompt.prompt() call. The inheritance only kicks in when the subagent doesn't already have its own variant configured (via agent config), so explicit per-agent variants are respected.

Related issues

Issue Title Relevance
#7138 Support default variant configuration per agent Root feature request for per-agent variant control
#10320 Specify sub-agent variant (thinking lvl) from script for token economy Directly requests parent→child variant passthrough
#8123 Can't set effort when configuring a sub-agent User pain point this PR alleviates
#6645 Support for Model Variants in (sub)agents Original feature request for variant support in subagents

Relationship with PR #7156 (agent-level config)

PR #7156 adds a static variant field to agent config so each agent can declare its own default. This PR complements that by handling the dynamic case: when no agent-level variant is configured, the subagent inherits the parent session's variant at spawn time.

Resolution order (with both PRs merged): user input > agent config (#7156) > parent variant (this PR) > model default

These two PRs are independent and merge cleanly; together they fully close the gap described in the issues above.

Changes

  • packages/opencode/src/tool/task.ts — After resolving the subagent, read the parent user message and compute inherited variant. Pass it to SessionPrompt.prompt().
  • packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts — Fix reasoning_opaque handling: the Copilot API can send multiple reasoning_opaque deltas in a single response (e.g. one with reasoning text, another with tool calls). Previously this threw an InvalidResponseDataError; now it accepts the latest value. This fix is required because with thinking variants active, multi-turn Copilot responses hit this edge case.
  • packages/opencode/test/session/prompt-variant.test.ts — Three new tests covering: explicit variant passthrough, parent→child variant inheritance, and no-inherit when agent has own variant.

How it works: SessionPrompt.prompt() already supports a variant parameter that gets stored on the user message and used when building the LLM request. The Task tool just wasn't passing it through. The fix reads the parent message (which task.ts already has access to via msg.info.parentID) and conditionally forwards its variant.

How did you verify your code works?

  1. bun test packages/opencode/test/session/prompt-variant.test.ts — all 5 tests pass (2 existing + 3 new)
  2. Manual testing with GitHub Copilot provider using variant: "high" — confirmed subagents now show extended thinking output where they previously didn't

Closes #10320
Related: #7138, #8123, #6645, #7156

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12567 **State:** open **Merged:** No --- ### What does this PR do? When a user sets a thinking variant (e.g. `"high"`) on their main session, subagents spawned via the Task tool don't inherit it — they always run at default thinking. This means if you're using Claude with extended thinking or any model with reasoning variants, your subagents silently drop that setting. This PR fixes that by reading the parent user message's `variant` in `task.ts` and forwarding it to the child session's `SessionPrompt.prompt()` call. The inheritance only kicks in when the subagent doesn't already have its own `variant` configured (via agent config), so explicit per-agent variants are respected. #### Related issues | Issue | Title | Relevance | |-------|-------|-----------| | #7138 | Support default variant configuration per agent | Root feature request for per-agent variant control | | #10320 | Specify sub-agent variant (thinking lvl) from script for token economy | Directly requests parent→child variant passthrough | | #8123 | Can't set effort when configuring a sub-agent | User pain point this PR alleviates | | #6645 | Support for Model Variants in (sub)agents | Original feature request for variant support in subagents | #### Relationship with PR #7156 (agent-level config) PR #7156 adds a static `variant` field to agent config so each agent can declare its own default. **This PR complements that** by handling the dynamic case: when no agent-level variant is configured, the subagent inherits the parent session's variant at spawn time. Resolution order (with both PRs merged): **user input > agent config (#7156) > parent variant (this PR) > model default** These two PRs are independent and merge cleanly; together they fully close the gap described in the issues above. #### Changes - **`packages/opencode/src/tool/task.ts`** — After resolving the subagent, read the parent user message and compute inherited variant. Pass it to `SessionPrompt.prompt()`. - **`packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts`** — Fix `reasoning_opaque` handling: the Copilot API can send multiple `reasoning_opaque` deltas in a single response (e.g. one with reasoning text, another with tool calls). Previously this threw an `InvalidResponseDataError`; now it accepts the latest value. This fix is required because with thinking variants active, multi-turn Copilot responses hit this edge case. - **`packages/opencode/test/session/prompt-variant.test.ts`** — Three new tests covering: explicit variant passthrough, parent→child variant inheritance, and no-inherit when agent has own variant. **How it works:** `SessionPrompt.prompt()` already supports a `variant` parameter that gets stored on the user message and used when building the LLM request. The Task tool just wasn't passing it through. The fix reads the parent message (which `task.ts` already has access to via `msg.info.parentID`) and conditionally forwards its variant. ### How did you verify your code works? 1. `bun test packages/opencode/test/session/prompt-variant.test.ts` — all 5 tests pass (2 existing + 3 new) 2. Manual testing with GitHub Copilot provider using `variant: "high"` — confirmed subagents now show extended thinking output where they previously didn't Closes #10320 Related: #7138, #8123, #6645, #7156
yindo added the pull-request label 2026-02-16 18:19:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14273