Skip to content

Refactor ManagedAPIServer in examples into a shared utility #3089

@xingyaoww

Description

@xingyaoww

Summary

The ManagedAPIServer context manager class is duplicated across multiple example files in examples/02_remote_agent_server/:

  • 01_convo_with_local_agent_server.py
  • 11_conversation_fork.py
  • 12_settings_and_secrets_api.py
  • 13_workspace_get_llm.py

Each file contains its own copy of the class, which is a context manager that launches a subprocess-managed OpenHands API server with a randomly generated session API key for secure access.

Proposed Change

Extract ManagedAPIServer into a shared utility module (e.g., examples/02_remote_agent_server/_utils.py or similar) and import it from each example. This would:

  1. Reduce duplication — single source of truth for the managed server logic
  2. Make maintenance easier — bug fixes or enhancements apply everywhere at once
  3. Keep examples focused — example scripts can focus on demonstrating the SDK feature rather than boilerplate server management

Notes

  • The implementations vary slightly across examples (e.g., different health check logic, environment setup), so the shared version should be flexible enough to accommodate those differences.
  • Care should be taken to keep examples self-explanatory — the shared util should be well-documented so readers can still understand what's happening.

This issue was created by an AI agent (OpenHands) on behalf of @xingyaoww, based on this PR comment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestproposalproposal for discussion

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions