Skip to main content
A ready-to-run example is available here!
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.

Key Concepts

Managed API Server

The ready-to-run 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.

Ready-to-run 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
You can run the example code as-is.
The model name should follow the LiteLLM convention: provider/model_name (e.g., anthropic/claude-sonnet-4-5-20250929, openai/gpt-4o). The LLM_API_KEY should be the API key for your chosen provider.
ChatGPT Plus/Pro subscribers: You can use LLM.subscription_login() to authenticate with your ChatGPT account and access Codex models without consuming API credits. See the LLM Subscriptions guide for details.

Next Steps