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.
Related event: TokenShield fixes CrewAI retry loops with turn-scoped hashing(2 posts)→
More from coding & agent
- Kolab Benchmark Uses Pro Screen Recordings to Show AI Agents Overestimate Collaboration Quality — minnesotanlp · 2026-10-27
- Dev argues Claude burns far more tokens than GPT models for the same coding work — haider1 · 2026-10-27
- Stop building agents that can't change models: stable contracts, external state, real evals — rseroter · 2026-10-27
- Cheap models can cost more in agent harnesses than frontier ones, researcher warns — vasuman · 2026-10-27
- Kanzo: A 5k-Line Rust Kanban Binary With MCP for Claude Code and Codex — allmudi · 2026-10-27
- 'A human approves everything' is a trap: approval fatigue and how to actually design safe agents — Efistoffeles · 2026-10-27