Dev.to
7/24/2026

grok-loop-kit: automatic context compaction for long-running Grok 4.5 agents
Original: Stop your Grok 4.5 agents from blowing past the context window
Short summary
grok-loop-kit is an open-source Node and Python library that automatically manages context compaction for xAI's Grok 4.5 agents, calling the compaction endpoint at configurable turn or token thresholds to prevent context window overflow. The library handles xAI's exact compaction item format, integrates with LangGraph via a BaseChatModel adapter, and includes streaming, retries, and state management for durable agents. Adversarial testing confirms information preservation: 5/5 random vault codes were recalled exactly after four compaction cycles.
- •Open-source library automating xAI's context-compaction endpoint for long-running Grok 4.5 agents
- •Provides LangGraph integration via BaseChatModel adapter plus streaming, retries, and durable state management
- •Adversarial testing verifies information retention across multiple compaction cycles
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



