Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions examples/01_standalone_sdk/40_acp_agent_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Example: Using ACPAgent with Claude Code ACP server.

This example shows how to use an ACP-compatible server (claude-code-acp)
as the agent backend instead of direct LLM calls.

Prerequisites:
- Node.js / npx available
- Claude Code CLI authenticated (or CLAUDE_API_KEY set)

Usage:
uv run python examples/01_standalone_sdk/40_acp_agent_example.py
"""

import os

from openhands.sdk.agent import ACPAgent
from openhands.sdk.conversation import Conversation


agent = ACPAgent(acp_command=["npx", "-y", "claude-code-acp"])

try:
cwd = os.getcwd()
conversation = Conversation(agent=agent, workspace=cwd)

conversation.send_message(
"List the Python source files under openhands-sdk/openhands/sdk/agent/, "
"then read the __init__.py and summarize what agent classes are exported."
)
conversation.run()
finally:
# Clean up the ACP server subprocess
agent.close()

print("Done!")
20 changes: 20 additions & 0 deletions openhands-sdk/openhands/sdk/agent/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from openhands.sdk.agent.agent import Agent
from openhands.sdk.agent.base import AgentBase


if TYPE_CHECKING:
from openhands.sdk.agent.acp_agent import ACPAgent


# Lazy import: eagerly importing ACPAgent registers it in the
# DiscriminatedUnionMixin, which makes `kind` required in Agent payloads
# that previously defaulted.
def __getattr__(name: str):
if name == "ACPAgent":
from openhands.sdk.agent.acp_agent import ACPAgent

return ACPAgent
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


__all__ = [
"Agent",
"AgentBase",
"ACPAgent",
]
Loading
Loading