{"slug": "agents-that-don-t-quit-rate-limits-memory-loops-and-broken-files", "title": "Agents that don't quit: rate limits, memory, loops, and broken files", "summary": "A developer released Unstuck, a free, open-source, stdlib-only Python library that addresses four common infrastructure failures in agent loops: rate limits, context-window overflow, repeated-action loops, and unrecoverable file edits. The library provides four classes — PoliteWaiter, SmartMemory, LoopAlarm, and CheckpointManager — totaling under 300 lines, with no API keys, internet access, or package installs required. The developer says the top cause of failed agent runs is infrastructure, not prompting, and cites agents burning through $2 of API credits repeating the same broken command.", "body_md": "I run eleven AI apps. Most of them are agents â€” they read input, call a model, act on the result, repeat. And the #1 reason an agent run dies isn't bad prompts. It's one of four boring infrastructure failures:\n\nI built Unstuck to fix all four. It's stdlib-only Python, free, open-source, with green CI. Here's why each pain exists, and how to handle it without a framework.\n\nMost agent loops look like this:\n\n```\nwhile True:\n    response = llm.call(messages)\n    result = tool.execute(response.tool_call)\n    messages.append(result)\n```\n\nWhen the model API returns 429, the naive agent crashes. Retry logic is usually an afterthought, bolted on with `time.sleep(60)` â€” which blocks everything, or worse, no retry at all.\n\nUnstuck's waiter treats rate limits as expected, not exceptional:\n\n``` python\nfrom src.waiter import PoliteWaiter\n\nwaiter = PoliteWaiter(max_retries=5, base_delay=2.0)\n\nfor attempt in waiter.retry():\n    try:\n        response = llm.call(messages)\n        break\n    except RateLimitError as e:\n        waiter.sleep(e.retry_after or waiter.next_delay())\n```\n\nKey details: it reads `retry-after` from the response when the API provides it, uses exponential backoff otherwise, and never retries forever. Five attempts, then it hands back control. A rate limit is a slowdown, not a crash.\n\nAgent context windows are finite. Every tool result, every model response, every scraped page gets appended to messages. Eventually you overflow.\n\nThe common fix â€” truncating the oldest messages â€” throws away the system prompt and the user's original request, which are exactly what you need most.\n\nUnstuck condenses old work instead:\n\n``` python\nfrom src.memory import SmartMemory\n\nmemory = SmartMemory(max_messages=12, summary_every=6)\n\n# After every 6 exchanges, the oldest ones are summarized into one message:\n# \"User asked for a sentiment analysis of product reviews. Model identified\n# three negative themes: shipping delays, packaging, and customer support.\n# Tools used: web_scrape (5 calls), llm_classify (3 calls).\"\n```\n\nThe agent keeps working with a short, accurate summary instead of a giant transcript. You lose verbatim history, but you keep the decisions â€” which is what actually matters for the next step.\n\nThis is the most embarrassing failure mode: an agent tries to edit a file, the edit fails, it tries the same edit again, fails again, and repeats until the run is killed. I've watched agents burn through $2 of API credits on the same broken command.\n\nUnstuck halts on repetition:\n\n``` python\nfrom src.loop_alarm import LoopAlarm\n\nalarm = LoopAlarm(max_repeats=3)\n\nwhile True:\n    action = agent.decide()\n    if alarm.seen(action):\n        alarm.halt(\"Same action repeated 3 times. Waiting for human.\")\n        break\n    result = tool.execute(action)\n    alarm.record(action, result)\n```\n\nThree identical actions and the agent stops, hands control back, and asks. No infinite spins, no surprise bills.\n\nAgents write code. Agents break code. Without checkpoints, a bad edit is permanent.\n\nUnstuck checkpoints before every mutation:\n\n``` python\nfrom src.undo import CheckpointManager\n\ncheckpoints = CheckpointManager()\n\nbefore = file.read()\ncheckpoints.save(\"edit-1\", before)\n\ntry:\n    file.write(agent_edit(before))\nexcept Exception:\n    file.write(checkpoints.restore(\"edit-1\"))\n    raise\n```\n\nOne click restores the last good state. No git knowledge required, no manual `git checkout`.\n\nUnstuck is stdlib-only â€” no keys, no internet, no npm install:\n\n```\npython -m venv .venv\n.venv\\Scripts\\activate\npython examples/quickstart.py\n```\n\nCopy `src/` into your project:\n\n``` python\nfrom src.waiter import PoliteWaiter\nfrom src.memory import SmartMemory\nfrom src.loop_alarm import LoopAlarm\nfrom src.undo import CheckpointManager\n```\n\nThat's the whole integration. Four classes, under 300 lines total.\n\nThe roadmap: async waiter with a token-bucket queue (so parallel agents share a rate limit), embedding-based loop detection (similar actions, not just identical), and git-native checkpoints. All of these solve the same four pains at a larger scale.\n\nBut the core lesson is already there: agents don't need to be complex to be reliable. They need to handle rate limits politely, summarize memory, halt on loops, and undo bad edits. Everything else is bonus.", "url": "https://wpnews.pro/news/agents-that-don-t-quit-rate-limits-memory-loops-and-broken-files", "canonical_source": "https://dev.to/rudraattripandey/agents-that-dont-quit-rate-limits-memory-loops-and-broken-files-4foc", "published_at": "2026-11-29 09:39:00+00:00", "updated_at": "2026-11-29 09:44:06.925520+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "large-language-models"], "entities": ["Unstuck", "PoliteWaiter", "SmartMemory", "LoopAlarm", "CheckpointManager", "Python"], "also_reported_by": [], "takeaway": "Unstuck's four stdlib-only classes — PoliteWaiter (retry-after plus exponential backoff, capped at five attempts), SmartMemory (summarize the oldest messages every six exchanges), LoopAlarm (halt after three identical actions), and CheckpointManager (snapshot files before each mutation) — give agent", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/agents-that-don-t-quit-rate-limits-memory-loops-and-broken-files", "markdown": "https://wpnews.pro/news/agents-that-don-t-quit-rate-limits-memory-loops-and-broken-files.md", "text": "https://wpnews.pro/news/agents-that-don-t-quit-rate-limits-memory-loops-and-broken-files.txt", "jsonld": "https://wpnews.pro/news/agents-that-don-t-quit-rate-limits-memory-loops-and-broken-files.jsonld"}}