agent: apply config backend/model when switching agents via /agent
This commit is contained in:
parent
8c3b40ffe1
commit
45959cb79d
|
|
@ -207,6 +207,19 @@ func (s *agent) handleCommand(ctx context.Context, input string, handler EventHa
|
|||
}
|
||||
d := s.newDispatcher()
|
||||
env := BuildAgentEnv(cfg, d, s.cwd)
|
||||
if env.Backend != "" {
|
||||
newBe, err := s.newBackend(env.Backend)
|
||||
if err != nil {
|
||||
handler(infoEvent(fmt.Sprintf("error: backend %q: %v", env.Backend, err)))
|
||||
return
|
||||
}
|
||||
if env.Model != "" {
|
||||
newBe.SetModel(env.Model)
|
||||
}
|
||||
s.cfg.Backend = newBe
|
||||
} else if env.Model != "" {
|
||||
s.cfg.Backend.SetModel(env.Model)
|
||||
}
|
||||
s.dispatcher = env.dispatcher
|
||||
s.hooks = env.Hooks
|
||||
s.cfg.preamble = env.preamble
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ type AgentEnv struct {
|
|||
preamble string
|
||||
genParams backend.GenerationParams
|
||||
maxSteps int
|
||||
Backend string // from config; empty means no override
|
||||
Model string // from config; empty means no override
|
||||
Messages []string
|
||||
}
|
||||
|
||||
|
|
@ -136,6 +138,12 @@ func BuildAgentEnv(cfg *config.Config, d tools.Dispatcher, cwd string) AgentEnv
|
|||
}
|
||||
}
|
||||
|
||||
var backendName, modelName string
|
||||
if cfg != nil {
|
||||
backendName = cfg.Backend
|
||||
modelName = cfg.Model
|
||||
}
|
||||
|
||||
return AgentEnv{
|
||||
dispatcher: d,
|
||||
tools: allTools,
|
||||
|
|
@ -145,6 +153,8 @@ func BuildAgentEnv(cfg *config.Config, d tools.Dispatcher, cwd string) AgentEnv
|
|||
preamble: preamble,
|
||||
genParams: genParams,
|
||||
maxSteps: maxSteps,
|
||||
Backend: backendName,
|
||||
Model: modelName,
|
||||
Messages: messages,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue