diff --git a/src/a2a/client/base_client.py b/src/a2a/client/base_client.py index fbcdb955e..9c5298653 100644 --- a/src/a2a/client/base_client.py +++ b/src/a2a/client/base_client.py @@ -17,6 +17,7 @@ from a2a.plugins.types import ClientRequest, ClientResponse from a2a.types.a2a_pb2 import ( AgentCard, + AgentInterface, CancelTaskRequest, DeleteTaskPushNotificationConfigRequest, GetExtendedAgentCardRequest, @@ -41,13 +42,14 @@ class BaseClient(Client): the interceptors, ``after_client_request`` after them. """ - def __init__( + def __init__( # noqa: PLR0913 self, card: AgentCard, config: ClientConfig, transport: ClientTransport, interceptors: list[ClientCallInterceptor], *, + interface: AgentInterface | None = None, plugins: PluginManager | None = None, ): """Initializes the client. @@ -57,6 +59,7 @@ def __init__( config: The client configuration. transport: The transport used for calls. interceptors: Interceptors applied to every call. + interface: The card interface this client talks to. plugins: Plugin manager whose client hooks run for every call. Defaults to the global manager at construction time. """ @@ -65,6 +68,7 @@ def __init__( self._config = config self._transport = transport self._interceptors = interceptors + self._interface = interface self._plugins = plugins if plugins is not None else get_global() async def send_message( @@ -411,6 +415,7 @@ def _client_request( payload=input_data, agent_card=self._card, context=context if context is not None else ClientCallContext(), + interface=self._interface, ) async def _execute_with_interceptors( diff --git a/src/a2a/client/client_factory.py b/src/a2a/client/client_factory.py index 14d2ab107..ef8ac446c 100644 --- a/src/a2a/client/client_factory.py +++ b/src/a2a/client/client_factory.py @@ -396,6 +396,7 @@ def create( self._config, transport, interceptors or [], + interface=selected_interface, ) diff --git a/src/a2a/plugins/types.py b/src/a2a/plugins/types.py index 922dcdf0e..00acd51a0 100644 --- a/src/a2a/plugins/types.py +++ b/src/a2a/plugins/types.py @@ -18,7 +18,7 @@ from a2a.server.tasks.push_notification_sender import ( PushNotificationEvent, ) - from a2a.types.a2a_pb2 import AgentCard, Task, TaskState + from a2a.types.a2a_pb2 import AgentCard, AgentInterface, Task, TaskState @dataclass @@ -77,12 +77,14 @@ class ClientRequest: agent_card: The card of the remote agent. context: The call context. ``service_parameters`` holds the outgoing headers. + interface: The Agent Card interface the client selected. """ method: str payload: Any agent_card: AgentCard context: ClientCallContext + interface: AgentInterface | None = None @dataclass diff --git a/tests/client/test_base_client_plugins.py b/tests/client/test_base_client_plugins.py index dbb375e7e..420f2f5cc 100644 --- a/tests/client/test_base_client_plugins.py +++ b/tests/client/test_base_client_plugins.py @@ -120,6 +120,7 @@ async def test_unary_call_runs_hooks(): (request,) = recorder.hooks('before_client_request') assert request.method == 'get_task' assert request.agent_card.name == 'Remote' + assert request.interface is None (response,) = recorder.hooks('after_client_request') assert response.payload is result assert response.is_final diff --git a/tests/client/test_client_factory.py b/tests/client/test_client_factory.py index 269090c83..ecb4f65f0 100644 --- a/tests/client/test_client_factory.py +++ b/tests/client/test_client_factory.py @@ -88,6 +88,7 @@ def test_client_factory_selects_secondary_transport_url( assert isinstance(client._transport, RestTransport) # type: ignore[attr-defined] assert client._transport.url == 'http://secondary-url.com' # type: ignore[attr-defined] + assert client._interface.url == 'http://secondary-url.com' # type: ignore[attr-defined] def test_client_factory_server_preference(base_agent_card: AgentCard):