Use compaction model context limit

This commit is contained in:
Ollie Agent 2026-08-15 14:13:44 +02:00
parent 8553bc7283
commit 9330632402
1 changed files with 12 additions and 2 deletions

View File

@ -320,9 +320,19 @@ func (ag *Agent) executeTurn(ctx context.Context, input string) string {
return ""
}
// autoCompactLimit returns the token threshold for auto-compaction (75%).
// autoCompactLimit returns the token threshold for auto-compaction (75% of
// the compaction model's context window). Compaction may use a different model
// from the active turn model, so querying the active model here can overestimate
// the request limit.
func (ag *Agent) autoCompactLimit(ctx context.Context) int {
ctxLen := ag.runtime.Backend.ContextLength(ctx)
b := ag.runtime.Backend
compactModel := resolveCompactionModel(ag.runtime.CompactionModel, b)
origModel := b.Model()
if compactModel != "" && compactModel != origModel {
b.SetModel(compactModel)
defer b.SetModel(origModel)
}
ctxLen := b.ContextLength(ctx)
if ctxLen <= 0 {
ctxLen = defaultContextLength
}