Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
b158fda
fix: apply ruff auto-fixes
openhands-agent Sep 10, 2025
bdd8eca
Set up openhands-server as separate Python package
openhands-agent Sep 10, 2025
b190351
Remove unnecessary server dependency group from main pyproject.toml
openhands-agent Sep 10, 2025
62fe4b5
Merge commit '1f5acdb6e0efda929fda0b45750ea91fbddcc54a' into feature/…
xingyaoww Sep 10, 2025
52c2f33
remove integration tests
xingyaoww Sep 10, 2025
68eeabd
feat: Add PyInstaller build system for openhands-server
openhands-agent Sep 11, 2025
aaf15c0
feat: Add PyInstaller build and testing to server.yml workflow
openhands-agent Sep 11, 2025
4d199a5
Fix failing pre-commit checks: correct tool instantiation and formatting
openhands-agent Sep 11, 2025
f5f57d0
Fix failing GitHub Actions: resolve tool instantiation and type errors
openhands-agent Sep 11, 2025
f09e2fc
remove server group
xingyaoww Sep 11, 2025
45a110d
remove nodejs
xingyaoww Sep 11, 2025
147b9ac
remove extra md
xingyaoww Sep 11, 2025
9aa7ce2
Fix GitHub Actions workflow inconsistencies
openhands-agent Sep 11, 2025
44191df
Merge remote changes and fix workflow inconsistencies
openhands-agent Sep 11, 2025
87fbfe1
Remove mocking after 'except ImportError:' and '# type: ignore' comments
openhands-agent Sep 11, 2025
f3bd828
Fix GitHub Actions server workflow pytest command
openhands-agent Sep 11, 2025
970f738
Merge remote changes
openhands-agent Sep 11, 2025
81dc536
Remove all Mock classes and mocking infrastructure from server CLI
openhands-agent Sep 11, 2025
3af3611
Remove mock detection logic from OpenAPI generator
openhands-agent Sep 11, 2025
8e2a8dc
fix imports
xingyaoww Sep 11, 2025
eb16701
set default to port 9000
xingyaoww Sep 11, 2025
4f69e28
Eliminate ConversationStateResponse duplication by using SDK Conversa…
xingyaoww Sep 11, 2025
0c92741
Merge commit '2b9b48f5c062c1dc8dfa6b7d7bd022eda03a24cb' into feature/…
xingyaoww Sep 11, 2025
5147fb1
simplify
xingyaoww Sep 11, 2025
b059ca4
Implement simplified proxy SDK with automatic translator
openhands-agent Sep 11, 2025
d45ebee
Merge commit '22baa101a1b75a9df543d7fd1ed86a3bd2099489' into feature/…
xingyaoww Sep 11, 2025
e4ed4d1
remove md
xingyaoww Sep 11, 2025
adbd0ed
very aggresive refactor based on GPT-5's proposal
xingyaoww Sep 11, 2025
9e0c7e1
revert examples and test for now
xingyaoww Sep 11, 2025
abb72dd
mark progress
xingyaoww Sep 11, 2025
94e60b0
Refactor RPC system to OpenAPI-first REST API
openhands-agent Sep 12, 2025
e763ea7
Rename rpc module to client for clarity
openhands-agent Sep 12, 2025
e56bb5b
Merge commit 'b3ddfb3468c22a37fbb87d96323914d23bacb4ed' into feature/…
xingyaoww Sep 12, 2025
c837bc4
fi xserver call
xingyaoww Sep 12, 2025
35a5220
import tools
xingyaoww Sep 12, 2025
fda5c81
try to simplify
xingyaoww Sep 12, 2025
b85b0d8
simplify the server to an extreme
xingyaoww Sep 12, 2025
5575a78
revert changes
xingyaoww Sep 12, 2025
94b84be
initial implementation of server
xingyaoww Sep 12, 2025
a15a2ff
move tool spec to SDK
xingyaoww Sep 12, 2025
c13e98f
fix microagent typing that breaks openapi.json; remove microagent met…
xingyaoww Sep 12, 2025
22b4995
fix openapi schema generate by separating some LLM fields into Spec
xingyaoww Sep 12, 2025
25a845e
add check for os
xingyaoww Sep 12, 2025
3e1ff5a
bring llm spec back
xingyaoww Sep 12, 2025
8e1a698
add client library
xingyaoww Sep 12, 2025
0ae8ab0
update server to automatically update client
xingyaoww Sep 12, 2025
da285b1
refactor conversation to a router
xingyaoww Sep 12, 2025
a11926f
set build-server with config
xingyaoww Sep 12, 2025
316202a
chore(ci): regenerate OpenAPI client and schema
xingyaoww Sep 12, 2025
3769902
Add auth middleware for server API client calls
xingyaoww Sep 12, 2025
7f7b6fd
Merge commit '316202a6158f3cb79bd363df8454fc57d1987fe4' into feature/…
xingyaoww Sep 12, 2025
2c05b9d
chore(ci): regenerate OpenAPI client and schema
xingyaoww Sep 12, 2025
74a86d5
make convo dependent on the auth module
xingyaoww Sep 12, 2025
eb4c592
update key
xingyaoww Sep 12, 2025
747e532
redirect root to docs
xingyaoww Sep 12, 2025
4ed9fd3
add list convo
xingyaoww Sep 12, 2025
daf7aad
add server endpoints
xingyaoww Sep 12, 2025
30d3846
add tag
xingyaoww Sep 12, 2025
3601e3a
chore(ci): regenerate OpenAPI client and schema
xingyaoww Sep 12, 2025
7a75f49
fix package name
xingyaoww Sep 12, 2025
be7252a
add default test key
xingyaoww Sep 12, 2025
701b014
simplify
xingyaoww Sep 12, 2025
fe26f9a
fix ToolAnnotation name conflict with mcp.ToolAnntation for JSON schema
xingyaoww Sep 13, 2025
32527dd
fix: generate stable, client-friendly JSON schema for discriminated u…
xingyaoww Sep 13, 2025
0d65ff9
update import and base
xingyaoww Sep 13, 2025
f7cc325
stop building generated client
xingyaoww Sep 13, 2025
abac423
remove that from CI
xingyaoww Sep 13, 2025
7df45fb
update openapi
xingyaoww Sep 13, 2025
2374ae7
fix convo start with conversation id
xingyaoww Sep 13, 2025
7ce2671
remove client from library
xingyaoww Sep 13, 2025
3f210a1
fix llm dump
xingyaoww Sep 13, 2025
447cc08
fix circular import
xingyaoww Sep 13, 2025
8233465
Merge branch 'main' into feature/agent-sdk-server-api
xingyaoww Sep 13, 2025
a73e220
fix serialization
xingyaoww Sep 13, 2025
092e6e3
Merge commit '82334654255e24900d053eeee522a9fc15052154' into feature/…
xingyaoww Sep 13, 2025
4434c20
chore(ci): regenerate OpenAPI client and schema
xingyaoww Sep 13, 2025
7d5bbf7
add tests
xingyaoww Sep 13, 2025
62e0c9e
refactor client and get minimal example working
xingyaoww Sep 13, 2025
9fa1430
add comment back
xingyaoww Sep 13, 2025
3dd4369
port over changes from https://github.com/All-Hands-AI/agent-sdk/pull…
xingyaoww Sep 13, 2025
bbcedcf
include du_spec for MCPActionBase
xingyaoww Sep 13, 2025
77c2da9
update du spec
xingyaoww Sep 13, 2025
35b3e57
Merge commit '77c2da96ebc26bea85378c40ec4c08e328dcd1e2' into feature/…
xingyaoww Sep 13, 2025
4a15f4d
chore(ci): regenerate OpenAPI client and schema
xingyaoww Sep 13, 2025
6dacb6b
update server for multi-platform build
xingyaoww Sep 13, 2025
3da597a
Merge branch 'main' into feature/agent-sdk-server-api
xingyaoww Sep 13, 2025
a5c0fc8
chore(ci): regenerate OpenAPI client and schema
xingyaoww Sep 13, 2025
3b52fb4
initial runtime implementation
xingyaoww Sep 13, 2025
74e39da
examples(11): add optional DockerRuntime flow to build+run server bin…
xingyaoww Sep 13, 2025
abd38d6
server: add docker SDK dependency so runtime.impl.docker can be used …
xingyaoww Sep 14, 2025
78b6fa0
examples(11): ensure mcp_config is a dict (not null) in Docker path t…
xingyaoww Sep 14, 2025
d911afd
runtime(docker): add build log streaming via docker API and container…
xingyaoww Sep 14, 2025
71fa399
tweaks
xingyaoww Sep 14, 2025
4c14502
set py version correctly
xingyaoww Sep 14, 2025
c3d26bb
Merge branch 'main' into feature/agent-sdk-server-api
xingyaoww Sep 15, 2025
a14d42a
Merge branch 'main' into feature/agent-sdk-server-api
xingyaoww Sep 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
name: Server Executable & OpenAPI Client

