Skip to main content
The Local Agent Server demonstrates how to run a remote agent server locally and connect to it using RemoteConversation. This pattern is useful for local development, testing, and scenarios where you want to separate the client code from the agent execution environment.

Basic Example

This example shows how to programmatically start a local agent server and interact with it through a RemoteConversation:
examples/02_remote_agent_server/01_convo_with_local_agent_server.py
Running the Example

Key Concepts

Managed API Server

The example includes a ManagedAPIServer context manager that handles starting and stopping the server subprocess:
The server starts with python -m openhands.agent_server and automatically handles health checks to ensure it’s ready before proceeding.

Remote Workspace

When connecting to a remote server, you need to provide a Workspace that connects to that server:
When host is provided, the Workspace returns an instance of RemoteWorkspace (source). The Workspace object communicates with the remote server’s API to execute commands and manage files.

RemoteConversation

When you pass a remote Workspace to Conversation, it automatically becomes a RemoteConversation (source):
RemoteConversation handles communication with the remote agent server over WebSocket for real-time event streaming.

Event Callbacks

Callbacks receive events in real-time as they happen on the remote server:
This enables monitoring agent activity, tracking progress, and implementing custom event handling logic.

Conversation State

The conversation state provides access to all events and status:
This allows you to inspect the conversation history, analyze agent behavior, and build custom monitoring tools.

Next Steps