openhands-sdk/openhands/sdk/conversation/
Core Responsibilities
The Conversation system has four primary responsibilities:- Agent Lifecycle Management - Initialize, run, pause, and terminate agents
- State Orchestration - Maintain conversation history, events, and execution status
- Workspace Coordination - Bridge agent operations with execution environments
- Runtime Services - Provide persistence, monitoring, security, and visualization
Architecture
Key Components
Factory Pattern
TheConversation class automatically selects the correct implementation based on workspace type:
Dispatch Logic:
- Local: String paths or
LocalWorkspace→ in-process execution - Remote:
RemoteWorkspace→ agent-server via HTTP/WebSocket
State Management
State updates follow a two-path pattern depending on the type of change: Two Update Patterns:- State-Only Updates - Modify fields without appending events (e.g., status changes, stat increments)
- Event-Based Updates - Append to event log when new messages, actions, or observations occur
- FIFO Lock ensures ordered, atomic updates
- Callbacks fire after successful commit
- Read operations never block writes
Execution Models
The conversation system supports two execution models with identical APIs:Local vs Remote Execution
Key Insight: Same API surface means switching between local and remote requires only changing workspace type—no code changes.
Auxiliary Services
The conversation system provides pluggable services that operate independently on the event stream:
Design Principle: Services read from the event log but never mutate state directly. This enables:
- Services can be enabled/disabled independently
- Easy to add new services without changing core orchestration
- Event stream acts as the integration point
Component Relationships
How Conversation Interacts
Relationship Characteristics:- Conversation → Agent: One-way orchestration, agent reports back via state updates
- Conversation → Workspace: Configuration only, workspace doesn’t know about conversation
- Agent → Conversation: Indirect via state events
See Also
- Agent Architecture - Agent reasoning loop design
- Workspace Architecture - Execution environment design
- Event System - Event types and flow
- Conversation Usage Guide - Practical examples