on:
push:
branches: [ main, develop ]
paths:
- 'openhands/server/**'
- 'pyproject.toml'
- '.github/workflows/server.yml'
- 'Makefile'
# Publish artifacts to a GitHub Release whenever you tag (e.g. v0.7.0)
tags:
- 'v*'
pull_request:
branches: [ main, develop ]
paths:
- 'openhands/server/**'
- 'pyproject.toml'
- '.github/workflows/server.yml'
- 'Makefile'

permissions:
contents: write
pull-requests: write

jobs:
build-executable:
name: Build server executable (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
# macos-14 => Apple Silicon; macos-13 => Intel
os: [ubuntu-22.04, windows-2022, macos-14, macos-13]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v6
with:
version: "latest"
python-version: 3.12

- name: Sync deps
run: uv sync --frozen --group dev

- name: Build executable (PyInstaller)
shell: bash
run: |
set -euxo pipefail
uv run pyinstaller openhands/server/openhands-server.spec
ls -lah dist || true

- name: Package executable
shell: bash
run: |
set -euxo pipefail
BIN_NAME="openhands-server"
mkdir -p build_release

# Locate built binary
if [ "${{ runner.os }}" = "Windows" ]; then
SRC="dist/${BIN_NAME}/${BIN_NAME}.exe"
else
SRC="dist/${BIN_NAME}/${BIN_NAME}"
chmod +x "$SRC"
fi

# Normalize OS/ARCH labels used in file names
case "${{ runner.os }}" in
Linux) OS="linux" ;;
macOS) OS="darwin" ;;
Windows) OS="windows" ;;
esac

