Make your own event-sourced agent harness using stream processors — Jonas Templestein, Iterate

By AI Engineer

Share:

Key Concepts

  • Event Sourcing: An architectural pattern where the state of an application is determined by a sequence of events rather than just the current state.
  • Stream Processor: A function that consumes a stream of events, reduces them into a state, and optionally triggers side effects.
  • Agent Harness: A framework for running AI agents that manages inputs, state, and tool execution.
  • Durable Streams: An append-only log of events with offset tracking, allowing for reliable, replayable communication.
  • Polyglot Architecture: A system design that allows components (plugins/processors) to be written in different programming languages (e.g., Rust, TypeScript).
  • Edge Computing: Running agent logic on distributed servers close to the user, accessible via standard HTTP/URL endpoints.

1. Main Topics and Architecture

The workshop introduces a prototype event-sourced agent framework hosted at events.iterate.com. The core philosophy is that an AI agent should be a "server program" that speaks HTTP and treats every interaction—from user input to LLM streaming chunks—as a discrete, logged event.

  • Event Primitive: Every agent interaction is stored as a YAML-formatted event with a type, payload, stream path, and an auto-incrementing offset.
  • Debuggability: Because the entire history is logged, debugging is simplified; developers can inspect the exact sequence of events that led to a specific agent state.
  • Extensibility: The system is designed to be composable. Users can create "processors" that observe specific event types, perform logic, and append new events to the stream.

2. Methodologies and Frameworks

The presenters propose a "reduce and react" methodology for building agents:

  1. Reduce: A synchronous function takes the current state and a new event, returning an updated state. This function must be pure (no side effects).
  2. After-Append Hook: A separate function handles side effects (e.g., making an API call to OpenAI or sending a Slack message) after the event has been successfully persisted.
  3. Circuit Breaking: To prevent infinite loops (a common issue in agentic systems), the framework includes a built-in processor that monitors event frequency. If a stream exceeds a threshold (e.g., 100 events/second), it automatically pauses the stream.

3. Key Arguments and Perspectives

  • Against "Before Hooks": Jonas argues against "before hooks" (intercepting events before they are saved), suggesting they cause performance regressions and break context caching. He advocates for an eventually consistent model where the system remains responsive even if a processor is slightly delayed.
  • Publicly Routable Agents: The speaker posits that every agent should have a URL. This eliminates the need for complex "connector" logic, allowing agents to receive webhooks directly from the internet.
  • Distributed Processing: By decoupling the processor from the storage (the event stream), different parts of an agent can run on different servers, in different languages, or even as dynamic workers.

4. Technical Implementation Details

  • Streaming: The system uses Server-Sent Events (SSE) for real-time communication. By appending ?live=true to a URL, a client can maintain an open connection to receive new events as they occur.
  • Dynamic Workers: A unique feature allows users to append an event containing source code (a stringified reducer). The system then executes this code as a "dynamic worker," effectively allowing the agent to update its own logic at runtime.
  • Idempotency: The system supports idempotency keys to prevent duplicate event processing, which is critical for distributed systems.

5. Notable Quotes

  • "I would like to find out whether this is like dumb or cool." — Jonas, on the experimental nature of the event-sourced agent harness.
  • "I'm kind of like a one-abstraction kind of guy... there should only be one thing which is an event." — Jonas, explaining the simplicity of the architecture.
  • "The moment an agent exists, it should have a URL." — Jonas, on the necessity of internet-connected, routable agents.

6. Synthesis and Conclusion

The workshop presents a vision for a "homebrew" agent infrastructure that prioritizes simplicity and transparency through event sourcing. While the live demonstration faced technical hurdles, the core takeaway is that complex agent behavior can be reduced to a simple stream of events. By treating agents as event-driven state machines, developers can build highly modular, distributed, and debuggable systems that avoid the "black box" nature of current monolithic agent frameworks. The presenters suggest that this architecture is particularly well-suited for future agent-to-agent interactions, where agents might "hire" other specialized agents (processors) to perform tasks, with the entire transaction logged as a series of events.

Chat with this Video

AI-Powered

Load the transcript when you're ready to chat so the initial page stays lighter.

Related Videos

Ready to summarize another video?

Summarize YouTube Video