September 7, 2026
Most agent runtimes share the same brittle skeleton. Here's what happens when you replace it with an event log.

Most AI agent frameworks today are built around a single, never‑ending loop that repeatedly reads the model’s output, executes a tool, and feeds the result back into the prompt. This while (true) skeleton is simple to understand, but it couples decision‑making, side‑effects, and state management into one monolithic cycle. As agents grow more capable — handling multi‑step reasoning, long‑running tasks, and human‑in‑the‑loop interactions — the loop becomes a bottleneck for reliability, observability, and extensibility.
In a classic loop‑based runtime the agent’s entire history lives in a mutable prompt buffer. Every iteration overwrites or appends to that buffer, making it difficult to answer questions such as “which tool call produced this error?” or “what would happen if we rolled back to step three?”. Debugging requires reproducing the exact sequence of model calls, which is fragile when the model is nondeterministic or when external APIs change. Moreover, the loop forces a synchronous execution model; long‑running operations block the whole agent, and there is no natural place to inject retries, timeouts, or compensation logic.
Replacing the loop with an append‑only event log changes the mental model from “run until done” to “record what happened”. Each significant action — model request, tool invocation, human feedback, error — becomes an immutable event with a timestamp, correlation ID, and payload. The agent’s current state is then a pure function that folds over the log. This approach mirrors event‑sourcing patterns used in distributed systems and gives the runtime a durable, queryable history without any extra instrumentation.
Start by defining a minimal event schema: type Event = ModelRequest | ToolCall | ToolResult | HumanInput | Error. Wrap the existing loop in a function that emits an event for each iteration and stores it in an append‑only store (a file, a database, or an in‑memory log for prototypes). Replace the mutable prompt buffer with a pure reducer that rebuilds the prompt from the log whenever the model is called. Gradually move side‑effects — API calls, file writes — into separate handlers that react to ToolCall events, turning them into asynchronous, retryable workflows. Finally, expose the log via a simple HTTP endpoint so that debugging dashboards, replay scripts, and automated tests can consume it directly.
Further reading: https://dev.to/tomsun28/why-does-every-ai-agent-still-look-like-while-true--258a
You've probably had this exact moment. You ask an AI a math question. It lays out the steps...
Sep 7, 2026