Skip to content

Subagents launched via task tool ignore their model: frontmatter and inherit parent agent's model #35126

Closed as not planned

Description

@ichasco

Bug Report

Description

When a primary agent launches a subagent via the task tool, the subagent ignores the model: field defined in its own frontmatter and instead uses the model configured for the parent (primary) agent.

Environment

  • opencode version: latest
  • Provider: custom OpenAI-compatible provider (9router)

Configuration

Global config (~/.config/opencode/opencode.json):

{
  "default_agent": "pm",
  "provider": {
    "9router": {
      "npm": "@ai-sdk/openai-compatible",
      "options": { "baseURL": "http://9router:20128/v1" },
      "models": {
        "pm":        { "name": "pm",        "modalities": { "input": ["text", "image"], "output": ["text"] } },
        "developer": { "name": "developer", "modalities": { "input": ["text", "image"], "output": ["text"] } },
        "designer":  { "name": "designer",  "modalities": { "input": ["text", "image"], "output": ["text"] } },
        "default":   { "name": "default",   "modalities": { "input": ["text", "image"], "output": ["text"] } }
      }
    }
  },
  "agent": {}
}

Primary agent (~/.config/opencode/agents/pm.md):

---
description: Project Manager orchestrator
mode: primary
model: 9router/pm
temperature: 0.2
---

Subagent example (~/.config/opencode/agents/frontend.md):

---
description: Frontend Senior developer
mode: subagent
model: 9router/developer
temperature: 0.3
---

Another subagent (~/.config/opencode/agents/devops.md):

---
description: DevOps Engineer
mode: subagent
model: 9router/default
temperature: 0.2
---

Steps to Reproduce

  1. Configure a primary agent with model: 9router/pm as the default agent.
  2. Configure multiple subagents each with a different model: (e.g. 9router/developer, 9router/default).
  3. Have the primary agent invoke a subagent via the task tool.
  4. Observe the model used by the subagent.

Expected Behavior

Each subagent should use the model specified in its own model: frontmatter field (e.g. 9router/developer for frontend, 9router/default for devops).

Actual Behavior

All subagents use 9router/pm — the model of the primary (parent) agent — regardless of the model: field defined in their own frontmatter.

Additional Notes

  • The subagents are defined as .md files under ~/.config/opencode/agents/ following the documented format.
  • The model: field is correctly set per agent and matches defined provider models.
  • When switching to a subagent manually via @mention, the issue may or may not reproduce (not fully confirmed).
  • The bug only manifests clearly when subagents are invoked programmatically via the task tool from a primary agent.

Activity

  1. github-actions commented on Jul 3, 2026

    @github-actions
    Contributor

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

  2. opencode-agent commented on Jul 9, 2026

    @opencode-agent
    Contributor

    Automated maintainer triage by OpenCode Agent.

    I tried to reproduce this on current dev (b8374b5a7c5, 2026-07-09) and could not reproduce it.

    Exact reproduction I used:

    1. Ran OpenCode from a fresh origin/dev worktree with an isolated HOME/XDG config and a writable SQLite DB.

    2. Registered a fake OpenAI-compatible provider test with two available models:

      • test/test-model — parent/default model
      • test/cheap-model — subagent model
    3. Created the markdown subagent at ~/.config/opencode/agents/test-agent.md:

      ---
      description: Test agent
      mode: subagent
      model: test/cheap-model
      ---
      Return "hello" and nothing else.
    4. Started a parent run on test/test-model and had the model call the task tool with:

      {
        "description": "inspect bug",
        "prompt": "say hello",
        "subagent_type": "test-agent"
      }
    5. Queried the session database afterward:

      SELECT agent, model FROM session ORDER BY time_created DESC LIMIT 5;

    Observed child session row:

    {
      "agent": "test-agent",
      "model": {"id":"cheap-model","providerID":"test","variant":"default"}
    }

    So on current dev, the subagent markdown model: frontmatter is parsed and honored through the task tool; it did not inherit the parent model.

    The most likely cause for reports that still look like this is that the configured model string is not resolving to a model available to that user/provider installation. Please run:

    opencode models
    # or
    opencode models <provider>

    and make sure the agent frontmatter uses the exact provider/model string shown there. This matters especially for custom OpenAI-compatible providers and model aliases.

    Closing as not reproducible on current dev. If this still happens on a current build, please open a fresh issue with:

    • exact opencode --version
    • sanitized provider config
    • opencode models / opencode models <provider> output for the relevant provider
    • the exact ~/.config/opencode/agents/<agent>.md frontmatter
    • the resulting SELECT agent, model FROM session ... row
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions