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:
I 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.
Most agent loops look like this:
while True:
response = llm.call(messages)
result = tool.execute(response.tool_call)
messages.append(result)
When 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.
Unstuck's waiter treats rate limits as expected, not exceptional:
from src.waiter import PoliteWaiter
waiter = PoliteWaiter(max_retries=5, base_delay=2.0)
for attempt in waiter.retry():
try:
response = llm.call(messages)
break
except RateLimitError as e:
waiter.sleep(e.retry_after or waiter.next_delay())
Key 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.
Agent context windows are finite. Every tool result, every model response, every scraped page gets appended to messages. Eventually you overflow.
The common fix — truncating the oldest messages — throws away the system prompt and the user's original request, which are exactly what you need most.
Unstuck condenses old work instead:
from src.memory import SmartMemory
memory = SmartMemory(max_messages=12, summary_every=6)
The 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.
This 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.
Unstuck halts on repetition:
from src.loop_alarm import LoopAlarm
alarm = LoopAlarm(max_repeats=3)
while True:
action = agent.decide()
if alarm.seen(action):
alarm.halt("Same action repeated 3 times. Waiting for human.")
break
result = tool.execute(action)
alarm.record(action, result)
Three identical actions and the agent stops, hands control back, and asks. No infinite spins, no surprise bills.
Agents write code. Agents break code. Without checkpoints, a bad edit is permanent.
Unstuck checkpoints before every mutation:
from src.undo import CheckpointManager
checkpoints = CheckpointManager()
before = file.read()
checkpoints.save("edit-1", before)
try:
file.write(agent_edit(before))
except Exception:
file.write(checkpoints.restore("edit-1"))
raise
One click restores the last good state. No git knowledge required, no manual git checkout.
Unstuck is stdlib-only — no keys, no internet, no npm install:
python -m venv .venv
.venv\Scripts\activate
python examples/quickstart.py
Copy src/ into your project:
from src.waiter import PoliteWaiter
from src.memory import SmartMemory
from src.loop_alarm import LoopAlarm
from src.undo import CheckpointManager
That's the whole integration. Four classes, under 300 lines total.
The 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.
But 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.