Skip to content

Commit c2ef930

Browse files
authored
add option to allow agent switches to not change model (#3356)
1 parent 3c3d2f5 commit c2ef930

File tree

1 file changed

+27
-39
lines changed
  • packages/tui/internal/app

1 file changed

+27
-39
lines changed

packages/tui/internal/app/app.go

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -253,22 +253,14 @@ func SetClipboard(text string) tea.Cmd {
253253
return tea.Sequence(cmds...)
254254
}
255255

256-
func (a *App) cycleMode(forward bool) (*App, tea.Cmd) {
257-
if forward {
258-
a.AgentIndex++
259-
if a.AgentIndex >= len(a.Agents) {
260-
a.AgentIndex = 0
261-
}
262-
} else {
263-
a.AgentIndex--
264-
if a.AgentIndex < 0 {
265-
a.AgentIndex = len(a.Agents) - 1
266-
}
267-
}
268-
if a.Agent().Mode == "subagent" {
269-
return a.cycleMode(forward)
270-
}
256+
func (a *App) updateModelForNewAgent() {
257+
singleModelEnv := os.Getenv("OPENCODE_AGENTS_SWITCH_SINGLE_MODEL")
258+
isSingleModel := singleModelEnv == "1" || singleModelEnv == "true"
271259

260+
if isSingleModel {
261+
return
262+
}
263+
// Set up model for the new agent
272264
modelID := a.Agent().Model.ModelID
273265
providerID := a.Agent().Model.ProviderID
274266
if modelID == "" {
@@ -292,6 +284,25 @@ func (a *App) cycleMode(forward bool) (*App, tea.Cmd) {
292284
}
293285
}
294286
}
287+
}
288+
289+
func (a *App) cycleMode(forward bool) (*App, tea.Cmd) {
290+
if forward {
291+
a.AgentIndex++
292+
if a.AgentIndex >= len(a.Agents) {
293+
a.AgentIndex = 0
294+
}
295+
} else {
296+
a.AgentIndex--
297+
if a.AgentIndex < 0 {
298+
a.AgentIndex = len(a.Agents) - 1
299+
}
300+
}
301+
if a.Agent().Mode == "subagent" {
302+
return a.cycleMode(forward)
303+
}
304+
305+
a.updateModelForNewAgent()
295306

296307
a.State.Agent = a.Agent().Name
297308
a.State.UpdateAgentUsage(a.Agent().Name)
@@ -380,30 +391,7 @@ func (a *App) SwitchToAgent(agentName string) (*App, tea.Cmd) {
380391
}
381392
}
382393

383-
// Set up model for the new agent
384-
modelID := a.Agent().Model.ModelID
385-
providerID := a.Agent().Model.ProviderID
386-
if modelID == "" {
387-
if model, ok := a.State.AgentModel[a.Agent().Name]; ok {
388-
modelID = model.ModelID
389-
providerID = model.ProviderID
390-
}
391-
}
392-
393-
if modelID != "" {
394-
for _, provider := range a.Providers {
395-
if provider.ID == providerID {
396-
a.Provider = &provider
397-
for _, model := range provider.Models {
398-
if model.ID == modelID {
399-
a.Model = &model
400-
break
401-
}
402-
}
403-
break
404-
}
405-
}
406-
}
394+
a.updateModelForNewAgent()
407395

408396
a.State.Agent = a.Agent().Name
409397
a.State.UpdateAgentUsage(agentName)

0 commit comments

Comments
 (0)