on main help sign in
chore: improve summarize logic
2aedcb7Kujtim Hoxha
internal/agent/agent.go+9−3
@@ -361,10 +361,16 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
361 },
361 },
362 StopWhen: []fantasy.StopCondition{
362 StopWhen: []fantasy.StopCondition{
363 func(_ []fantasy.StepResult) bool {
363 func(_ []fantasy.StepResult) bool {
364− contextWindow := a.largeModel.CatwalkCfg.ContextWindow
364+ cw := int64(a.largeModel.CatwalkCfg.ContextWindow)
365 tokens := currentSession.CompletionTokens + currentSession.PromptTokens
365 tokens := currentSession.CompletionTokens + currentSession.PromptTokens
366− percentage := (float64(tokens) / float64(contextWindow)) * 100
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+ }
367− if (percentage > 80) && !a.disableAutoSummarize {
373+ if (remaining <= threshold) && !a.disableAutoSummarize {
368 shouldSummarize = true
374 shouldSummarize = true
369 return true
375 return true
370 }
376 }