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
- Chaining dependent MCP tool calls: no rollback, duplicate risk — agentrsdg · 2026-09-11
- DeepMind-led paper makes design docs the source of truth, code disposable — SMART regenerates in 1.5-3h for ~$100 — Roger_M_Taylor · 2026-09-11
- Agent-built classifier labels 192k docs for $0.70 vs $13-26 with frontier LLMs — vanstriendaniel · 2026-09-11
- MathModelAgent gains traction: auto-solves math modeling and writes a submission-ready paper — jihe520 · 2026-09-11
- alphaXiv open-sources OpenResearch to run parallel research agents with any model — alphaXiv · 2026-09-11
- DeskcommCRM: open-source AI sales CRM with native agents and WhatsApp hits 1k stars — melgarafael · 2026-09-11