picoclaw/pkg/config
xiaoen 9c82b0baa2 refactor(agent): context boundary detection, proactive budget check, and safe compression
Separate context_window from max_tokens — they serve different purposes
(input capacity vs output generation limit). The previous conflation caused
premature summarization or missed compression triggers.

Changes:
- Add context_window field to AgentDefaults config (default: 4x max_tokens)
- Extract boundary-safe truncation helpers (isSafeBoundary, findSafeBoundary)
  into context_budget.go — pure functions with no AgentLoop dependency
- forceCompression: align split to safe boundary so tool-call sequences
  (assistant+ToolCalls → tool results) are never torn apart
- summarizeSession: use findSafeBoundary instead of hardcoded keep-last-4
- estimateTokens: count ToolCalls arguments and ToolCallID metadata,
  not just Content — fixes systematic undercounting in tool-heavy sessions
- Add proactive context budget check before LLM call in runAgentLoop,
  preventing 400 context-length errors instead of reacting to them
- Add estimateToolDefsTokens for tool definition token cost

Closes #556, closes #665
Ref #1439
2026-03-16 14:48:32 +08:00
..
config.go refactor(agent): context boundary detection, proactive budget check, and safe compression 2026-03-16 14:48:32 +08:00
config_test.go add model command to set default model (#1250) 2026-03-13 14:10:11 +08:00
defaults.go feat(agent): steering (#1517) 2026-03-16 00:08:16 +08:00
migration.go feat(provider): add ModelScope as OpenAI-compatible provider (#1486) 2026-03-13 14:02:23 +08:00
migration_test.go feat(provider): add ModelScope as OpenAI-compatible provider (#1486) 2026-03-13 14:02:23 +08:00
model_config_test.go refactor(modernize): apply safe modernize fixes 2026-02-27 16:35:07 +08:00
version.go feat:Modify the location where version is obtained, and insert version information into the context (#1300) 2026-03-10 17:42:05 +08:00
version_test.go feat:Modify the location where version is obtained, and insert version information into the context (#1300) 2026-03-10 17:42:05 +08:00