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
7 changes: 1 addition & 6 deletions src/acp/agent/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from ..interfaces import Agent
from ..meta import CLIENT_METHODS
from ..schema import (
AcceptElicitationResponse,
AgentMessageChunk,
AgentPlanContentUpdate,
AgentPlanRemovedUpdate,
Expand All @@ -20,7 +19,6 @@
AuthAccount,
AuthStatusUpdateNotification,
AvailableCommandsUpdate,
CancelElicitationResponse,
CompleteElicitationNotification,
ConfigOptionUpdate,
CreateElicitationResponse,
Expand All @@ -33,7 +31,6 @@
CreateUrlRequestElicitationRequest,
CreateUrlSessionElicitationRequest,
CurrentModeUpdate,
DeclineElicitationResponse,
ElicitationFormRequestMode,
ElicitationFormSessionMode,
ElicitationMode,
Expand Down Expand Up @@ -275,9 +272,7 @@ async def kill_terminal(self, session_id: str, terminal_id: str, **kwargs: Any)
KillTerminalResponse,
)

async def create_elicitation(
self, message: str, mode: ElicitationMode, **kwargs: Any
) -> AcceptElicitationResponse | DeclineElicitationResponse | CancelElicitationResponse:
async def create_elicitation(self, message: str, mode: ElicitationMode, **kwargs: Any) -> CreateElicitationResponse:
request = _create_elicitation_request(message, mode, kwargs or None)
response = await self._conn.send_request(CLIENT_METHODS["elicitation_create"], serialize_params(request))
return _CREATE_ELICITATION_RESPONSE_ADAPTER.validate_python(response)
Expand Down
31 changes: 31 additions & 0 deletions tests/test_elicitation_catchall.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
known values must still resolve to their specific typed variant.
"""

from typing import get_type_hints

import pytest
from pydantic import TypeAdapter, ValidationError

from acp import Client
from acp._protocol_adapters import _mode_from_create_elicitation_request
from acp.agent.connection import AgentSideConnection
from acp.exceptions import RequestError
from acp.schema import (
AcceptElicitationResponse,
CreateElicitationRequest,
CreateElicitationResponse,
CreateOtherElicitationRequest,
ElicitationFormSessionMode,
ElicitationOtherPropertySchema,
ElicitationSchema,
ElicitationStringPropertySchema,
OtherElicitationResponse,
OtherMultiSelectItems,
Expand All @@ -38,6 +44,31 @@ def test_custom_elicitation_response_falls_back_to_catchall() -> None:
assert parsed.model_dump(by_alias=True)["until"] == "later"


def test_elicitation_return_annotation_matches_client() -> None:
client_return = get_type_hints(Client.create_elicitation)["return"]
assert client_return == CreateElicitationResponse
assert get_type_hints(AgentSideConnection.create_elicitation)["return"] == client_return


@pytest.mark.asyncio
async def test_custom_elicitation_response_roundtrip(connect, client, monkeypatch: pytest.MonkeyPatch) -> None:
expected = OtherElicitationResponse.model_validate({"action": "x-snooze", "until": "later"})

async def create_elicitation(**kwargs) -> OtherElicitationResponse:
return expected

monkeypatch.setattr(client, "create_elicitation", create_elicitation)
agent_conn, client_conn = connect(use_unstable_protocol=True)
async with agent_conn, client_conn:
response = await agent_conn.create_elicitation(
"Need input",
ElicitationFormSessionMode(session_id="sess", requested_schema=ElicitationSchema(properties={})),
)

assert isinstance(response, OtherElicitationResponse)
assert response == expected


def test_malformed_known_variant_is_rejected_not_catchall() -> None:
# A "form" request missing the required requestedSchema must fail validation rather
# than silently degrade to the catch-all (restores the schema's dropped `not` clause).
Expand Down
Loading