Skip to main content

Agent: Stateless Event Processor

The Agent is the core decision-making component in OpenHands SDK. Unlike traditional agents with internal state, OpenHands agents are pure, stateless functions that consume events and produce new events.

Key Concept: Stateless Design

Benefits:
  • Testable: No mocking needed - just pass in state
  • Serializable: Can be sent across network boundaries
  • Distributed: Can run anywhere without hidden state
  • Composable: Sub-agents work naturally

Core Execution Model

The step() Method

Every agent implements a single core method:

Execution Flow

Agent Configuration

Agents are fully defined by immutable configuration:

Default Agent

The SDK provides a production-ready default agent:

Custom Agents

Create custom agents for specialized reasoning:

Agent Delegation (Sub-agents)

Agents can delegate to specialized sub-agents:

Example: Hierarchical Agents

Pause and Resume

Agents naturally support pause/resume via event sourcing:

How Pause/Resume Works

Observability via Callbacks

Monitor agent behavior in real-time:

Testing Agents

Stateless design makes testing trivial:

Agent Lifecycle

Built-in Agent Types

Default Agent

Microagent

Best Practices

✅ Do

  • Keep agents stateless - all state in ConversationState
  • Use immutable configuration - frozen after creation
  • Test with synthetic state - no complex setup needed
  • Implement custom agents for specialized reasoning
  • Use callbacks for observability

❌ Don’t

  • Store state in agent - use ConversationState
  • Mutate configuration - create new agent instead
  • Mix concerns - agent should only decide actions
  • Skip type safety - use Pydantic models

API Reference

Next Steps