ARCH="$(uname -m 2>/dev/null || echo $PROCESSOR_ARCHITECTURE)"
case "$ARCH" in
x86_64|amd64|AMD64) ARCH="x64" ;;
arm64|aarch64|ARM64) ARCH="arm64" ;;
*) echo "Unsupported arch: $ARCH"; exit 1 ;;
esac

# Compress per-OS
if [ "${{ runner.os }}" = "Windows" ]; then
PKG="${BIN_NAME}-${OS}-${ARCH}.zip"
powershell -NoProfile -Command "Compress-Archive -Path \"$SRC\" -DestinationPath \"build_release/$PKG\""
else
PKG="${BIN_NAME}-${OS}-${ARCH}.tar.gz"
tar -C "$(dirname "$SRC")" -czf "build_release/$PKG" "$(basename "$SRC")"
fi

echo "PKG_NAME=$PKG" >> $GITHUB_ENV

- name: Upload executable artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.PKG_NAME }}
path: build_release/${{ env.PKG_NAME }}
retention-days: 7

release:
name: Publish GitHub Release assets
needs: build-executable
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: release_assets
merge-multiple: true

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: release_assets/**
# Autogenerate release notes is handy; you can also supply a body file.
generate_release_notes: true


generate-and-commit-openapi-client:
name: Generate OpenAPI client and push to PR branch
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest

steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- name: Install uv
uses: astral-sh/setup-uv@v6
with:
version: "latest"

- name: Install dependencies
run: |
uv sync --frozen --group dev

- name: Run make build-server (exports OpenAPI & generates client)
run: |
make build-server

- name: Auto-commit generated client & schema
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore(ci): regenerate OpenAPI client and schema"
file_pattern: |
openhands/server/openapi.json
branch: ${{ github.head_ref }}
commit_user_name: "github-actions[bot]"
commit_user_email: "41898282+github-actions[bot]@users.noreply.github.com"
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@ help:
@echo " $(GREEN)lint$(RESET) - Lint code with ruff"
@echo " $(GREEN)clean$(RESET) - Clean up cache files"
@echo " $(GREEN)help$(RESET) - Show this help message"

build-server: check-uv-version
@echo "$(YELLOW)Building openapi.json...$(RESET)"
uv run openhands/server/export_openapi.py
@echo "$(GREEN)openapi.json build complete.$(RESET)"

run-server: build-server
@echo "$(YELLOW)Starting OpenHands server...$(RESET)"
uv run -m uvicorn openhands.server.main:app --reload --reload-dir openhands/server --host 0.0.0.0 --port 9000
159 changes: 159 additions & 0 deletions examples/12_api_via_docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import os
import time
import zipfile
import tempfile
from pathlib import Path
import urllib.request

from pydantic import SecretStr

from openhands.sdk import LLM, OpenHandsClient, TextContent, ToolSpec

# Optional: start the server inside Docker using the runtime toolkit
USE_DOCKER = os.getenv("OH_USE_DOCKER_RUNTIME", "1").lower() in {"1", "true", "yes"}
SERVER_URL = os.getenv("OPENHANDS_SERVER_URL", "http://localhost:9000")
MASTER_KEY = os.getenv("MASTER_KEY", "test")

container_runtime = None

if USE_DOCKER:
# Build and run the OpenHands server in Docker as a tiny, two-stage image
from openhands.server.runtime import BuildSpec, DockerRuntime

def make_repo_zip(root: Path, out_path: Path) -> Path:
# Package the openhands/ directory (sdk, tools, server) into a zip
# Excludes .git and virtualenvs for a small context
with zipfile.ZipFile(out_path, "w", compression=zipfile.ZIP_DEFLATED) as zf:
for p in root.rglob("*"):
if "/.git" in str(p) or "/.venv" in str(p):
continue
if p.is_file():
arcname = str(p.relative_to(root.parent))
zf.write(p, arcname)
return out_path

repo_root = Path(__file__).resolve().parents[1]
openhands_dir = repo_root / "openhands"
if not openhands_dir.is_dir():
raise RuntimeError(f"Expected openhands/ at {openhands_dir}")

tmp_zip = Path(tempfile.gettempdir()) / "openhands_bundle.zip"
make_repo_zip(openhands_dir, tmp_zip)

dockerfile_tpl = """
{% set artifact='payload/openhands_bundle.zip' %}
# Stage 1: build a standalone binary via PyInstaller
FROM {{ base_image }} AS builder
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential gcc unzip && rm -rf /var/lib/apt/lists/*
WORKDIR /build
COPY . /ctx
RUN mkdir -p /src && unzip -q /ctx/{{ artifact }} -d /src
# Install local packages first so "openhands-server" deps resolve from local
RUN python -m pip install --no-cache-dir -U pip wheel setuptools \
&& python -m pip install --no-cache-dir pyinstaller>=6.15.0 \
&& python -m pip install --no-cache-dir -e /src/openhands/sdk -e /src/openhands/tools \
&& python -m pip install --no-cache-dir -e /src/openhands/server
WORKDIR /src/openhands/server
# Build the binary. Spec already includes hidden imports/data files.
RUN pyinstaller -y openhands-server.spec && ls -la dist

# Stage 2: runtime image with only the binary
FROM {{ base_image }} AS runtime
WORKDIR /app
COPY --from=builder /src/openhands/server/dist/openhands-server /usr/local/bin/openhands-server
EXPOSE 9000
ENV MASTER_KEY=test
CMD ["/usr/local/bin/openhands-server"]
"""

spec = BuildSpec(
base_image="python:3.12-slim",
tag=os.getenv("OPENHANDS_SERVER_IMAGE", "openhands/server:pyinst-dev"),
dockerfile_template_str=dockerfile_tpl,
artifact_zip=str(tmp_zip),
artifact_relpath="payload/openhands_bundle.zip",
build_args={"DEBIAN_FRONTEND": "noninteractive"},
)

rt = DockerRuntime(name=os.getenv("OPENHANDS_SERVER_NAME", "openhands-server"))
print("[docker] building image…")
rt.build(spec)
print(f"[docker] built {rt.image}")
print("[docker] starting container…")
rt.start(ports={9000: 9000})
container_runtime = rt

# Wait for health endpoint
for _ in range(60):
try:
with urllib.request.urlopen(f"{SERVER_URL}/health", timeout=2) as resp:
if resp.status == 200:
break
except Exception:
pass
time.sleep(1)
else:
raise RuntimeError("Server did not become healthy in time")

LLM_API_KEY = os.getenv("LITELLM_API_KEY")
if not LLM_API_KEY:
# print("[info] LITELLM_API_KEY not set; will only test /health and skip conversation.")
raise RuntimeError("LITELLM_API_KEY environment variable is not set.")

with OpenHandsClient(server_url=SERVER_URL, master_key=MASTER_KEY) as oh:
print("Starting conversation…")

working_dir = "/app" if USE_DOCKER else os.getcwd()
conv_id, _state = oh.start_conversation(
llm=LLM(
model="litellm_proxy/anthropic/claude-sonnet-4-20250514",
api_key=SecretStr(LLM_API_KEY),
base_url="https://llm-proxy.eval.all-hands.dev",
),
tools=[
ToolSpec(name="BashTool", params={"working_dir": working_dir}),
ToolSpec(name="FileEditorTool", params={}),
],
mcp_config=(
{"mcpServers": {}}
if USE_DOCKER
else {
"mcpServers": {
"fetch": {"command": "uvx", "args": ["mcp-server-fetch"]}
}
}
),
)
print("Conversation ID:", conv_id)

# 1) Ask the agent to read the repo and write 3 facts into FACTS.txt
oh.send_message(
conversation_id=conv_id,
content=[
TextContent(
text="Read https://github.com/All-Hands-AI/OpenHands and "
"write 3 facts about the project into FACTS.txt."
)
],
)
oh.wait_until_idle(conv_id)

# 2) Ask the agent to delete the file
oh.send_message(
conversation_id=conv_id,
content=[TextContent(text="Great! Now delete that file.")],
)
oh.wait_until_idle(conv_id)

# Print compact view of LLM messages
print("=" * 80)
evts = oh.get_events(conv_id, start=0, limit=1000)
print("Events:")
for e in evts:
print(e)

if container_runtime is not None:
print("[docker] stopping container…")
container_runtime.stop(remove=True)
2 changes: 2 additions & 0 deletions openhands/sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from importlib.metadata import PackageNotFoundError, version

from openhands.sdk.agent import Agent, AgentBase
from openhands.sdk.client import OpenHandsClient
from openhands.sdk.context import AgentContext
from openhands.sdk.conversation import Conversation, ConversationCallbackType
from openhands.sdk.event import (
Expand Down Expand Up @@ -55,5 +56,6 @@
"AgentContext",
"FileStore",
"LocalFileStore",
"OpenHandsClient",
"__version__",
]
Loading