fix(agent): route fallback candidates to correct provider
Look up each fallback candidate's provider configuration via GetModelConfig and CreateProviderFromConfig instead of reusing the primary agent's provider. This ensures candidates from different providers (e.g. Gemini, Groq) are routed correctly during fallback execution.
This commit is contained in:
parent
92c00a3a81
commit
09fa0a1b88
1 changed files with 15 additions and 1 deletions
|
|
@ -518,7 +518,21 @@ func (al *AgentLoop) runLLMIteration(
|
||||||
if len(agent.Candidates) > 1 && al.fallback != nil {
|
if len(agent.Candidates) > 1 && al.fallback != nil {
|
||||||
fbResult, fbErr := al.fallback.Execute(ctx, agent.Candidates,
|
fbResult, fbErr := al.fallback.Execute(ctx, agent.Candidates,
|
||||||
func(ctx context.Context, provider, model string) (*providers.LLMResponse, error) {
|
func(ctx context.Context, provider, model string) (*providers.LLMResponse, error) {
|
||||||
return agent.Provider.Chat(ctx, messages, providerToolDefs, model, map[string]any{
|
candProvider := agent.Provider
|
||||||
|
candModelID := model
|
||||||
|
|
||||||
|
// Attempt to dynamically route to the correct provider defined in model_list
|
||||||
|
if modelCfg, err := al.cfg.GetModelConfig(model); err == nil {
|
||||||
|
if modelCfg.Workspace == "" {
|
||||||
|
modelCfg.Workspace = al.cfg.WorkspacePath()
|
||||||
|
}
|
||||||
|
if p, mID, err := providers.CreateProviderFromConfig(modelCfg); err == nil {
|
||||||
|
candProvider = p
|
||||||
|
candModelID = mID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return candProvider.Chat(ctx, messages, providerToolDefs, candModelID, map[string]any{
|
||||||
"max_tokens": agent.MaxTokens,
|
"max_tokens": agent.MaxTokens,
|
||||||
"temperature": agent.Temperature,
|
"temperature": agent.Temperature,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue