Skip to content

Commit e7a1c50

Browse files
committed
refactor: simplify client factory interface and standardize streaming return types to StreamResponse
1 parent b7b699a commit e7a1c50

4 files changed

Lines changed: 7 additions & 11 deletions

File tree

src/a2a/client/base_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async def send_message(
6464
context: Optional client call context.
6565
6666
Yields:
67-
An async iterator of `ClientEvent`
67+
An async iterator of `StreamResponse`
6868
"""
6969
self._apply_client_config(request)
7070
if not self._config.streaming or not self._card.capabilities.streaming:
@@ -314,7 +314,7 @@ async def subscribe(
314314
context: Optional client call context.
315315
316316
Yields:
317-
An async iterator of `ClientEvent` objects.
317+
An async iterator of `StreamResponse` objects.
318318
319319
Raises:
320320
NotImplementedError: If streaming is not supported by the client or server.
@@ -432,7 +432,7 @@ async def _execute_stream_with_interceptors(
432432
)
433433
before_result = await self._intercept_before(before_args)
434434

435-
if before_result:
435+
if before_result is not None:
436436
after_args = AfterArgs(
437437
result=before_result['early_return'],
438438
method=method,

src/a2a/client/client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ async def send_message(
132132
133133
This will automatically use the streaming or non-streaming approach
134134
as supported by the server and the client config. Client will
135-
aggregate update events and return an iterator of (`Task`,`Update`)
136-
pairs, or a `Message`. Client will also send these values to any
137-
configured `Consumer`s in the client.
135+
aggregate update events and return an iterator of `StreamResponse`.
138136
"""
139137
return
140138
yield

src/a2a/client/client_factory.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ class ClientFactory:
6363
6464
.. code-block:: python
6565
66-
factory = ClientFactory(config, consumers)
66+
factory = ClientFactory(config)
6767
# Optionally register custom client implementations
6868
factory.register('my_customer_transport', NewCustomTransportClient)
69-
# Then with an agent card make a client with additional consumers and
70-
# interceptors
71-
client = factory.create(card, additional_consumers, interceptors)
69+
# Then with an agent card make a client with additional interceptors
70+
client = factory.create(card, interceptors)
7271
7372
Now the client can be used consistently regardless of the transport. This
7473
aligns the client configuration with the server's capabilities.

tests/client/test_base_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ async def create_stream(*args, **kwargs):
150150
)
151151
assert not mock_transport.send_message.called
152152
assert len(events) == 1
153-
# events[0] is (StreamResponse, Task) tuple
154153
response = events[0]
155154
assert response.task.id == 'task-123'
156155

0 commit comments

Comments
 (0)