Skip to content

Commit 1ae30ee

Browse files
committed
Formatting
1 parent fcd9828 commit 1ae30ee

File tree

14 files changed

+211
-238
lines changed

14 files changed

+211
-238
lines changed

src/a2a/client/__init__.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,42 @@
77
CredentialService,
88
InMemoryContextCredentialStore,
99
)
10+
from a2a.client.client import (
11+
A2ACardResolver,
12+
Client,
13+
ClientConfig,
14+
ClientEvent,
15+
Consumer,
16+
)
17+
from a2a.client.client_factory import (
18+
ClientFactory,
19+
ClientProducer,
20+
minimal_agent_card,
21+
)
1022
from a2a.client.errors import (
1123
A2AClientError,
1224
A2AClientHTTPError,
1325
A2AClientJSONError,
1426
A2AClientTimeoutError,
1527
)
28+
from a2a.client.grpc_client import (
29+
GrpcClient,
30+
GrpcTransportClient,
31+
NewGrpcClient,
32+
)
33+
from a2a.client.helpers import create_text_message_object
1634
from a2a.client.jsonrpc_client import (
1735
JsonRpcClient,
1836
JsonRpcTransportClient,
1937
NewJsonRpcClient,
2038
)
21-
from a2a.client.grpc_client import (
22-
GrpcTransportClient,
23-
GrpcClient,
24-
NewGrpcClient,
25-
)
39+
from a2a.client.middleware import ClientCallContext, ClientCallInterceptor
2640
from a2a.client.rest_client import (
27-
RestTransportClient,
28-
RestClient,
2941
NewRestfulClient,
42+
RestClient,
43+
RestTransportClient,
3044
)
31-
from a2a.client.helpers import create_text_message_object
32-
from a2a.client.middleware import ClientCallContext, ClientCallInterceptor
33-
from a2a.client.client import (
34-
A2ACardResolver,
35-
Client,
36-
ClientConfig,
37-
Consumer,
38-
ClientEvent,
39-
)
40-
from a2a.client.client_factory import (
41-
ClientFactory,
42-
ClientProducer,
43-
minimal_agent_card
44-
)
45+
4546

4647
# For backward compatability define this alias. This will be deprecated in
4748
# a future release.
@@ -71,32 +72,32 @@ def __init__(self, *args, **kwargs):
7172

7273
__all__ = [
7374
'A2ACardResolver',
75+
'A2AClient', # for backward compatability
7476
'A2AClientError',
7577
'A2AClientHTTPError',
7678
'A2AClientJSONError',
7779
'A2AClientTimeoutError',
80+
'A2AGrpcClient', # for backward compatability
7881
'AuthInterceptor',
82+
'Client',
7983
'ClientCallContext',
8084
'ClientCallInterceptor',
81-
'Consumer',
82-
'CredentialService',
83-
'InMemoryContextCredentialStore',
84-
'create_text_message_object',
85-
'A2AClient', # for backward compatability
86-
'A2AGrpcClient', # for backward compatability
87-
'Client',
85+
'ClientConfig',
8886
'ClientEvent',
8987
'ClientFactory',
90-
'ClientConfig',
9188
'ClientProducer',
92-
'GrpcTransportClient',
89+
'Consumer',
90+
'CredentialService',
9391
'GrpcClient',
94-
'NewGrpcClient',
92+
'GrpcTransportClient',
93+
'InMemoryContextCredentialStore',
9594
'JsonRpcClient',
9695
'JsonRpcTransportClient',
96+
'NewGrpcClient',
9797
'NewJsonRpcClient',
98-
'minimal_agent_card',
99-
'RestTransportClient',
100-
'RestClient',
10198
'NewRestfulClient',
99+
'RestClient',
100+
'RestTransportClient',
101+
'create_text_message_object',
102+
'minimal_agent_card',
102103
]

src/a2a/client/client.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,30 @@
33
import logging
44

55
from abc import ABC, abstractmethod
6-
from collections.abc import AsyncIterator
7-
from typing import Any, Callable, Coroutine
8-
from uuid import uuid4
6+
from collections.abc import AsyncIterator, Callable, Coroutine
7+
from typing import Any
98

109
import httpx
1110

12-
from httpx_sse import SSEError, aconnect_sse
1311
from pydantic import ValidationError
1412

13+
1514
# Attempt to import the optional module
1615
try:
1716
from grpc.aio import Channel
1817
except ImportError:
1918
# If grpc.aio is not available, define a dummy type for type checking.
2019
# This dummy type will only be used by type checkers.
2120
if TYPE_CHECKING:
21+
2222
class Channel: # type: ignore[no-redef]
2323
pass
2424
else:
25-
Channel = None # At runtime, pd will be None if the import failed.
25+
Channel = None # At runtime, pd will be None if the import failed.
2626

