fix: separate ContextWindow from MaxTokens configuration

- Add ContextWindow field to AgentDefaults config
- ContextWindow now defaults to 128K (most modern models support this)
- Previously ContextWindow was incorrectly set to MaxTokens (output limit)
- This fixes premature context compression for large-context models like GLM-5 (128K context)

Fixes issue where:
- GLM-5 with 128K context was limited to 65K (MaxTokens value)
- Compression threshold was underestimated by 50%
- Forced compression dropped 50% of history without summary
This commit is contained in:
Qee 2026-02-27 12:22:40 +08:00
parent 2c8416e658
commit 8ba784a736
2 changed files with 9 additions and 1 deletions

View file

@ -82,6 +82,13 @@ func NewAgentInstance(
maxTokens = 8192
}
// ContextWindow defaults to 128K if not specified (most modern models support this)
// For models with smaller context, users should configure this explicitly
contextWindow := defaults.ContextWindow
if contextWindow == 0 {
contextWindow = 128000
}
temperature := 0.7
if defaults.Temperature != nil {
temperature = *defaults.Temperature
@ -103,7 +110,7 @@ func NewAgentInstance(
MaxIterations: maxIter,
MaxTokens: maxTokens,
Temperature: temperature,
ContextWindow: maxTokens,
ContextWindow: contextWindow,
Provider: provider,
Sessions: sessionsManager,
ContextBuilder: contextBuilder,

View file

@ -177,6 +177,7 @@ type AgentDefaults struct {
ImageModel string `json:"image_model,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_IMAGE_MODEL"`
ImageModelFallbacks []string `json:"image_model_fallbacks,omitempty"`
MaxTokens int `json:"max_tokens" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOKENS"`
ContextWindow int `json:"context_window" env:"PICOCLAW_AGENTS_DEFAULTS_CONTEXT_WINDOW"`
Temperature *float64 `json:"temperature,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_TEMPERATURE"`
MaxToolIterations int `json:"max_tool_iterations" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOOL_ITERATIONS"`
}