Skip to content

Commit 2887c1f

Browse files
committed
change Sending Messages & Handling Responses
1 parent 1b1b49b commit 2887c1f

1 file changed

Lines changed: 16 additions & 43 deletions

File tree

docs/migrations/v1_0/README.md

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This guide covers the breaking changes introduced in `a2a-sdk` v1.0 and explains
1313
3. [Server: DefaultRequestHandler](#3-server-defaultrequesthandler)
1414
4. [Server: Application Setup](#4-server-application-setup)
1515
5. [Client: Creating a Client](#5-client-creating-a-client)
16-
6. [Client: Sending Messages & Handling Responses](#6-client-sending-messages--handling-responses)
16+
6. [Client: Send Message](#6-client-send-message)
1717
7. [Client: Push Notifications Config](#7-client-push-notifications-config)
1818
8. [Helper Utilities](#8-helper-utilities)
1919

@@ -277,63 +277,36 @@ async with client:
277277
278278
---
279279

280-
## 6. Client: Sending Messages & Handling Responses
280+
## 6. Client: Send Message
281281

282-
Key differences:
283-
- `send_message()` returns `AsyncIterator[StreamResponse]`; iterate with `async for`
284-
- `send_message_streaming()``send_message()` (unified method)
285-
- `SendStreamingMessageRequest``SendMessageRequest`
286-
- `MessageSendParams` wrapper is gone; `message` is a field directly on `SendMessageRequest`
287-
- Each `StreamResponse` has a `payload` which is one of: `'task'`, `'message'`, `'status_update'`, `'artifact_update'`. Use `HasField()` to check which field is set.
288-
- Agent outputs should now be published as **Artifacts**, not status message text
282+
The key change in `BaseClient` is the return type of `send_message()`: it **now returns `AsyncIterator[StreamResponse]`** (v0.3 returned `AsyncIterator[ClientEvent | Message]`).
289283

290-
**Before (v0.3):**
291284
```python
292-
from a2a.types import (
293-
Message, MessageSendParams, Part, Role, SendStreamingMessageRequest,
294-
TextPart,
295-
)
285+
from a2a.types import Message, Part, Role, SendMessageRequest
296286
from uuid import uuid4
297287

298-
message_params = MessageSendParams(
288+
request = SendMessageRequest(
299289
message=Message(
300-
role=Role.user,
301-
parts=[Part(TextPart(text=user_input))],
290+
role=Role.ROLE_USER,
291+
parts=[Part(text=user_input)],
302292
message_id=uuid4().hex,
303-
task_id=uuid4().hex,
304293
)
305294
)
306-
request = SendStreamingMessageRequest(id=uuid4().hex, params=message_params)
307-
308-
response = client.send_message_streaming(request)
309-
310-
```
311-
312-
**After (v1.0):**
313-
```python
314-
from a2a.helpers import get_artifact_text
315-
from a2a.types import (
316-
Message, Part, Role, SendMessageRequest,
317-
)
318-
from uuid import uuid4
319-
320-
parts = [Part(text=user_input)]
321-
message = Message(
322-
role=Role.ROLE_USER,
323-
parts=parts,
324-
message_id=uuid4().hex,
325-
task_id=uuid4().hex,
326-
)
327-
request = SendMessageRequest(message=message)
328295

329296
async for chunk in client.send_message(request):
330297
if chunk.HasField('artifact_update'):
331-
print(get_artifact_text(chunk.artifact_update.artifact))
298+
...
332299
elif chunk.HasField('status_update'):
333-
print(chunk.status_update.status.state)
300+
...
301+
elif chunk.HasField('task'):
302+
...
303+
elif chunk.HasField('message'):
304+
...
334305
```
335306

336-
> **Example**: [`helloworld/test_client.py` in PR #474](https://github.com/a2aproject/a2a-samples/pull/474/files#diff-f62c07d3b00364a3100b7effb3e2a1cca0624277d3e40da1bdb07bb46b6a8cef)
307+
Each `StreamResponse` yields exactly one of: `task`, `message`, `status_update`, or `artifact_update`. Use `HasField()` to check which field is set.
308+
309+
> **Note**: The legacy `A2AClient` class has been removed. Use `create_client()` as shown in [section 5](#5-client-creating-a-client). **Example**: [`helloworld/test_client.py` in PR #474](https://github.com/a2aproject/a2a-samples/pull/474/files#diff-f62c07d3b00364a3100b7effb3e2a1cca0624277d3e40da1bdb07bb46b6a8cef)
337310
338311
---
339312

0 commit comments

Comments
 (0)