Open-source TokenShield adds turn-scoped hashes to stop CrewAI retry loops
bulleykebaal · reddit · 2026-07-25
Fixing CrewAI retry loops with turn-scoped hashes
The author refactored their open-source TokenShield FastAPI gateway after feedback from an earlier discussion on catching agents that get stuck retrying.
They tested it on a stubborn local CrewAI script where an agent repeatedly hit a failing database tool maxiter=10. Without the shield, the agent hammered the tool 10 times and prompt usage grew from about 139 tokens on the first turn to 600+ tokens per turn as chat history kept being appended.
What changed
- Per-turn hash window: normalized signatures are tracked only within the current turn, avoiding false positives from earlier retries.
- Tier 1 soft steering: when stagnation is detected, the gateway injects re-planning instructions before stopping the request.
- Tier 2 hard stop: if the agent keeps going, the system returns a clean 429 to stop further token burn.
The takeaway is that turn-scoped hashing can keep circuit breakers precise in CrewAI-style multi-agent graphs while preventing runaway API costs.
More from coding & agent
- A developer refuses to ship yet another generic AI wrapper desktop UI — sull · 2026-07-25
- Statistician Shares AI Workflow: Let AI Handle Narrative, Humans Keep the Math — Excellent_Copy4646 · 2026-07-25
- GitHub screenshot jokes about 41 subagents and 157,288 new lines of code — zeeg · 2026-07-25
- Anthropic makes agent memory file-based, exportable, auditable, and reversible — VraserX · 2026-07-25
- “Typing code was never the job,” argues a post on Claude and $500K engineers — gdechichi · 2026-07-25
- Etched says inference means owning the full stack, not just writing kernels — AccBalanced · 2026-07-25