on main help sign in
chore: improve summarize logic
commit2aedcb7fad6f06c747b3f4b80851d1d5b6c11fef authorKujtim Hoxha <kujtimii.h@gmail.com> dateMon 27 Oct 2025, 09:25 (1 year ago) parentec9f94f
1 file changed+9−3
internal/agent/agent.go+9−3
internal/agent/agent.go+9−3
@@ -361,10 +361,16 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
361361 },
362362 StopWhen: []fantasy.StopCondition{
363363 func(_ []fantasy.StepResult) bool {
364− contextWindow := a.largeModel.CatwalkCfg.ContextWindow
364+ cw := int64(a.largeModel.CatwalkCfg.ContextWindow)
365365 tokens := currentSession.CompletionTokens + currentSession.PromptTokens
366− percentage := (float64(tokens) / float64(contextWindow)) * 100
367− if (percentage > 80) && !a.disableAutoSummarize {
366+ remaining := cw - tokens
367+ var threshold int64
368+ if cw > 200_000 {
369+ threshold = 20_000
370+ } else {
371+ threshold = int64(float64(cw) * 0.2)
372+ }
373+ if (remaining <= threshold) && !a.disableAutoSummarize {
368374 shouldSummarize = true
369375 return true
370376 }