2727
from a2a.client.errors import (
2828
A2AClientHTTPError,
2929
A2AClientJSONError,
30-
A2AClientTimeoutError,
3130
)
3231
from a2a.client.middleware import ClientCallContext, ClientCallInterceptor
3332
from a2a.types import (
@@ -36,14 +35,13 @@ class Channel: # type: ignore[no-redef]
3635
Message,
3736
PushNotificationConfig,
3837
Task,
38+
TaskArtifactUpdateEvent,
3939
TaskIdParams,
40-
TaskQueryParams,
4140
TaskPushNotificationConfig,
41+
TaskQueryParams,
4242
TaskStatusUpdateEvent,
43-
TaskArtifactUpdateEvent,
4443
)
4544
from a2a.utils.constants import AGENT_CARD_WELL_KNOWN_PATH
46-
from a2a.utils.telemetry import SpanKind, trace_class
4745

4846

4947
logger = logging.getLogger(__name__)
@@ -136,6 +134,7 @@ async def get_agent_card(
136134

137135
return agent_card
138136

137+
139138
@dataclasses.dataclass
140139
class ClientConfig:
141140
"""Configuration class for the A2A Client Factory"""
@@ -154,7 +153,7 @@ class ClientConfig:
154153
grpc_channel_factory: Callable[[str], Channel] | None = None
155154
"""Generates a grpc connection channel for a given url."""
156155

157-
supported_transports: list[str] = dataclasses.field(default_factory=list)
156+
supported_transports: list[str] = dataclasses.field(default_factory=list)
158157
"""Ordered list of transports for connecting to agent
159158
(in order of preference). Empty implies JSONRPC only.
160159
@@ -166,12 +165,15 @@ class ClientConfig:
166165
"""Whether to use client transport preferences over server preferences.
167166
Recommended to use server preferences in most situations."""
168167

169-
accepted_outputModes: list[str] = dataclasses.field(default_factory=list)
168+
accepted_outputModes: list[str] = dataclasses.field(default_factory=list)
170169
"""The set of accepted output modes for the client."""
171170

172-
push_notification_configs: list[PushNotificationConfig] = dataclasses.field(default_factory=list)
171+
push_notification_configs: list[PushNotificationConfig] = dataclasses.field(
172+
default_factory=list
173+
)
173174
"""Push notification callbacks to use for every request."""
174175

176+
175177
UpdateEvent = TaskStatusUpdateEvent | TaskArtifactUpdateEvent | None
176178
# Alias for emitted events from client
177179
ClientEvent = tuple[Task, UpdateEvent]
@@ -183,7 +185,6 @@ class ClientConfig:
183185

184186

185187
class Client(ABC):
186-
187188
def __init__(
188189
self,
189190
consumers: list[Consumer] = [],
@@ -252,14 +253,11 @@ async def resubscribe(
252253
*,
253254
context: ClientCallContext | None = None,
254255
) -> AsyncIterator[Task | Message]:
255-
pass
256256
yield
257257

258258
@abstractmethod
259259
async def get_card(
260-
self,
261-
*,
262-
context: ClientCallContext | None = None
260+
self, *, context: ClientCallContext | None = None
263261
) -> AgentCard:
264262
pass
265263

src/a2a/client/client_factory.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,20 @@
11
from __future__ import annotations
2-
import json
3-
import logging
4-
5-
from collections.abc import AsyncGenerator
6-
from typing import Any, TYPE_CHECKING, Callable
7-
8-
import httpx
92

10-
from httpx_sse import SSEError, aconnect_sse
11-
from pydantic import ValidationError
3+
import logging
124

13-
from a2a.utils import Transports
5+
from collections.abc import Callable
146

157
from a2a.client.client import Client, ClientConfig, Consumer
16-
from a2a.client.jsonrpc_client import NewJsonRpcClient
178
from a2a.client.grpc_client import NewGrpcClient
9+
from a2a.client.jsonrpc_client import NewJsonRpcClient
10+
from a2a.client.middleware import ClientCallInterceptor
1811
from a2a.client.rest_client import NewRestfulClient
19-
from a2a.client.errors import A2AClientHTTPError, A2AClientJSONError
20-
from a2a.client.middleware import ClientCallContext, ClientCallInterceptor
2112
from a2a.types import (
2213
AgentCapabilities,
2314
AgentCard,
24-
Message,
25-
Task,
26-
TaskIdParams,
27-
TaskQueryParams,
28-
GetTaskPushNotificationConfigParams,
29-
TaskPushNotificationConfig,
3015
)
16+
from a2a.utils import Transports
17+
3118

3219
logger = logging.getLogger(__name__)
3320

@@ -36,11 +23,12 @@
3623
AgentCard | str,
3724
ClientConfig,
3825
list[Consumer],
39-
list[ClientCallInterceptor]
26+
list[ClientCallInterceptor],
4027
],
41-
Client
28+
Client,
4229
]
4330

31+
4432
class ClientFactory:
4533
"""ClientFactory is used to generate the appropriate client for the agent.
4634
@@ -103,9 +91,7 @@ def create(
10391
# Determine preferential transport
10492
server_set = [card.preferred_transport or 'JSONRPC']
10593
if card.additional_interfaces:
106-
server_set.extend(
107-
[x.transport for x in card.additional_interfaces]
108-
)
94+
server_set.extend([x.transport for x in card.additional_interfaces])
10995
client_set = self._config.supported_transports or ['JSONRPC']
11096
transport = None
11197
# Two options, use the client ordering or the server ordering.
@@ -130,6 +116,7 @@ def create(
130116
card, self._config, all_consumers, interceptors
131117
)
132118

119+
133120
def minimal_agent_card(url: str, transports: list[str] = []) -> AgentCard:
134121
"""Generates a minimal card to simplify bootstrapping client creation.
135122

src/a2a/client/client_task_manager.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import logging
22

3+
from a2a.client.errors import A2AClientInvalidArgsError
34
from a2a.server.events.event_queue import Event
45
from a2a.types import (
5-
InvalidParamsError,
66
Message,
77
Task,
88
TaskArtifactUpdateEvent,
@@ -11,7 +11,6 @@
1111
TaskStatusUpdateEvent,
1212
)
1313
from a2a.utils import append_artifact_to_task
14-
from a2a.client.errors import A2AClientInvalidArgsError
1514

1615

1716
logger = logging.getLogger(__name__)
@@ -74,7 +73,7 @@ async def save_task_event(
7473
if isinstance(event, Task):
7574
if self._current_task:
7675
raise A2AClientInvalidArgsError(
77-
"Task is already set, create new manager for new tasks."
76+
'Task is already set, create new manager for new tasks.'
7877
)
7978
await self._save_task(event)
8079
return event
@@ -101,7 +100,9 @@ async def save_task_event(
101100
)
102101
if isinstance(event, TaskStatusUpdateEvent):
103102
logger.debug(
104-
'Updating task %s status to: %s', event.taskId, event.status.state
103+
'Updating task %s status to: %s',
104+
event.taskId,
105+
event.status.state,
105106
)
106107
if event.status.message:
107108
if not task.history:

src/a2a/client/grpc_client.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
Client,
1818
ClientCallContext,
1919
ClientConfig,
20-
Consumer,
2120
ClientEvent,
21+
Consumer,
2222
)
23-
from a2a.client.middleware import ClientCallInterceptor
2423
from a2a.client.client_task_manager import ClientTaskManager
24+
from a2a.client.middleware import ClientCallInterceptor
2525
from a2a.grpc import a2a_pb2, a2a_pb2_grpc
2626
from a2a.types import (
2727
AgentCard,
@@ -64,8 +64,7 @@ def __init__(
6464
# If they don't provide an agent card, but do have a stub, lookup the
6565
# card from the stub.
6666
self._needs_extended_card = (
67-
agent_card.supportsAuthenticatedExtendedCard
68-
if agent_card else True
67+
agent_card.supportsAuthenticatedExtendedCard if agent_card else True
6968
)
7069

7170
async def send_message(
@@ -251,7 +250,7 @@ async def get_card(
251250
card_pb = await self.stub.GetAgentCard(
252251
a2a_pb2.GetAgentCardRequest(),
253252
)
254-
card = proto_utils.FromProto.agent_card(card_pb)
253+
card = proto_utils.FromProto.agent_card(card_pb)
255254
self.agent_card = card
256255
self._needs_extended_card = False
257256
return card
@@ -324,7 +323,7 @@ async def send_message(
324323
await tracker.process(event)
325324
result = (
326325
tracker.get_task(),
327-
None if isinstance(event, Task) else event
326+
None if isinstance(event, Task) else event,
328327
)
329328
await self.consume(result, self._card)
330329
yield result
@@ -410,7 +409,7 @@ def NewGrpcClient(
410409
card: AgentCard,
411410
config: ClientConfig,
412411
consumers: list[Consumer],
413-
middleware: list[ClientCallInterceptor]
412+
middleware: list[ClientCallInterceptor],
414413
) -> Client:
415414
"""Generator for the `GrpcClient` implementation."""
416415
return GrpcClient(card, config, consumers, middleware)

0 commit comments

Comments
 (0)