Skip to content

Commit b1143fa

Browse files
committed
add the before example to ## 7. Client: Send Message
1 parent 68b7dea commit b1143fa

1 file changed

Lines changed: 27 additions & 29 deletions

File tree

docs/migrations/v1_0/README.md

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Migration Guide: v0.3 → v1.0
22

3-
This guide covers the breaking changes introduced in `a2a-sdk` v1.0 and explains how to update your code. The changes reflect updates to the A2A protocol specification — see the [A2A protocol What's new in v1.0](https://a2a-protocol.org/latest/whats-new-v1/).
3+
This guide covers the breaking changes introduced in `a2a-sdk` v1.0 and explains how to update your code. The changes reflect updates to the A2A protocol specification: [What's new in v1.0](https://a2a-protocol.org/latest/whats-new-v1/).
44

55
> **Related guides**: If you use the database persistence layer, also see the [Database Migration Guide](database/).
66
@@ -264,20 +264,21 @@ create_rest_routes(request_handler, enable_v0_3_compat=True)
264264

265265
## 6. Client: Creating a Client
266266

267-
The `A2AClient` class has been removed. Use the new `create_client()` factory function.
267+
New `create_client()` `ClientFactory` function that creates a client for the agent.
268268

269-
### Simple usage: `create_client()`
269+
> **Note**: The legacy `A2AClient` class has been removed.
270270
271271
**Before (v0.3):**
272272
```python
273-
import httpx
274-
from a2a.client import A2AClient, A2ACardResolver
275-
276-
async with httpx.AsyncClient() as httpx_client:
277-
resolver = A2ACardResolver(httpx_client, base_url)
278-
agent_card = await resolver.get_agent_card()
279-
client = A2AClient(httpx_client, agent_card=agent_card)
280-
# use client...
273+
from a2a.client import ClientFactory
274+
275+
# From URL
276+
factory = ClientFactory()
277+
client = factory.create_client('http://localhost:9999/')
278+
279+
# From an already-resolved AgentCard
280+
factory = ClientFactory()
281+
client = factory.create_client(agent_card)
281282
```
282283

283284
**After (v1.0):**
@@ -286,13 +287,9 @@ from a2a.client import create_client
286287

287288
# From URL — resolves the agent card automatically
288289
client = await create_client('http://localhost:9999/')
289-
async with client:
290-
# use client...
291290

292291
# From an already-resolved AgentCard
293292
client = await create_client(agent_card)
294-
async with client:
295-
# use client...
296293
```
297294

298295

@@ -302,20 +299,24 @@ async with client:
302299

303300
## 7. Client: Send Message
304301

305-
The key change in `BaseClient` is the return type of `send_message()`: it **now returns `AsyncIterator[StreamResponse]`** (v0.3 returned `AsyncIterator[ClientEvent | Message]`).
302+
The `BaseClient.send_message()` return type is standardised from `AsyncIterator[ClientEvent | Message]` to `AsyncIterator[StreamResponse]`.
306303

307-
```python
308-
from a2a.types import Message, Part, Role, SendMessageRequest
309-
from uuid import uuid4
304+
Each `StreamResponse` yields exactly one of: `task`, `message`, `status_update`, or `artifact_update`. Use `HasField()` to check which field is set.
310305

311-
request = SendMessageRequest(
312-
message=Message(
313-
role=Role.ROLE_USER,
314-
parts=[Part(text=user_input)],
315-
message_id=uuid4().hex,
316-
)
317-
)
318306

307+
**Before (v0.3):**
308+
```python
309+
async for event, message in client.send_message(request):
310+
if isinstance(event, Task):
311+
...
312+
if isinstance(event, UpdateEvent):
313+
...
314+
if message:
315+
...
316+
```
317+
318+
**After (v1.0):**
319+
```python
319320
async for chunk in client.send_message(request):
320321
if chunk.HasField('artifact_update'):
321322
...
@@ -327,9 +328,6 @@ async for chunk in client.send_message(request):
327328
...
328329
```
329330

330-
Each `StreamResponse` yields exactly one of: `task`, `message`, `status_update`, or `artifact_update`. Use `HasField()` to check which field is set.
331-
332-
> **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)
333331

334332
---
335333

0 commit comments

Comments
 (0)