Skip to content
Open
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: 6 additions & 1 deletion src/a2a/client/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from a2a.plugins.types import ClientRequest, ClientResponse
from a2a.types.a2a_pb2 import (
AgentCard,
AgentInterface,
CancelTaskRequest,
DeleteTaskPushNotificationConfigRequest,
GetExtendedAgentCardRequest,
Expand All @@ -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.
Expand All @@ -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.
"""
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/a2a/client/client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
try:
from a2a.client.transports.grpc import GrpcTransport
except ImportError:
GrpcTransport = None # type: ignore # pyright: ignore

Check warning on line 42 in src/a2a/client/client_factory.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

ty (unused-type-ignore-comment)

src/a2a/client/client_factory.py:42:27: unused-type-ignore-comment: Unused blanket `type: ignore` directive help: Remove the unused suppression comment


try:
from a2a.compat.v0_3.grpc_transport import CompatGrpcTransport
except ImportError:
CompatGrpcTransport = None # type: ignore # pyright: ignore

Check warning on line 48 in src/a2a/client/client_factory.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

ty (unused-type-ignore-comment)

src/a2a/client/client_factory.py:48:33: unused-type-ignore-comment: Unused blanket `type: ignore` directive help: Remove the unused suppression comment

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -396,6 +396,7 @@
self._config,
transport,
interceptors or [],
interface=selected_interface,
)


Expand Down
4 changes: 3 additions & 1 deletion src/a2a/plugins/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/client/test_base_client_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/client/test_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading