* Add incremental delay and modify the context truncation logic
This commit is contained in:
parent
b09c4f13fe
commit
71a7f70097
1 changed files with 23 additions and 7 deletions
|
|
@ -1463,7 +1463,7 @@ func (al *AgentLoop) retryLLMCall(
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
if attempt < maxRetries-1 {
|
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,
|
existingSummary string,
|
||||||
) (string, error) {
|
) (string, error) {
|
||||||
const (
|
const (
|
||||||
llmMaxRetries = 3
|
llmMaxRetries = 3
|
||||||
llmMaxTokens = 1024
|
llmMaxTokens = 1024
|
||||||
llmTemperature = 0.3
|
llmTemperature = 0.3
|
||||||
fallbackMaxContentLength = 200
|
fallbackMinContentLength = 200
|
||||||
|
fallbackMaxContentPercent = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
|
|
@ -1512,8 +1513,23 @@ func (al *AgentLoop) summarizeBatch(
|
||||||
}
|
}
|
||||||
content := strings.TrimSpace(m.Content)
|
content := strings.TrimSpace(m.Content)
|
||||||
runes := []rune(content)
|
runes := []rune(content)
|
||||||
if len(runes) > fallbackMaxContentLength {
|
if len(runes) == 0 {
|
||||||
content = string(runes[:fallbackMaxContentLength]) + "..."
|
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))
|
fallback.WriteString(fmt.Sprintf("%s: %s", m.Role, content))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue