openhands-sdk/openhands/sdk/event/
Core Responsibilities
The Event System has four primary responsibilities:- Type Safety - Enforce event schemas through Pydantic models
- LLM Integration - Convert events to/from LLM message formats
- Append-Only Log - Maintain immutable event history
- Service Integration - Enable observers to react to event streams
Architecture
Key Components
| Component | Purpose | Design |
|---|---|---|
Event | Base event class | Immutable Pydantic model with ID, timestamp, source |
LLMConvertibleEvent | LLM-compatible events | Abstract class with to_llm_message() method |
MessageEvent | Text messages | User or assistant conversational messages with skills |
ActionEvent | Tool calls | Agent tool invocations with thought, reasoning, security risk |
ObservationBaseEvent | Tool response base | Base for all tool call responses |
ObservationEvent | Tool results | Successful tool execution outcomes |
UserRejectObservation | User rejection | User rejected action in confirmation mode |
AgentErrorEvent | Agent errors | Errors from agent/scaffold (not model output) |
SystemPromptEvent | System context | System prompt with tool schemas |
CondensationSummaryEvent | Condenser summary | LLM-convertible summary of forgotten events |
ConversationStateUpdateEvent | State updates | Key-value conversation state changes |
Condensation | Condensation result | Events being forgotten with optional summary |
CondensationRequest | Request compression | Trigger for conversation history compression |
PauseEvent | User pause | User requested pause of agent execution |
Event Types
LLM-Convertible Events
Events that participate in agent reasoning and can be converted to LLM messages:| Event Type | Source | Content | LLM Role |
|---|---|---|---|
| MessageEvent (user) | user | Text, images | user |
| MessageEvent (agent) | agent | Text reasoning, skills | assistant |
| ActionEvent | agent | Tool call with thought, reasoning, security risk | assistant with tool_calls |
| ObservationEvent | environment | Tool execution result | tool |
| UserRejectObservation | environment | Rejection reason | tool |
| AgentErrorEvent | agent | Error details | tool |
| SystemPromptEvent | agent | System prompt with tool schemas | system |
| CondensationSummaryEvent | environment | Summary of forgotten events | user |
ActionEvents share the same llm_response_id (parallel function calling):
- Group all ActionEvents by
llm_response_id - Combine into single Message with multiple
tool_calls - Only first event’s
thought,reasoning_content, andthinking_blocksare included - All subsequent events in the batch have empty thought fields
Internal Events
Events for metadata, control flow, and user actions (not sent to LLM):| Event Type | Source | Purpose | Key Fields |
|---|---|---|---|
| ConversationStateUpdateEvent | environment | State synchronization | key (field name), value (serialized data) |
| CondensationRequest | environment | Trigger history compression | Signal to condenser when context window exceeded |
| Condensation | environment | Compression result | forgotten_event_ids, summary, summary_offset |
| PauseEvent | user | User pause action | Indicates agent execution was paused by user |
- user: Event originated from user input
- agent: Event generated by agent logic
- environment: Event from system/framework/tools
Component Relationships
How Events Integrate
Relationship Characteristics:- Agent → Events: Reads history for context, writes actions/messages
- Conversation → Events: Owns and persists event log
- Tools → Events: Create ObservationEvents after execution
- Services → Events: Read-only observers for monitoring, visualization
See Also
- Agent Architecture - How agents read and write events
- Conversation Architecture - Event log management
- Tool System - ActionEvent and ObservationEvent generation
- Condenser - Event history compression

