From 71a7f70097a3752a782877a793b916dcc281cbee Mon Sep 17 00:00:00 2001 From: lxowalle Date: Mon, 9 Mar 2026 11:06:05 +0800 Subject: [PATCH] * Add incremental delay and modify the context truncation logic --- pkg/agent/loop.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 3c03dd957..edd896751 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -1463,7 +1463,7 @@ func (al *AgentLoop) retryLLMCall( return resp, nil } if attempt < maxRetries-1 { - time.Sleep(100 * time.Millisecond) + time.Sleep(time.Duration(attempt+1) * 100 * time.Millisecond) } } @@ -1478,10 +1478,11 @@ func (al *AgentLoop) summarizeBatch( existingSummary string, ) (string, error) { const ( - llmMaxRetries = 3 - llmMaxTokens = 1024 - llmTemperature = 0.3 - fallbackMaxContentLength = 200 + llmMaxRetries = 3 + llmMaxTokens = 1024 + llmTemperature = 0.3 + fallbackMinContentLength = 200 + fallbackMaxContentPercent = 10 ) var sb strings.Builder @@ -1512,8 +1513,23 @@ func (al *AgentLoop) summarizeBatch( } content := strings.TrimSpace(m.Content) runes := []rune(content) - if len(runes) > fallbackMaxContentLength { - content = string(runes[:fallbackMaxContentLength]) + "..." + if len(runes) == 0 { + fallback.WriteString(fmt.Sprintf("%s: ", m.Role)) + continue + } + + keepLength := len(runes) * fallbackMaxContentPercent / 100 + if keepLength < fallbackMinContentLength { + keepLength = fallbackMinContentLength + } + + if keepLength > len(runes) { + keepLength = len(runes) + } + + content = string(runes[:keepLength]) + if keepLength < len(runes) { + content += "..." } fallback.WriteString(fmt.Sprintf("%s: %s", m.Role, content)) }