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
80 changes: 62 additions & 18 deletions openhands-sdk/openhands/sdk/agent/acp_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,34 @@
from acp.exceptions import RequestError as ACPRequestError
from acp.helpers import image_block, text_block
from acp.schema import (
AcpMcpServer,
AgentMessageChunk,
AgentThoughtChunk,
AllowedOutcome,
CreateElicitationResponse,
CreateTerminalResponse,
DeclineElicitationResponse,
ElicitationMode,
EnvVariable,
HttpHeader,
HttpMcpServer,
ImageContentBlock,
KillTerminalResponse,
McpServerStdio,
PermissionOption,
PromptResponse,
ReadTextFileResponse,
ReleaseTerminalResponse,
RequestPermissionResponse,
SseMcpServer,
TerminalOutputResponse,
TextContentBlock,
ToolCallProgress,
ToolCallStart,
ToolCallUpdate,
UsageUpdate,
WaitForTerminalExitResponse,
WriteTextFileResponse,
)
from acp.transports import default_environment
from pydantic import (
Expand Down Expand Up @@ -617,14 +630,23 @@ async def _apply_acp_model(
Codex, callers may still pass a combined Canvas id such as ``gpt-5.5/high``;
codex-acp exposes reasoning effort as a separate config option, so split it
only on the config-options mechanism.

agent-client-protocol 0.12.1 dropped the UNSTABLE ``models`` extension from
the ACP schema and removed ``ClientSideConnection.set_session_model``. A live
0.12 connection therefore has no legacy RPC to call, so the ``else`` branch
only invokes it when the connection actually exposes the method (test
doubles do; real 0.12 connections do not) and otherwise no-ops rather than
raising ``AttributeError``.
"""
if via_config_option:
for config_id, value in _model_config_options(agent_name, model):
await conn.set_config_option(
config_id=config_id, value=value, session_id=session_id
)
else:
await conn.set_session_model(model_id=model, session_id=session_id)
elif hasattr(conn, "set_session_model"):
await conn.set_session_model( # type: ignore[attr-defined]
model_id=model, session_id=session_id
)


def _usable_models(infos: Iterable[ACPModelInfo]) -> list[ACPModelInfo]:
Expand Down Expand Up @@ -689,7 +711,7 @@ def _extract_session_models(


# The ACP MCP server union accepted by new_session() / load_session().
_ACPMcpServer = HttpMcpServer | SseMcpServer | McpServerStdio
_ACPMcpServer = HttpMcpServer | SseMcpServer | McpServerStdio | AcpMcpServer


def _remote_mcp_headers(server: MCPServer, name: str) -> list[HttpHeader]:
Expand Down Expand Up @@ -1579,11 +1601,11 @@ def _maybe_signal_activity(self) -> None:

async def request_permission(
self,
options: list[Any],
session_id: str, # noqa: ARG002
tool_call: Any,
tool_call: ToolCallUpdate,
options: list[PermissionOption],
**kwargs: Any, # noqa: ARG002
) -> Any:
) -> RequestPermissionResponse:
"""Auto-approve all permission requests from the ACP server."""
# Pick the first option (usually "allow once")
option_id = options[0].option_id if options else "allow_once"
Expand All @@ -1596,52 +1618,74 @@ async def request_permission(
outcome=AllowedOutcome(outcome="selected", option_id=option_id),
)

async def create_elicitation(
self,
message: str, # noqa: ARG002
mode: ElicitationMode, # noqa: ARG002
**kwargs: Any, # noqa: ARG002
) -> CreateElicitationResponse:
"""Decline elicitation requests; the headless bridge has no user to ask.

Added to the ``Client`` protocol in agent-client-protocol 0.12.x. None
of the pinned ACP providers elicit during a headless turn, so this is a
defensive default rather than an exercised code path.
"""
return DeclineElicitationResponse(action="decline")

async def complete_elicitation(
self,
elicitation_id: str, # noqa: ARG002
**kwargs: Any, # noqa: ARG002
) -> None:
"""No-op completion for an elicitation the bridge always declines."""
return None

# fs/terminal methods — raise NotImplementedError; ACP server handles its own
async def write_text_file(
self, content: str, path: str, session_id: str, **kwargs: Any
) -> None:
self, session_id: str, path: str, content: str, **kwargs: Any
) -> WriteTextFileResponse | None:
raise NotImplementedError("ACP server handles file operations")

async def read_text_file(
self,
path: str,
session_id: str,
limit: int | None = None,
path: str,
line: int | None = None,
limit: int | None = None,
**kwargs: Any,
) -> Any:
) -> ReadTextFileResponse:
raise NotImplementedError("ACP server handles file operations")

async def create_terminal(
self,
command: str,
session_id: str,
command: str,
args: list[str] | None = None,
env: list[EnvVariable] | None = None,
cwd: str | None = None,
env: Any = None,
output_byte_limit: int | None = None,
**kwargs: Any,
) -> Any:
) -> CreateTerminalResponse:
raise NotImplementedError("ACP server handles terminal operations")

async def terminal_output(
self, session_id: str, terminal_id: str, **kwargs: Any
) -> Any:
) -> TerminalOutputResponse:
raise NotImplementedError("ACP server handles terminal operations")

async def release_terminal(
self, session_id: str, terminal_id: str, **kwargs: Any
) -> None:
) -> ReleaseTerminalResponse | None:
raise NotImplementedError("ACP server handles terminal operations")

async def wait_for_terminal_exit(
self, session_id: str, terminal_id: str, **kwargs: Any
) -> Any:
) -> WaitForTerminalExitResponse:
raise NotImplementedError("ACP server handles terminal operations")

async def kill_terminal(
self, session_id: str, terminal_id: str, **kwargs: Any
) -> None:
) -> KillTerminalResponse | None:
raise NotImplementedError("ACP server handles terminal operations")

async def ext_method(
Expand Down
2 changes: 1 addition & 1 deletion openhands-sdk/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "OpenHands SDK - Core functionality for building AI agents"

requires-python = ">=3.12"
dependencies = [
"agent-client-protocol>=0.10.1,<0.11.0", # 0.11.0 reordered prompt() args, broke the client (#4830)
"agent-client-protocol>=0.12.1,<0.13.0", # 0.11.0 reordered prompt() args, broke the client (#4830)
"deprecation>=2.1.0",
"fakeredis[lua]>=2.32.1", # Explicit dependency for docket/fastmcp background tasks
"fastmcp>=3.2.0", # 3.2.0 reads back the stored absolute OAuth token expiry
Expand Down
14 changes: 11 additions & 3 deletions tests/sdk/agent/test_acp_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8492,12 +8492,20 @@ def test_codex_112_prefers_config_option_over_legacy_models(self):
]

def test_gemini_046_uses_set_session_model(self):
# agent-client-protocol 0.12.1 bumped the ACP schema to v1.19.0, which
# dropped the UNSTABLE ``models`` extension from ``NewSessionResponse``.
# gemini-cli 0.46.0 selected its model via that legacy ``models`` block
# and advertises no ``model`` ``configOptions`` select, so once parsed
# through the 0.12.1 schema the block is no longer visible: the SDK
# detects no model-selection mechanism (current/available both absent,
# mechanism falls back to the legacy default) rather than hallucinating
# a model. ``_apply_acp_model`` then no-ops the legacy branch because
# ``ClientSideConnection.set_session_model`` was removed alongside it.
resp = NewSessionResponse.model_validate(_GEMINI_046_SESSION)
cur, avail, via = _extract_session_models(resp)
assert via is False
assert cur == "gemini-3-flash-preview"
assert avail is not None
assert "gemini-3-pro-preview" in [m.model_id for m in avail]
assert cur is None
assert avail is None


class TestApplyAcpModelNoFallback:
Expand Down
9 changes: 8 additions & 1 deletion tests/sdk/agent/test_acp_conformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,14 @@ def _spy_select_auth_method(auth_methods, env):

# The session advertised *some* model-selection mechanism, matching
# supports_set_session_model's premise that one exists.
if provider.supports_set_session_model:
# agent-client-protocol 0.12.1 dropped the UNSTABLE ``models`` extension
# from NewSessionResponse, so a provider that selects its model via the
# legacy ``set_session_model`` RPC (gemini-cli 0.46, which advertises no
# ``model`` configOptions select) no longer surfaces ``_available_models``
# even though the live session still sends the block. Only require a
# visible mechanism when the session advertised the (still-supported)
# configOptions select.
if provider.supports_set_session_model and agent._model_via_config_option:
assert agent._available_models is not None, (
f"provider={provider.key} claims supports_set_session_model "
"but the session response carried neither configOptions nor "
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading