Merge PR #1312
This commit is contained in:
commit
38c2e7bbc0
1 changed files with 15 additions and 4 deletions
|
|
@ -1401,11 +1401,15 @@ func (al *AgentLoop) runLLMIteration(
|
||||||
return finalContent, iteration, nil
|
return finalContent, iteration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// selectCandidates returns the model candidates and resolved model name to use
|
// selectCandidates returns the model candidates and resolved model ID to use
|
||||||
// for a conversation turn. When model routing is configured and the incoming
|
// for a conversation turn. When model routing is configured and the incoming
|
||||||
// message scores below the complexity threshold, it returns the light model
|
// message scores below the complexity threshold, it returns the light model
|
||||||
// candidates instead of the primary ones.
|
// candidates instead of the primary ones.
|
||||||
//
|
//
|
||||||
|
// The returned model string is the resolved full model ID (e.g. openrouter/qwen/...)
|
||||||
|
// for API requests, not the model name alias, so that providers (e.g. OpenRouter)
|
||||||
|
// receive the correct format including provider prefix.
|
||||||
|
//
|
||||||
// The returned (candidates, model) pair is used for all LLM calls within one
|
// The returned (candidates, model) pair is used for all LLM calls within one
|
||||||
// turn — tool follow-up iterations use the same tier as the initial call so
|
// turn — tool follow-up iterations use the same tier as the initial call so
|
||||||
// that a multi-step tool chain doesn't switch models mid-way.
|
// that a multi-step tool chain doesn't switch models mid-way.
|
||||||
|
|
@ -1414,8 +1418,15 @@ func (al *AgentLoop) selectCandidates(
|
||||||
userMsg string,
|
userMsg string,
|
||||||
history []providers.Message,
|
history []providers.Message,
|
||||||
) (candidates []providers.FallbackCandidate, model string) {
|
) (candidates []providers.FallbackCandidate, model string) {
|
||||||
|
resolveModel := func(cands []providers.FallbackCandidate, fallbackName string) string {
|
||||||
|
if len(cands) > 0 {
|
||||||
|
return cands[0].Model
|
||||||
|
}
|
||||||
|
return fallbackName
|
||||||
|
}
|
||||||
|
|
||||||
if agent.Router == nil || len(agent.LightCandidates) == 0 {
|
if agent.Router == nil || len(agent.LightCandidates) == 0 {
|
||||||
return agent.Candidates, agent.Model
|
return agent.Candidates, resolveModel(agent.Candidates, agent.Model)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, usedLight, score := agent.Router.SelectModel(userMsg, history, agent.Model)
|
_, usedLight, score := agent.Router.SelectModel(userMsg, history, agent.Model)
|
||||||
|
|
@ -1426,7 +1437,7 @@ func (al *AgentLoop) selectCandidates(
|
||||||
"score": score,
|
"score": score,
|
||||||
"threshold": agent.Router.Threshold(),
|
"threshold": agent.Router.Threshold(),
|
||||||
})
|
})
|
||||||
return agent.Candidates, agent.Model
|
return agent.Candidates, resolveModel(agent.Candidates, agent.Model)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.InfoCF("agent", "Model routing: light model selected",
|
logger.InfoCF("agent", "Model routing: light model selected",
|
||||||
|
|
@ -1436,7 +1447,7 @@ func (al *AgentLoop) selectCandidates(
|
||||||
"score": score,
|
"score": score,
|
||||||
"threshold": agent.Router.Threshold(),
|
"threshold": agent.Router.Threshold(),
|
||||||
})
|
})
|
||||||
return agent.LightCandidates, agent.Router.LightModel()
|
return agent.LightCandidates, resolveModel(agent.LightCandidates, agent.Router.LightModel())
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybeSummarize triggers summarization if the session history exceeds thresholds.
|
// maybeSummarize triggers summarization if the session history exceeds thresholds.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue