feat(opencode): add runtime model override for task tool subagents - #35800
pratikranaa wants to merge 1 commit into
Conversation
Add an optional model parameter to the task tool so a primary agent can choose a subagent model at runtime using "provider/model-id" format. Model selection order: explicit task model -> subagent configured model -> parent assistant message model. Explicit overrides are gated behind a new model_override permission that defaults to "ask", so users control which models agents can switch to without a prompt-injection escalation risk. Also adds test coverage for the existing per-agent model feature (frontmatter model field) which previously had no tests, and tests for the new runtime override including format validation, permission checking, and priority over the agent configured model. Closes anomalyco#17595, anomalyco#32730
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate FoundPR #29447: feat(opencode): add task model override Why it's related: This is the exact same feature mentioned in the PR description. PR #29447 has been waiting for review since May and implements the same task tool model override functionality. The current PR (35800) is an independent implementation of the same feature. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
really need this, i don't have to write a bunch of special agent def files if this get merged. |
|
@pratikranaa It's not clear to me skimming the code if the variant can also be overridden? I think definitely all of these should be possible:
For example, the parent model could be "xhigh" and call a "low" subagent or vice versa. If this is possible already, I think the docs/tool should be updated so it's more visible. |
The primary agent can now override which model a specific task dispatch uses (model: "provider/model-id", plus an optional variant), instead of every dispatch always using the subagent's statically- configured model. Ported from upstream anomalyco#6651 (86 reactions/44 comments -- a contested, actively-discussed ask). At least 6 independent implementations exist over ~8 months, all unmerged; PR anomalyco#34947 (open since July, 13 files) is the consolidated, community-endorsed design, but PR anomalyco#35800 (open, 4 files, smaller focused variant) is the actual primary source here: its single ctx.ask permission gate and override-first model resolution (reusing the existing Provider.parseModel) is the core mechanism. The variant parameter and its "always allow" behavior come from anomalyco#34947. anomalyco#34947 defaulted the new permission to "deny"; this fork defaults to "ask" so the feature works without extra config. New model_override permission (default "ask", pre-allowable per pattern, e.g. {"model_override": {"anthropic/*": "allow"}}). Known gaps: the override model isn't validated up front (a nonexistent model fails only when the subagent runs); no typed config key yet (works as a free-form permission key); a resumed task doesn't remember a prior override; no TUI for picking a model per dispatch; only the legacy V1 Task-tool path is covered, not V2 SessionRunner/ AgentV2 dispatch; slug task IDs, resume, timeout, fallback_model (would overlap with this fork's own model-fallback feature), metadata, and cancelRun from anomalyco#34947's fuller scope were left out. New tests in packages/opencode/test/tool/task.test.ts (10 cases) plus a default-permission test in test/agent/agent.test.ts. Verified against this fork's current dev (not just the agent's own stale worktree base): bun typecheck clean; full packages/opencode suite 3613 pass, only the 4 pre-existing, confirmed-unrelated cf-ai-gateway failures. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Issue for this PR
Closes #17595, #32730
Type of change
What does this PR do?
Adds an optional
modelparameter to the task tool so a primary agent can pick a subagent model at runtime usingprovider/model-idformat.Model priority: explicit
modelparam → subagent configuredmodelfrontmatter → parent assistant message model.Explicit overrides are gated behind a new
model_overridepermission (defaults toask) to prevent prompt-injection escalation to expensive models.How did you verify your code works?
test/tool/task.test.ts(7 new) — all passbunx tsc --noEmitclean on changed filesScreenshots / recordings
N/A — backend logic change, no UI.
Checklist
Note: #29447 implements the same feature but has been waiting for review since May. This is an independent implementation.