Skip to content

Commit 33ba15e

Browse files
committed
Refactor to use TransportProtocol class from types.py
1 parent 2a24b5f commit 33ba15e

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

src/a2a/client/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Channel: # type: ignore[no-redef]
4040
TaskPushNotificationConfig,
4141
TaskQueryParams,
4242
TaskStatusUpdateEvent,
43+
TransportProtocol,
4344
)
4445
from a2a.utils.constants import AGENT_CARD_WELL_KNOWN_PATH
4546

@@ -153,11 +154,13 @@ class ClientConfig:
153154
grpc_channel_factory: Callable[[str], Channel] | None = None
154155
"""Generates a grpc connection channel for a given url."""
155156

156-
supported_transports: list[str] = dataclasses.field(default_factory=list)
157+
supported_transports: list[TransportProtocol | str] = dataclasses.field(
158+
default_factory=list
159+
)
157160
"""Ordered list of transports for connecting to agent
158161
(in order of preference). Empty implies JSONRPC only.
159162
160-
This is a string type and not a Transports enum type to allow custom
163+
This is a string type to allow custom
161164
transports to exist in closed ecosystems.
162165
"""
163166

src/a2a/client/client_factory.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
from a2a.client.jsonrpc_client import NewJsonRpcClient
1010
from a2a.client.middleware import ClientCallInterceptor
1111
from a2a.client.rest_client import NewRestfulClient
12-
from a2a.types import AgentCapabilities, AgentCard, AgentInterface
13-
from a2a.utils import Transports
12+
from a2a.types import (
13+
AgentCapabilities,
14+
AgentCard,
15+
AgentInterface,
16+
TransportProtocol,
17+
)
1418

1519

1620
logger = logging.getLogger(__name__)
@@ -54,12 +58,12 @@ def __init__(
5458
self._registry: dict[str, ClientProducer] = {}
5559
# By default register the 3 core transports if in the config.
5660
# Can be overridden with custom clients via the register method.
57-
if Transports.JSONRPC in self._config.supported_transports:
58-
self._registry[Transports.JSONRPC] = NewJsonRpcClient
59-
if Transports.RESTful in self._config.supported_transports:
60-
self._registry[Transports.RESTful] = NewRestfulClient
61-
if Transports.GRPC in self._config.supported_transports:
62-
self._registry[Transports.GRPC] = NewGrpcClient
61+
if TransportProtocol.jsonrpc in self._config.supported_transports:
62+
self._registry[TransportProtocol.jsonrpc] = NewJsonRpcClient
63+
if TransportProtocol.http_json in self._config.supported_transports:
64+
self._registry[TransportProtocol.http_json] = NewRestfulClient
65+
if TransportProtocol.grpc in self._config.supported_transports:
66+
self._registry[TransportProtocol.grpc] = NewGrpcClient
6367

6468
def register(self, label: str, generator: ClientProducer) -> None:
6569
"""Register a new client producer for a given transport label."""
@@ -88,10 +92,12 @@ def create(
8892
server configuration, a `ValueError` is raised.
8993
"""
9094
# Determine preferential transport
91-
server_set = [card.preferred_transport or 'JSONRPC']
95+
server_set = [card.preferred_transport or TransportProtocol.jsonrpc]
9296
if card.additional_interfaces:
9397
server_set.extend([x.transport for x in card.additional_interfaces])
94-
client_set = self._config.supported_transports or ['JSONRPC']
98+
client_set = self._config.supported_transports or [
99+
TransportProtocol.jsonrpc
100+
]
95101
transport = None
96102
# Two options, use the client ordering or the server ordering.
97103
if self._config.use_client_preference:

src/a2a/utils/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@
2828
completed_task,
2929
new_task,
3030
)
31-
from a2a.utils.transports import Transports
3231

3332

3433
__all__ = [
3534
'AGENT_CARD_WELL_KNOWN_PATH',
3635
'DEFAULT_RPC_URL',
3736
'EXTENDED_AGENT_CARD_PATH',
38-
'Transports',
3937
'append_artifact_to_task',
4038
'are_modalities_compatible',
4139
'build_text_artifact',

src/a2a/utils/transports.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)