I made an event-driven agent with no `while(true)` loop — here's the architecture

Reddit r/AI_Agents Tools

Summary

The article describes Pizza, an open-source event-driven AI agent that uses event sourcing and state machines to create a robust and auditable agent architecture with features like forking conversations and self-optimization.

I've been building Pizza in my free time — a personal, event-driven AI agent. The core bet is that the agent's execution loop should not be a brittle while(true), but a state machine over an immutable event log. What it means in practice: Every action is an event. Messages, tool calls, tool results, and file edits are all written to a local SQLite EventStore. The TUI, the LLM context, and the session tree are just live projections of that log. No while(true) loop. Each turn is driven by an event-handler table, so interrupts, retries, parallel tool calls, and mid-turn failures are first-class instead of special-cased. One CLI tool for the model. Instead of a long JSON tool list, the model gets a single CLI Tool and composes _read, _write, _edit, and shell commands. It ended up more robust in practice. Git-like session tree. Fork from any prior event, rewind, branch, compare, continue — the conversation is an immutable tree. Same runtime everywhere. TUI, JSON-RPC server, desktop app, and one-shot CLI all consume the same SessionFacade event stream. Agents can tell each other across workspaces. One agent can delegate work to another workspace's agent without leaking project context. (Opt-in) Self-optimization skill. It can mine its own event log, reproduce a bug, write a test, and open a PR against tomsun28/pizza. What I learned so far: event sourcing makes debugging and auditing sessions much easier; forking conversations is natural when state is an immutable tree; and giving the model a single CLI tool reduces schema hallucination and broken tool calls. It's open source (MIT), current version 0.2.7. Feedback and questions welcome — especially from anyone else experimenting with event-sourced or log-first agent architectures.
Original Article

Similar Articles