mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix(context): address review - clarify threshold alignment, i18n strings, add test coverage
This commit is contained in:
@@ -63,6 +63,13 @@ func computeContextUsage(agent *AgentInstance, sessionKey string) *bus.ContextUs
|
||||
|
||||
// summarizeAt = soft summarization trigger: matches maybeSummarize's
|
||||
// threshold (contextWindow * SummarizeTokenPercent / 100).
|
||||
//
|
||||
// NOTE: The engine's maybeSummarize compares this threshold against
|
||||
// history-message tokens only (via estimateTokens), while UsedTokens
|
||||
// (shown in /context) includes system prompt, summary, and tool
|
||||
// definitions on top of history tokens. A "Used > SummarizeAt" display
|
||||
// does not necessarily mean summarization will fire — the engine may
|
||||
// still consider the history-token budget to be under threshold.
|
||||
summarizeAt := contextWindow * agent.SummarizeTokenPercent / 100
|
||||
if summarizeAt <= 0 {
|
||||
summarizeAt = compressAt
|
||||
|
||||
@@ -602,10 +602,11 @@ func TestBeginStream_FinalizeIncludesContextUsage(t *testing.T) {
|
||||
t.Fatal("streamer should support FinalizeWithContext")
|
||||
}
|
||||
if err := contextStreamer.FinalizeWithContext(context.Background(), "final", &bus.ContextUsage{
|
||||
UsedTokens: 10,
|
||||
TotalTokens: 100,
|
||||
CompressAtTokens: 80,
|
||||
UsedPercent: 10,
|
||||
UsedTokens: 10,
|
||||
TotalTokens: 100,
|
||||
CompressAtTokens: 80,
|
||||
SummarizeAtTokens: 60,
|
||||
UsedPercent: 10,
|
||||
}); err != nil {
|
||||
t.Fatalf("FinalizeWithContext() error = %v", err)
|
||||
}
|
||||
@@ -627,6 +628,9 @@ func TestBeginStream_FinalizeIncludesContextUsage(t *testing.T) {
|
||||
if got := rawUsage["used_tokens"]; got != float64(10) {
|
||||
t.Fatalf("used_tokens = %#v, want 10", got)
|
||||
}
|
||||
if got := rawUsage["summarize_at_tokens"]; got != float64(60) {
|
||||
t.Fatalf("summarize_at_tokens = %#v, want 60", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateAndAddConnection_RespectsMaxConnectionsConcurrently(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user