pub enum ChatEvent {
SessionStarted {
meta: EventMeta,
session_id: String,
model: String,
},
SessionCompleted {
meta: EventMeta,
session_id: String,
status: SessionStatus,
},
RoundStarted {
meta: EventMeta,
round_id: String,
session_id: String,
model: String,
},
RoundCompleted {
meta: EventMeta,
round_id: String,
session_id: String,
status: RoundStatus,
usage: TokenUsage,
latency_ms: u64,
error: Option<String>,
},
ToolCalled {
meta: EventMeta,
tool_call_id: String,
round_id: String,
session_id: String,
tool_name: String,
latency_ms: u64,
success: bool,
},
MessageCountUpdated {
meta: EventMeta,
session_id: String,
message_count: u32,
},
}Expand description
Events emitted by the agent loop during chat sessions.
These events track the complete lifecycle of chat interactions within the agent, from session initialization to completion, including all intermediate operations like rounds and tool calls.
§Event Lifecycle
A typical chat session produces events in this order:
SessionStarted- When a new conversation beginsRoundStarted- When the agent begins processing a messageToolCalled(multiple) - For each tool invocation during the roundRoundCompleted- When the agent finishes processing the messageMessageCountUpdated- When the message count changesSessionCompleted- When the conversation ends
§Usage
These events are primarily used for:
- Performance monitoring (latency tracking)
- Resource usage analysis (token consumption)
- Behavior analytics (tool usage patterns)
- Error tracking and debugging
Variants§
SessionStarted
Emitted when a new chat session is initialized.
This marks the beginning of a conversation between the user and agent.
Fields
SessionCompleted
Emitted when a chat session completes or terminates.
This marks the end of a conversation, whether successful or due to an error.
Fields
status: SessionStatusFinal status of the session (completed, failed, or cancelled)
RoundStarted
Emitted when the agent starts processing a new message round.
A round represents a single request-response cycle within a session. Each user message typically triggers one round.
Fields
RoundCompleted
Emitted when the agent completes processing a message round.
Contains comprehensive metrics about the round including token usage, latency, and any errors that occurred.
Fields
status: RoundStatusFinal status of the round (success or failed)
usage: TokenUsageToken consumption during this round
ToolCalled
Emitted when the agent invokes a tool during a round.
Tracks tool execution for understanding agent behavior and measuring tool performance.
Fields
MessageCountUpdated
Emitted when the message count for a session is updated.
This tracks the total number of messages exchanged in the session, including both user and assistant messages.