Event Sourcing
Every agent action is recorded as an immutable event. Events are the single source of truth for what happened during a session.
Event Types
The system tracks 16 event types across 6 categories:
| Category | Event Type | Description |
|---|---|---|
| Session | SessionStart | New conversation session begins |
SessionEnd | Session terminated | |
| Conversation | UserMessage | User sends a message |
AssistantResponse | Agent sends a response | |
| Tools | ToolCall | Agent invokes a tool |
ToolResult | Tool execution completes | |
| Thinking | ThinkingStart | Agent begins reasoning |
| Tasks | TaskStart | Agent begins a task |
TaskEnd | Task completes (with status) | |
| Errors | Error | Error occurs during processing |
| Sub-Agents | SubAgentSpawn | Sub-agent is spawned |
SubAgentComplete | Sub-agent finishes | |
| Approvals | ApprovalRequested | Command approval request sent |
ApprovalGranted | User approved a command | |
ApprovalDenied | User denied a command |
Event Structure
rust
struct Event {
id: i64, // Auto-incrementing ID
session_id: String, // Session identifier
event_type: EventType,// One of the 16 types above
data: JsonValue, // Event-specific payload
created_at: DateTime, // Timestamp
consolidated_at: Option<DateTime>, // When processed
task_id: Option<String>, // Associated goal/task run
tool_name: Option<String>, // For tool events
}Daily Consolidation
A background task runs at 3:00 AM UTC daily and processes unconsolidated events:
- Fact extraction — the LLM analyzes event sequences to extract durable facts
- Procedure learning — repeated tool-call patterns are captured as procedures
- Error solution tracking — errors and their resolutions are paired for future debugging
After processing, events are marked with a consolidated_at timestamp.
Session Context
The event system provides a session summary for LLM context that includes tools used, errors encountered, approvals granted/denied, and sub-agent activity.
Event Pruning
A background task runs at 3:30 AM UTC and removes events older than the retention period (default 30 days).
Immutability
Events are append-only. The
consolidated_at field is the only field ever updated after creation.