ENยทESยทDEยทPTยทFR
โŒ˜K

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:

CategoryEvent TypeDescription
SessionSessionStartNew conversation session begins
SessionEndSession terminated
ConversationUserMessageUser sends a message
AssistantResponseAgent sends a response
ToolsToolCallAgent invokes a tool
ToolResultTool execution completes
ThinkingThinkingStartAgent begins reasoning
TasksTaskStartAgent begins a task
TaskEndTask completes (with status)
ErrorsErrorError occurs during processing
Sub-AgentsSubAgentSpawnSub-agent is spawned
SubAgentCompleteSub-agent finishes
ApprovalsApprovalRequestedCommand approval request sent
ApprovalGrantedUser approved a command
ApprovalDeniedUser 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:

  1. Fact extraction — the LLM analyzes event sequences to extract durable facts
  2. Procedure learning — repeated tool-call patterns are captured as procedures
  3. 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.