Add agent/context.go with a ContextBuilder that enforces a character budget (soft + hard) over the assembled history, evicting oldest non-system messages first and replacing large tool outputs with truncated summaries. Update agent/session.go to use ContextBuilder in History(), so the loop always sees a bounded context window regardless of how many steps have run. The budget defaults are: - SoftLimit: 24000 chars (~6k tokens at 4 chars/token) - HardLimit: 96000 chars (~24k tokens) - MaxToolOutputChars: 2000 - TailMessages: 6 (always keep last N messages verbatim) All limits are configurable via ContextConfig. |
||
|---|---|---|
| .. | ||
| context.go | ||
| loop.go | ||
| session.go | ||
| state.go | ||