-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Description
Summary
When launching a subagent session via the SDK with both agent and model parameters, opencode ignores the model parameter and uses its built-in fallback chain for that agent instead.
Environment
- opencode version: 1.2.27
- Platform: macOS (darwin)
Steps to Reproduce
- Configure a custom provider with models:
// ~/.config/opencode/opencode.json
{
"provider": {
"opencode-go": {
"npm": "@ai-sdk/anthropic",
"options": {
"baseURL": "https://cloud.infini-ai.com/maas/coding/v1",
"apiKey": "{env:GENSTUDIO_API_KEY}"
},
"models": {
"minimax-m2.7": { "name": "MiniMax M2.7" },
"glm-5": { "name": "GLM-5" }
}
}
}
}- Verify the provider and models work correctly:
$ opencode models opencode-go
opencode-go/glm-5
opencode-go/minimax-m2.7
$ opencode run -m opencode-go/minimax-m2.7 "Say: test"
# Works correctly! Uses opencode-go/minimax-m2.7- Launch a subagent via SDK with explicit model parameter:
await client.session.promptAsync({
path: { id: sessionID },
body: {
agent: "explore",
model: { providerID: "opencode-go", modelID: "minimax-m2.7" },
parts: [{ type: "text", text: "Say what model you are using" }]
}
});- Check the database record:
SELECT data FROM message WHERE agent = 'explore' AND role = 'user' ORDER BY time_created DESC LIMIT 1;
-- Result: {"agent":"explore","model":{"providerID":"opencode","modelID":"minimax-m2.5-free"},...}
-- The model is WRONG! It's using opencode/minimax-m2.5-free instead of opencode-go/minimax-m2.7Expected Behavior
When model parameter is explicitly provided, it should be used as-is. The agent's built-in fallback chain should only be used when NO model parameter is provided.
Actual Behavior
The model parameter is ignored when an agent is specified. OpenCode uses the agent's built-in fallback chain, which resolves to opencode/minimax-m2.5-free (a free built-in model).
Evidence
Database records showing the issue:
- Direct model usage (works correctly):
SELECT modelID, providerID FROM message WHERE role = 'assistant' ORDER BY time_created DESC LIMIT 1;
-- Result: modelID = "minimax-m2.7", providerID = "opencode-go" ✓- Subagent with agent name (broken):
SELECT json_extract(data, '$.model') FROM message WHERE agent = 'explore' AND role = 'user' ORDER BY time_created DESC LIMIT 1;
-- Result: {"providerID":"opencode","modelID":"minimax-m2.5-free"} ✗Root Cause
OpenCode has built-in fallback chains for agents like explore, librarian, etc. When processing a session prompt:
- If
agentis specified, OpenCode appears to use the agent's fallback chain - The explicitly provided
modelparameter is overridden
Why This Matters
- Plugin compatibility: Plugins like oh-my-opencode configure custom models for agents, but these are ignored
- User choice: Users cannot override agent models even when explicitly specifying them
- Cost control: Users may want to use their own API keys with specific providers, but fall back to built-in free models instead
Suggested Fix
The priority should be:
- User-provided model (highest priority) - use as-is
- Agent's built-in fallback chain (fallback) - only when no model is provided
- System default (last resort)
Related Issue
Also reported to oh-my-opencode: code-yeongyu/oh-my-openagent#2741
Initially thought it was an oh-my-opencode issue, but database evidence shows the model is already wrong in the user message record, indicating the issue is in opencode's session handling.