Skip to content

Commit fc84a48

Browse files
simonrosenbergclaudeenystxingyaoww
authored
feat: Add ACPAgent for Agent Client Protocol integration (#2133)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Engel Nyst <engel.nyst@gmail.com> Co-authored-by: Xingyao Wang <xingyao@all-hands.dev>
1 parent 86a0dfe commit fc84a48

File tree

6 files changed

+1417
-0
lines changed

6 files changed

+1417
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Example: Using ACPAgent with Claude Code ACP server.
2+
3+
This example shows how to use an ACP-compatible server (claude-code-acp)
4+
as the agent backend instead of direct LLM calls.
5+
6+
Prerequisites:
7+
- Node.js / npx available
8+
- Claude Code CLI authenticated (or CLAUDE_API_KEY set)
9+
10+
Usage:
11+
uv run python examples/01_standalone_sdk/40_acp_agent_example.py
12+
"""
13+
14+
import os
15+
16+
from openhands.sdk.agent import ACPAgent
17+
from openhands.sdk.conversation import Conversation
18+
19+
20+
agent = ACPAgent(acp_command=["npx", "-y", "claude-code-acp"])
21+
22+
try:
23+
cwd = os.getcwd()
24+
conversation = Conversation(agent=agent, workspace=cwd)
25+
26+
conversation.send_message(
27+
"List the Python source files under openhands-sdk/openhands/sdk/agent/, "
28+
"then read the __init__.py and summarize what agent classes are exported."
29+
)
30+
conversation.run()
31+
finally:
32+
# Clean up the ACP server subprocess
33+
agent.close()
34+
35+
print("Done!")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
15
from openhands.sdk.agent.agent import Agent
26
from openhands.sdk.agent.base import AgentBase
37

48

9+
if TYPE_CHECKING:
10+
from openhands.sdk.agent.acp_agent import ACPAgent
11+
12+
13+
# Lazy import: eagerly importing ACPAgent registers it in the
14+
# DiscriminatedUnionMixin, which makes `kind` required in Agent payloads
15+
# that previously defaulted.
16+
def __getattr__(name: str):
17+
if name == "ACPAgent":
18+
from openhands.sdk.agent.acp_agent import ACPAgent
19+
20+
return ACPAgent
21+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
22+
23+
524
__all__ = [
625
"Agent",
726
"AgentBase",
27+
"ACPAgent",
828
]

0 commit comments

Comments
 (0)