Skip to content

ACP: session/set_mode does not activate the agent's configured model #18620

@systemfreund

Description

@systemfreund

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:

  1. Extend ModeOption type to include model? and variant?
  2. Pass model and variant through in loadAvailableModes()
  3. 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

  1. Configure agent-specific models in opencode.json:
    {
      "model": "anthropic/claude-sonnet-4-5",
      "agent": {
        "custom": {
          "model": "anthropic/claude-opus-4"
        }
      }
    }
  2. Connect via ACP client
  3. Create a session, then call session/set_mode with modeId: "custom"
  4. Send a prompt — observes that claude-sonnet-4-5 is used instead of claude-opus-4

Related

Metadata

Metadata

Assignees

Labels

acpcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions