Skip to content

Conversation

@opencode-agent
Copy link
Contributor

Perfect! I've successfully fixed the TUI agent switching issue. Here's a summary of what I implemented:

Fix Summary

Problem: When switching between agents in the TUI, the model selection didn't respect each agent's configured default model. The model would either stick to the previous agent's model or require manual changes.

Root Cause: The automatic model update effect was outside the model function where modelStore wasn't accessible, and it always tried to update to the agent's configured model, overriding user manual selections.

Solution:

  1. Moved the logic inside the model function where modelStore is accessible
  2. Added agent switch detection by tracking the previous agent name
  3. Made the update conditional - only update to the agent's configured model when:
    • The agent actually switches (not just re-renders)
    • The agent has a configured model
    • The user hasn't manually set a model for this agent
  4. Preserved the priority order for model selection:
    • User's manual selection for the agent (highest priority)
    • Agent's configured default model
    • Global fallback model

Key Changes in packages/opencode/src/cli/cmd/tui/context/local.tsx:156-178:

  • Added previousAgentName tracking to detect actual agent switches
  • Only update model when previousAgentName !== agentName
  • Only update if agent has configured model AND no user manual selection exists
  • Moved the effect inside the model function where modelStore is accessible

This fix ensures that:

  • ✅ Agents with configured models automatically switch to their configured model when selected
  • ✅ User manual model selections are preserved and respected
  • ✅ Built-in agents without configured models fall back to global defaults
  • ✅ The model selection "sticks" properly when switching between agents

The fix addresses the exact issue described in #4344 where switching between Builder mode and Plan mode didn't respect each agent's configured model.

Closes #4344

New%20session%20-%202025-11-19T23%3A19%3A47.294Z
opencode session  |  github run

- Move automatic model update logic inside model function where modelStore is accessible
- Only update to agent's configured model when switching agents if user hasn't manually set a model for that agent
- Track previous agent name to detect agent switches properly
- Preserve user manual model selections while respecting agent configurations

Fixes issue where changing agents in TUI didn't respect the model each agent has defined for it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Selected model for agent in TUI doesn't stick between Agent Alternation

2 participants