Why Does Every AI Agent Still Look Like `while (true) { ... }`?
说明与用途
传统 AI 代理使用简单的 while (true) 循环和可变状态,导致脆弱性和中断、重试、并行调用等问题。Pizza 将状态替换为事件日志,每个操作都记录为事件,实现了重放、分支、多代理协作和统一接口。
问题
Traditional AI agent runtimes rely on a simple while (true) loop with a mutable state object, leading to brittle behavior, difficulty handling interruptions, retries, parallel tool calls, and lack of replayability.
结果
Switching to an event-sourced architecture eliminates brittle state handling, enables session replay, branching, and multi-agent collaboration, and unifies multiple interfaces over a single log.
工作流
- 1. Initialize EventStore table for events.
- 2. On each turn, read the latest events to reconstruct current state via projection.
- 3. Send LLM plan request with current state context.
- 4. Execute tool calls as events (e.g.,
clitool for shell commands). - 5. Append results as new events to the log.
- 6. Repeat until
isDonecondition met or user interrupts. - 7. For branching, create new
thread_idfrom earlier sequence and replay events to that point.
证据
Every message, tool call, result, and file edit becomes one row in an EventStore
The runtime doesn’t hold state in memory. It reads the tail of this log, dispatches the next event to a handler, and appends the result back.
If you want to branch the conversation, you start a new thread_id from an earlier sequence.
- 记录日期: 2026-09-12T03:15:34.684Z