Principle:AIPexStudio AIPex Streaming Event Architecture
| Knowledge Sources | |
|---|---|
| Domains | Event_Driven_Architecture, Real_Time_Streaming |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
An architecture that delivers AI agent execution results as a discriminated-union event stream, enabling real-time UI updates and incremental processing.
Description
Streaming Event Architecture replaces request-response patterns with an async generator that yields a sequence of typed events. Each event represents a discrete state transition in the agent's execution: text deltas, tool call starts/completions, metrics updates, and completion. This enables UIs to render partial results as they arrive, eliminates the need for polling, and allows downstream consumers (plugins, adapters) to react to individual events. The pattern uses a discriminated union type (`AgentEvent`) so consumers can pattern-match on `type` in a type-safe switch statement.
Usage
Use this principle when building AI agent systems that need real-time feedback, progressive rendering, or reactive plugin architectures. It is essential when the agent's execution takes more than a few seconds (multi-turn tool calling) and the user needs visible progress.
Theoretical Basis
The event stream is modeled as an `AsyncGenerator<AgentEvent>`:
AgentEvent =
| session_created
| session_resumed
| content_delta(delta)
| tool_call_start(toolName, params)
| tool_call_complete(toolName, result)
| tool_call_error(toolName, error)
| metrics_update(metrics)
| execution_complete(finalOutput, metrics)
| error(error)
Consumers iterate with `for await (const event of stream)` and dispatch on `event.type`. The stream is lazy—events are produced only as consumed.