diff --git a/cmd/olliesrv/internal/agent/turn.go b/cmd/olliesrv/internal/agent/turn.go index ae8b160..bcdbadb 100644 --- a/cmd/olliesrv/internal/agent/turn.go +++ b/cmd/olliesrv/internal/agent/turn.go @@ -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 }