• Agents eventually exhaust context windows, causing crashes and loss of progress. • Switching models (GPT‑5 Codex, Claude Sonnet) can improve performance but still hit limits. • Traditional drop‑old‑messages fails; need smart compression that retains essential context. • Keep only goals, file changes, outcomes-discard verbose history for efficiency. • Koog’s singleRunStrategy controls agent loops; can be extended for automatic compression. • Implementing compression in Kotlin preserves context, reduces memory, and prevents crashes.

Article Summaries:

  • JetBrains’ latest post in its “Building AI Agents in Kotlin” series tackles the problem of context‑window exhaustion in long‑running agents. The author explains that agents built with GPT‑5 Codex or Claude Sonnet 4.5 eventually crash when their memory of every file, command output, and user message exceeds the model’s token limit. To address this, the article introduces a new strategy, singleRunStrategyWithHistoryCompression(), which adds a checkpoint after each tool execution. The checkpoint checks the history size and, if it exceeds a threshold, compresses the context by retaining only essential facts. This approach allows agents to complete complex tasks without exceeding token limits, improving reliability and cost efficiency.

Sources: