Description
When switching agents via ACP JSON-RPC session/set_mode, the agent's configured model from opencode.json is not applied to the session. The session continues using whatever model was set before the mode switch.
This is the ACP counterpart to #7099, which describes the same problem for the HTTP REST API.
Root Cause
setSessionMode() in packages/opencode/src/acp/agent.ts only sets session.modeId but never updates session.model:
async setSessionMode(params: SetSessionModeRequest): Promise<SetSessionModeResponse | void> {
const session = this.sessionManager.get(params.sessionId)
const availableModes = await this.loadAvailableModes(session.cwd)
if (!availableModes.some((mode) => mode.id === params.modeId)) {
throw new Error(`Agent not found: ${params.modeId}`)
}
this.sessionManager.setMode(params.sessionId, params.modeId)
// session.model is never updated here
}
Additionally, loadAvailableModes() strips the model and variant fields from agent configs, so even if setSessionMode wanted to look up the model, the data isn't available.
Proposed Fix
Three changes in packages/opencode/src/acp/agent.ts:
- Extend
ModeOption type to include model? and variant?
- Pass
model and variant through in loadAvailableModes()
- In
setSessionMode(), after setting the mode, update session.model and session.variant if the selected agent has a configured model
async setSessionMode(params: SetSessionModeRequest): Promise<SetSessionModeResponse | void> {
const session = this.sessionManager.get(params.sessionId)
const availableModes = await this.loadAvailableModes(session.cwd)
- if (!availableModes.some((mode) => mode.id === params.modeId)) {
+ const selectedMode = availableModes.find((mode) => mode.id === params.modeId)
+ if (!selectedMode) {
throw new Error(`Agent not found: ${params.modeId}`)
}
this.sessionManager.setMode(params.sessionId, params.modeId)
+
+ if (selectedMode.model) {
+ this.sessionManager.setModel(session.id, {
+ providerID: ProviderID.make(selectedMode.model.providerID),
+ modelID: ModelID.make(selectedMode.model.modelID),
+ })
+ this.sessionManager.setVariant(session.id, selectedMode.variant)
+ }
}
Steps to Reproduce
- Configure agent-specific models in
opencode.json:
{
"model": "anthropic/claude-sonnet-4-5",
"agent": {
"custom": {
"model": "anthropic/claude-opus-4"
}
}
}
- Connect via ACP client
- Create a session, then call
session/set_mode with modeId: "custom"
- Send a prompt — observes that
claude-sonnet-4-5 is used instead of claude-opus-4
Related
Description
When switching agents via ACP JSON-RPC
session/set_mode, the agent's configured model fromopencode.jsonis not applied to the session. The session continues using whatever model was set before the mode switch.This is the ACP counterpart to #7099, which describes the same problem for the HTTP REST API.
Root Cause
setSessionMode()inpackages/opencode/src/acp/agent.tsonly setssession.modeIdbut never updatessession.model:Additionally,
loadAvailableModes()strips themodelandvariantfields from agent configs, so even ifsetSessionModewanted to look up the model, the data isn't available.Proposed Fix
Three changes in
packages/opencode/src/acp/agent.ts:ModeOptiontype to includemodel?andvariant?modelandvariantthrough inloadAvailableModes()setSessionMode(), after setting the mode, updatesession.modelandsession.variantif the selected agent has a configured modelasync setSessionMode(params: SetSessionModeRequest): Promise<SetSessionModeResponse | void> { const session = this.sessionManager.get(params.sessionId) const availableModes = await this.loadAvailableModes(session.cwd) - if (!availableModes.some((mode) => mode.id === params.modeId)) { + const selectedMode = availableModes.find((mode) => mode.id === params.modeId) + if (!selectedMode) { throw new Error(`Agent not found: ${params.modeId}`) } this.sessionManager.setMode(params.sessionId, params.modeId) + + if (selectedMode.model) { + this.sessionManager.setModel(session.id, { + providerID: ProviderID.make(selectedMode.model.providerID), + modelID: ModelID.make(selectedMode.model.modelID), + }) + this.sessionManager.setVariant(session.id, selectedMode.variant) + } }Steps to Reproduce
opencode.json:{ "model": "anthropic/claude-sonnet-4-5", "agent": { "custom": { "model": "anthropic/claude-opus-4" } } }session/set_modewithmodeId: "custom"claude-sonnet-4-5is used instead ofclaude-opus-4Related