Events Overview
Events are the runtime language of HPD Agent. They are how local apps, hosted clients, TUIs, bot adapters, middleware, sessions, workflows, and subagents observe what is happening during a run.
The simplest event experience is streaming text. The broader event model lets you build:
- transcripts from text and reasoning events
- tool timelines from tool-call events
- permission prompts from bidirectional interactive events
- workflow timelines from workflow events
- subagent and multi-agent views from metadata and child events
- trace views from trace/span fields
- thread replay from durable thread events
What To Read
Start here:
- Streaming Events: first local subscription.
- Application Composition: how generated event schemas are selected, persisted, and kept AOT-safe.
- Event Streams And Hierarchies: the mental model for flat streams and nested projections.
- Render An Event Stream: practical rendering guidance for UIs and clients.
- Tool And Function Events: render tool calls and emit progress from tool code.
- Bidirectional Events: request/response event flows for permissions, clarification, and host decisions.
- TypeScript Client Events: consume live streams, thread history, custom events, and interactive requests from TypeScript apps.
- Custom Events: define app-specific events, emit them from middleware, and encode them through the selected application composition.
- Serialization And Registration: event envelopes, custom discriminators, and AOT metadata.
- Canonical And Process-Local Events: choose between replayable thread facts and process-local activity.
- Lifecycle, Retry, And Error Events: turn lifecycle, retries, and failure rendering.
- Testing Event-Driven Code: capture and assert event-driven behavior.
- Logging And Telemetry: export agent events and usage into logs and metrics.
Then use focused pages:
- Workflow Events: render workflow progress, nodes, layers, and routes.
- Permissions Middleware: answer bidirectional permission events.
- Hosted Streaming API: read control state and receive committed events over resumable SSE.
- Thread History And Forking: read durable thread event history.
- Events Reference: event families, envelopes, and publication semantics.
Core Rule
HPD sends events linearly. Your app projects them into the shape it needs.
ordered event stream
-> transcript
-> tool timeline
-> permission queue
-> workflow tree
-> subagent view
-> trace/debug logPush Or Pull
Observation has one verb, Subscribe, on the AgentRuntime. Pass a handler and the runtime calls it for each event; omit the handler and you get a bounded inbox you read yourself. A subscription sees the events of every agent the runtime runs:
// push: react in-process (print, log, prompt)
using var text = runtime.Subscribe<TextDeltaEvent>(evt => Console.Write(evt.Text));
// pull: forward at your own pace (SSE, WebSocket, a bot)
await using var events = runtime.Subscribe<AgentEvent>(
new ThreadKey(sessionId, "main"),
AgentEventHierarchy.ThreadAndDescendants);
await foreach (var evt in events)
await socket.SendAsync(evt);Both shapes take the same scope: all of the runtime's own events, one exact thread, or a thread hierarchy. The inbox is subscribed when Subscribe returns, so nothing emitted before your first read is lost. Its policy decides what happens when you fall behind: EventInboxOptions.Deterministic() (the default shape) makes the agent wait, LatestOnly() keeps only the newest event, and LossyTelemetry() drops new events. Always dispose an inbox you stop reading. Disposing either shape stops observation only; it never cancels the run. Process-local struct events use SubscribeStruct<TEvent>(...).
For hierarchy, use the most specific correlation fields available: MessageId for message content, CallId for tools, request ids such as PermissionId for bidirectional flows, workflow node ids for workflows, agent metadata for child-agent labels, and trace/span fields for trace views.
Durable thread-scoped projectable events commit to the canonical journal before publication. Live-only diagnostics, progress, metrics, and high-volume samples use their dedicated runtime surfaces. Choose [DurableEvent] only when the event must participate in replay and thread reconstruction.