Skip to content

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

Closed as not planned

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

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 22, 2026
  2. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  3. github-actions commented on Jul 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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