Skip to content

Commit 034ccbc

Browse files
authored
fix(v1): widen AgentSideConnection.create_elicitation return type (#213)
1 parent e01508a commit 034ccbc

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

‎src/acp/agent/connection.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from ..interfaces import Agent
1212
from ..meta import CLIENT_METHODS
1313
from ..schema import (
14-
AcceptElicitationResponse,
1514
AgentMessageChunk,
1615
AgentPlanContentUpdate,
1716
AgentPlanRemovedUpdate,
@@ -20,7 +19,6 @@
2019
AuthAccount,
2120
AuthStatusUpdateNotification,
2221
AvailableCommandsUpdate,
23-
CancelElicitationResponse,
2422
CompleteElicitationNotification,
2523
ConfigOptionUpdate,
2624
CreateElicitationResponse,
@@ -33,7 +31,6 @@
3331
CreateUrlRequestElicitationRequest,
3432
CreateUrlSessionElicitationRequest,
3533
CurrentModeUpdate,
36-
DeclineElicitationResponse,
3734
ElicitationFormRequestMode,
3835
ElicitationFormSessionMode,
3936
ElicitationMode,
@@ -275,9 +272,7 @@ async def kill_terminal(self, session_id: str, terminal_id: str, **kwargs: Any)
275272
KillTerminalResponse,
276273
)
277274

278-
async def create_elicitation(
279-
self, message: str, mode: ElicitationMode, **kwargs: Any
280-
) -> AcceptElicitationResponse | DeclineElicitationResponse | CancelElicitationResponse:
275+
async def create_elicitation(self, message: str, mode: ElicitationMode, **kwargs: Any) -> CreateElicitationResponse:
281276
request = _create_elicitation_request(message, mode, kwargs or None)
282277
response = await self._conn.send_request(CLIENT_METHODS["elicitation_create"], serialize_params(request))
283278
return _CREATE_ELICITATION_RESPONSE_ADAPTER.validate_python(response)

‎tests/test_elicitation_catchall.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@
55
known values must still resolve to their specific typed variant.
66
"""
77

8+
from typing import get_type_hints
9+
810
import pytest
911
from pydantic import TypeAdapter, ValidationError
1012

13+
from acp import Client
1114
from acp._protocol_adapters import _mode_from_create_elicitation_request
15+
from acp.agent.connection import AgentSideConnection
1216
from acp.exceptions import RequestError
1317
from acp.schema import (
1418
AcceptElicitationResponse,
1519
CreateElicitationRequest,
1620
CreateElicitationResponse,
1721
CreateOtherElicitationRequest,
22+
ElicitationFormSessionMode,
1823
ElicitationOtherPropertySchema,
24+
ElicitationSchema,
1925
ElicitationStringPropertySchema,
2026
OtherElicitationResponse,
2127
OtherMultiSelectItems,
@@ -38,6 +44,31 @@ def test_custom_elicitation_response_falls_back_to_catchall() -> None:
3844
assert parsed.model_dump(by_alias=True)["until"] == "later"
3945

4046

47+
def test_elicitation_return_annotation_matches_client() -> None:
48+
client_return = get_type_hints(Client.create_elicitation)["return"]
49+
assert client_return == CreateElicitationResponse
50+
assert get_type_hints(AgentSideConnection.create_elicitation)["return"] == client_return
51+
52+
53+
@pytest.mark.asyncio
54+
async def test_custom_elicitation_response_roundtrip(connect, client, monkeypatch: pytest.MonkeyPatch) -> None:
55+
expected = OtherElicitationResponse.model_validate({"action": "x-snooze", "until": "later"})
56+
57+
async def create_elicitation(**kwargs) -> OtherElicitationResponse:
58+
return expected
59+
60+
monkeypatch.setattr(client, "create_elicitation", create_elicitation)
61+
agent_conn, client_conn = connect(use_unstable_protocol=True)
62+
async with agent_conn, client_conn:
63+
response = await agent_conn.create_elicitation(
64+
"Need input",
65+
ElicitationFormSessionMode(session_id="sess", requested_schema=ElicitationSchema(properties={})),
66+
)
67+
68+
assert isinstance(response, OtherElicitationResponse)
69+
assert response == expected
70+
71+
4172
def test_malformed_known_variant_is_rejected_not_catchall() -> None:
4273
# A "form" request missing the required requestedSchema must fail validation rather
4374
# than silently degrade to the catch-all (restores the schema's dropped `not` clause).

0 commit comments

Comments
 (0)