hebel. today · 3 November 202645 / 68
Technology · AI engineering
Replace agent loops with durable execution runs
Most AI agents fail during long tasks because they rely on fragile, single-process loops that crash when servers time out or connections drop. Instead of keeping state in volatile chat history, transition to durable…
From 4 newsletters · 1 min read · one thing to try
Most AI agents fail during long tasks because they rely on fragile, single-process loops that crash when servers time out or connections drop (Making AI Accessible with Louis-François). Instead of keeping state in volatile chat history, transition to durable execution where every step—a single LLM call or tool invocation—saves its result to external storage (Making AI Accessible with Louis-François). This allows an agent to resume exactly where it stopped after a crash, deployment, or long wait (Elsewhere). Treat step renames like database migrations to avoid re-triggering side effects like emails or payments for paused runs.
“Once an agent is long-running, you sort of stop building a loop and start building a run: something that has to survive failures, pause, and be inspected hours or days after it started.”
Making AI Accessible with Louis-François
Reliability requires moving from open-ended loops to hard constraints defined in code. Implement strict iteration caps, token budgets, and timeouts to prevent agents from getting stuck in repetitive tool calls. When an agent hits these limits, it should save a partial result and stop cleanly rather than guessing. For irreversible actions, enforce idempotency keys so that retries do not duplicate transactions. By offloading state and control to a persistent harness, you ensure that agents remain auditable and predictable even as they scale across complex, interconnected workflows (Decoding AI Magazine).
Try today · 45 min
Implement a hard limit on your agent's execution loop.
Replace your open-ended loop with a counter that forces a clean exit and state save after a set number of steps.
You need
- Existing agent codebase
- Step counter variable
- Token budget check function
- State persistence logic
Steps
- Define a maximum step count variable in your agent configuration.
- Initialize a counter at the start of the agent run.
- Increment the counter after each tool call or LLM interaction.
- Add a conditional check at the beginning of the loop to compare the counter against the maximum.
- If the limit is reached, trigger a function to save the current run state to a database or file.
- Ensure the agent exits cleanly and returns a partial result instead of continuing.