Compare commits

..

4 Commits

Author SHA1 Message Date
Iva Sokolaj
ae6a562d5d
docs: rename "Stream Message" to "Send Streaming Message" and replace legacy method names (#1784)
## Summary
Standardizes the operation names used throughout the spec and Python
tutorials so they match the canonical A2A operation names (`Send
Message` / `Send Streaming Message`) instead of the older JSON-RPC-style
identifiers (`message/send`, `message/stream`) or the inconsistent short
form `Stream Message`.
## Changes
- **`docs/specification.md`**
  - Architecture diagram: `Stream Message` → `Send Streaming Message`.
  - Section 3.1.3 (Get Task): `message/send` → `Send Message`.
  - Event delivery section: `Stream Message` → `Send Streaming Message`.
- Multi-protocol functionality table: `Stream message` → `Send Streaming
Message`.
- **`docs/tutorials/python/4-agent-executor.md`**: `message/send` /
`message/stream` → `Send Message` / `Send Streaming Message`.
- **`docs/tutorials/python/6-interact-with-server.md`**: same rename in
the `test_client.py` description.
- **`docs/tutorials/python/7-streaming-and-multiturn.md`**:
`message/send` → `Send Message` in the `CurrencyAgentExecutor`
walkthrough.
## Why
The docs previously mixed three different names for the same operations
(`message/stream`, `Stream Message`, `SendStreamingMessage`), which was
confusing for readers cross-referencing the spec, tutorials, and SDK.
This change picks one human-readable form per operation and uses it
consistently in prose, while leaving the code-level identifiers
(`SendMessage`, `SendStreamingMessage`, `POST /message:stream`, etc.)
untouched in the protocol-binding tables.
2026-04-23 13:54:31 +02:00
Iva Sokolaj
434d1fecbb
docs: use 127.0.0.1 in tutorial as in the referenced sample (#1783)
## Description
Follow-up cleanup to the Python helloworld tutorial to use the address
that the samples actually bind to.
## Changes
- **Host address**: Update tutorial references from
`http://localhost:9999/` to `http://127.0.0.1:9999/` so the docs match
the URL printed by the helloworld sample's Agent Card.
- Updated in `docs/tutorials/python/3-agent-skills-and-card.md` and
`docs/tutorials/python/6-interact-with-server.md`.
2026-04-23 12:27:17 +02:00
Iva Sokolaj
c5104cec72
docs: update Python helloworld tutorial for a2a-sdk v1.0 (#1775)
# Description
Update the Python tutorial to be compliant with the newly released A2A
SDK v1.0.

`Helloworld sample` referenced in the Python tutorial was updated to use
the new `v1.0.1`: [PR
527](https://github.com/a2aproject/a2a-samples/pull/527)
2026-04-23 11:23:52 +02:00
madankumarpichamuthu
7ff1004159
fix(spec): prefer application/a2a+json in HTTP binding (#1753)
## Summary
- Updates HTTP+JSON/REST binding guidance to state that
`application/a2a+json` SHOULD be used for request/response payloads.
- Aligns HTTP A2A examples in the spec to use `Content-Type:
application/a2a+json`.
- Keeps JSON-RPC-specific `/rpc` example on `application/json` to avoid
changing JSON-RPC semantics.

## Why
Issue #1748 identified inconsistent guidance: Section 11.1 said
`application/json`, while many HTTP examples and the registered A2A
media type (`application/a2a+json`) already pointed to A2A-specific
media typing.

This change resolves that inconsistency and improves interoperability
clarity for HTTP+JSON implementations.

Fixes #1748

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2026-04-21 09:53:57 -07:00
8 changed files with 133 additions and 71 deletions

View File

@ -354,6 +354,7 @@ taskstate
taskstatus
textpart
threadsafe
tiangolo
toctree
tok
tolgaki

View File

@ -53,7 +53,7 @@ graph TB
subgraph L2 ["A2A Operations"]
direction LR
G[Send Message] ~~~ H[Stream Message] ~~~ I[Get Task] ~~~ J[List Tasks] ~~~ K[Cancel Task] ~~~ L[Get Agent Card]
G[Send Message] ~~~ H[Send Streaming Message] ~~~ I[Get Task] ~~~ J[List Tasks] ~~~ K[Cancel Task] ~~~ L[Get Agent Card]
end
subgraph L3 ["Protocol Bindings"]
@ -213,7 +213,7 @@ The agent MAY return a `Task` for complex processing with status/artifact update
#### 3.1.3. Get Task
Retrieves the current state (including status, artifacts, and optionally history) of a previously initiated task. This is typically used for polling the status of a task initiated with message/send, or for fetching the final state of a task after being notified via a push notification or after a stream has ended.
Retrieves the current state (including status, artifacts, and optionally history) of a previously initiated task. This is typically used for polling the status of a task initiated with Send Message, or for fetching the final state of a task after being notified via a push notification or after a stream has ended.
**Inputs:**
@ -659,7 +659,7 @@ The A2A protocol provides three complementary mechanisms for clients to receive
**Streaming:**
- Real-time delivery of events as they occur
- Operations: Stream Message ([Section 3.1.2](#312-send-streaming-message)) and Subscribe to Task ([Section 3.1.6](#316-subscribe-to-task))
- Operations: Send Streaming Message ([Section 3.1.2](#312-send-streaming-message)) and Subscribe to Task ([Section 3.1.6](#316-subscribe-to-task))
- Low latency, efficient for frequent updates
- Requires persistent connection support
- Best for: Interactive applications, real-time dashboards, live progress monitoring
@ -848,7 +848,7 @@ When a task update occurs, the agent sends an HTTP POST request to the configure
```http
POST {webhook_url}
Authorization: {authentication_scheme} {credentials}
Content-Type: application/json
Content-Type: application/a2a+json
{
/* StreamResponse object - one of: */
@ -1055,7 +1055,7 @@ Clients indicate their desire to opt into the use of specific extensions through
```http
POST /message:send HTTP/1.1
Host: agent.example.com
Content-Type: application/json
Content-Type: application/a2a+json
Authorization: Bearer token
A2A-Extensions: https://example.com/extensions/geolocation/v1,https://standards.org/extensions/citations/v1
@ -1162,7 +1162,7 @@ When an agent supports multiple protocols, all supported protocols **MUST**:
| Functionality | JSON-RPC Method | gRPC Method | REST Endpoint |
| :------------------------------ | :--------------------------------- | :--------------------------------- | :------------------------------------------------------ |
| Send message | `SendMessage` | `SendMessage` | `POST /message:send` |
| Stream message | `SendStreamingMessage` | `SendStreamingMessage` | `POST /message:stream` |
| Send streaming message | `SendStreamingMessage` | `SendStreamingMessage` | `POST /message:stream` |
| Get task | `GetTask` | `GetTask` | `GET /tasks/{id}` |
| List tasks | `ListTasks` | `ListTasks` | `GET /tasks` |
| Cancel task | `CancelTask` | `CancelTask` | `POST /tasks/{id}:cancel` |
@ -1177,17 +1177,17 @@ When an agent supports multiple protocols, all supported protocols **MUST**:
All A2A-specific errors defined in [Section 3.3.2](#332-error-handling) **MUST** be mapped to binding-specific error representations. The following table provides the canonical mappings for each standard protocol binding:
| A2A Error Type | JSON-RPC Code | gRPC Status | HTTP Status |
| :------------------------------------ | :------------ | :-------------------- | :--------------------------- |
| `TaskNotFoundError` | `-32001` | `NOT_FOUND` | `404 Not Found` |
| `TaskNotCancelableError` | `-32002` | `FAILED_PRECONDITION` | `400 Bad Request` |
| `PushNotificationNotSupportedError` | `-32003` | `FAILED_PRECONDITION` | `400 Bad Request` |
| `UnsupportedOperationError` | `-32004` | `FAILED_PRECONDITION` | `400 Bad Request` |
| `ContentTypeNotSupportedError` | `-32005` | `INVALID_ARGUMENT` | `400 Bad Request` |
| `InvalidAgentResponseError` | `-32006` | `INTERNAL` | `500 Internal Server Error` |
| `ExtendedAgentCardNotConfiguredError` | `-32007` | `FAILED_PRECONDITION` | `400 Bad Request` |
| `ExtensionSupportRequiredError` | `-32008` | `FAILED_PRECONDITION` | `400 Bad Request` |
| `VersionNotSupportedError` | `-32009` | `FAILED_PRECONDITION` | `400 Bad Request` |
| A2A Error Type | JSON-RPC Code | gRPC Status | HTTP Status |
| :------------------------------------ | :------------ | :-------------------- | :-------------------------- |
| `TaskNotFoundError` | `-32001` | `NOT_FOUND` | `404 Not Found` |
| `TaskNotCancelableError` | `-32002` | `FAILED_PRECONDITION` | `400 Bad Request` |
| `PushNotificationNotSupportedError` | `-32003` | `FAILED_PRECONDITION` | `400 Bad Request` |
| `UnsupportedOperationError` | `-32004` | `FAILED_PRECONDITION` | `400 Bad Request` |
| `ContentTypeNotSupportedError` | `-32005` | `INVALID_ARGUMENT` | `400 Bad Request` |
| `InvalidAgentResponseError` | `-32006` | `INTERNAL` | `500 Internal Server Error` |
| `ExtendedAgentCardNotConfiguredError` | `-32007` | `FAILED_PRECONDITION` | `400 Bad Request` |
| `ExtensionSupportRequiredError` | `-32008` | `FAILED_PRECONDITION` | `400 Bad Request` |
| `VersionNotSupportedError` | `-32009` | `FAILED_PRECONDITION` | `400 Bad Request` |
**Custom Binding Requirements:**
@ -2748,7 +2748,7 @@ The HTTP+JSON protocol binding provides a RESTful interface using standard HTTP
### 11.1. Protocol Requirements
- **Protocol:** HTTP(S) with JSON payloads
- **Content-Type:** `application/json` for requests and responses
- **Content-Type:** application/a2a+json **SHOULD** be used for requests and responses
- **Methods:** Standard HTTP verbs (GET, POST, PUT, DELETE)
- **URL Patterns:** RESTful resource-based URLs
- **Streaming:** Server-Sent Events for real-time updates
@ -2768,7 +2768,7 @@ A2A service parameters defined in [Section 3.2.6](#326-service-parameters) **MUS
```http
POST /message:send HTTP/1.1
Host: agent.example.com
Content-Type: application/json
Content-Type: application/a2a+json
Authorization: Bearer token
A2A-Version: 0.3
A2A-Extensions: https://example.com/extensions/geolocation/v1,https://standards.org/extensions/citations/v1
@ -2814,7 +2814,7 @@ All requests and responses use JSON objects structurally equivalent to the Proto
```http
POST /message:send
Content-Type: application/json
Content-Type: application/a2a+json
{
"message": {
@ -2834,7 +2834,7 @@ Content-Type: application/json
```http
HTTP/1.1 200 OK
Content-Type: application/json
Content-Type: application/a2a+json
{
"task": {
@ -2920,7 +2920,7 @@ For the complete mapping of A2A error types to HTTP status codes, see [Section 5
```http
HTTP/1.1 404 Not Found
Content-Type: application/json
Content-Type: application/a2a+json
{
"error": {
@ -2952,7 +2952,7 @@ REST streaming uses Server-Sent Events with the `data` field containing JSON ser
```http
POST /message:stream
Content-Type: application/json
Content-Type: application/a2a+json
{ /* SendMessageRequest object */ }
```

View File

@ -1,4 +1,4 @@
# 2. Setup Your Environment
# 2. Set Up Your Environment
## Prerequisites
@ -38,7 +38,7 @@ We recommend using a virtual environment for Python projects. The A2A Python SDK
.venv\Scripts\activate
```
2. **Install needed Python dependencies along with the A2A SDK and its dependencies:**
2. **Install the A2A SDK and its required Python dependencies:**
```bash
pip install -r samples/python/requirements.txt

View File

@ -33,7 +33,6 @@ The **Agent Card** is a JSON document that an A2A Server makes available, typica
Key attributes of an `AgentCard` (defined in `a2a.types`):
- `name`, `description`, `version`: Basic identity information.
- `icon_url`: A URL to an icon representing the agent.
- `supported_interfaces`: Ordered list of endpoints and protocols where the A2A service can be reached.
- `capabilities`: Supported A2A features like `streaming` or `extended_agent_card`.
- `default_input_modes` / `default_output_modes`: Default Media Types for the agent.
@ -45,6 +44,4 @@ The `helloworld` example defines its Agent Card like this:
--8<-- "https://raw.githubusercontent.com/a2aproject/a2a-samples/refs/heads/main/samples/python/agents/helloworld/__main__.py:AgentCard"
```
This card tells us the agent is named "Hello World Agent", runs at `http://localhost:9999` using `JSONRPC`, supports text interactions, and has the `hello_world` skill. Its capabilities also indicate support for streaming and an extended authenticated configuration.
Understanding the Agent Card is crucial because it's how a client discovers an agent and learns how to interact with it.
This card tells us the agent is named "Hello World Agent", can be run at `http://127.0.0.1:9999/`, supports text interactions, and has the `hello_world` skill.

View File

@ -41,19 +41,16 @@ Let's look at `agent_executor.py`. It defines `HelloWorldAgentExecutor`.
--8<-- "https://raw.githubusercontent.com/a2aproject/a2a-samples/refs/heads/main/samples/python/agents/helloworld/agent_executor.py:HelloWorldAgentExecutor_execute"
```
When a `message/send` or `message/stream` request comes in (both are handled by `execute` in this simplified executor):
When a `Send Message` or `Send Streaming Message` request comes in (both are handled by `execute` in this simplified executor), the following steps occur:
1. It retrieves the current task from the context or creates a new one, enqueueing it as the first event.
2. It enqueues a `TaskStatusUpdateEvent` with a state of `TASK_STATE_WORKING` to indicate the agent has begun processing.
3. It calls `self.agent.invoke()` to execute the actual business logic (which simply returns "Hello, World!").
4. It enqueues a `TaskArtifactUpdateEvent` containing the result text.
5. Finally, it enqueues a `TaskStatusUpdateEvent` with a state of `TASK_STATE_COMPLETED` to conclude the task.
**Step 1.** The `A2A instance` (server) retrieves the current task from the context. If there is no task in context, then it creates a new task and adds it to the `EventQueue`.
- **`cancel`**:
The Hello World example's `cancel` method simply raises an exception, indicating that cancellation is not supported for this basic agent.
**Step 2.** It enqueues a `TaskStatusUpdateEvent` with a state of `TASK_STATE_WORKING` to indicate the agent has begun processing.
```python { .no-copy }
--8<-- "https://raw.githubusercontent.com/a2aproject/a2a-samples/refs/heads/main/samples/python/agents/helloworld/agent_executor.py:HelloWorldAgentExecutor_cancel"
```
**Step 3.** It calls `self.agent.invoke()` to execute the actual business logic (which simply returns "Hello, World!").
**Step 4.** It enqueues a `TaskArtifactUpdateEvent` containing the result text from the agent.
**Step 5.** Finally, it enqueues a `TaskStatusUpdateEvent` with a state of `TASK_STATE_COMPLETED` to conclude the task.
The `AgentExecutor` acts as the bridge between the A2A protocol (managed by the request handler and server application) and your agent's specific logic. It receives context about the request and uses an event queue to communicate results or updates back.

View File

@ -2,7 +2,9 @@
Now that we have an Agent Card and an Agent Executor, we can set up and start the A2A server.
The A2A Python SDK provides an `A2AStarletteApplication` class that simplifies running an A2A-compliant HTTP server. It uses [Starlette](https://www.starlette.io/) for the web framework and is typically run with an ASGI server like [Uvicorn](https://www.uvicorn.org/).
To set up an A2A server, the Python SDK provides a route factory and helper functions (`create_agent_card_routes`, `create_jsonrpc_routes`, `create_rest_routes`). Use the route factory to create routes for the A2A server's services. These routes can be attached natively to popular frameworks like [Starlette](https://www.starlette.io/) and [FastAPI](https://fastapi.tiangolo.com/), which give you better control over authentication, logging, and other features.
In this tutorial, we will use Starlette with [Uvicorn](https://www.uvicorn.org/).
## Server Setup in Helloworld
@ -16,20 +18,20 @@ Let's break this down:
1. **`DefaultRequestHandler`**:
- The SDK provides `DefaultRequestHandler`. This handler takes your `AgentExecutor` implementation (here, `HelloWorldAgentExecutor`) and a `TaskStore` (here, `InMemoryTaskStore`).
- The SDK provides `DefaultRequestHandler`. This handler takes your `AgentExecutor` implementation (`HelloWorldAgentExecutor`), a `TaskStore` (`InMemoryTaskStore`), and the public and extended `AgentCard` objects.
- It routes incoming A2A RPC calls to the appropriate methods on your executor (like `execute` or `cancel`).
- The `TaskStore` is used by the `DefaultRequestHandler` to manage the lifecycle of tasks, especially for stateful interactions, streaming, and resubscription. Even if your agent executor is simple, the handler needs a task store.
- `agent_card` is passed to the handler so it can verify the agent's declared capabilities when processing incoming requests. For example, it checks whether streaming or push notifications are supported before handling those request types.
- `extended_agent_card` is passed so the handler can serve it via the `GetExtendedAgentCard` RPC method to authenticated clients.
2. **`A2AStarletteApplication`**:
2. **`create_agent_card_routes` and `create_jsonrpc_routes`**:
- The `A2AStarletteApplication` class is instantiated with the `agent_card`, `request_handler` (referred to as `http_handler` in its constructor), and an optional `extended_agent_card`.
- The `agent_card` is exposed at the `/.well-known/agent-card.json` endpoint for public discovery.
- The `request_handler` processes all incoming A2A method calls by interacting with your `AgentExecutor`.
- The `extended_agent_card` provides additional capabilities and skills for authenticated users and is exposed via the `GetExtendedAgentCard` RPC method.
- `create_agent_card_routes(public_agent_card)` returns Starlette routes that expose the Agent Card at the `/.well-known/agent-card.json` endpoint for public discovery.
- `create_jsonrpc_routes(request_handler, '/')` returns Starlette routes that handle all incoming A2A JSON-RPC method calls by delegating to the `request_handler`.
- These route lists are combined and passed to a standard `Starlette` application.
3. **`uvicorn.run(server_app_builder.build(), ...)`**:
- The `A2AStarletteApplication` has a `build()` method that constructs the actual Starlette application.
- This application is then run using `uvicorn.run()`, making your agent accessible over HTTP.
3. **`uvicorn.run(app, ...)`**:
- The constructed `Starlette` app is run using `uvicorn.run()`, making your agent accessible over HTTP.
- `host='127.0.0.1'` makes the server accessible only from your local machine.
- `port=9999` specifies the port to listen on. This matches the endpoints defined in the `AgentCard`'s `supported_interfaces`.

View File

@ -1,18 +1,18 @@
# 6. Interacting with the Server
With the Helloworld A2A server running, let's send some requests to it. The SDK includes a client (`A2AClient`) that simplifies these interactions.
With the Helloworld A2A server running, let's send some requests to it.
## The Helloworld Test Client
The `test_client.py` script demonstrates how to:
1. Fetch the Agent Card from the server.
2. Create an `A2AClient` instance.
3. Send both non-streaming (`message/send`) and streaming (`message/stream`) requests.
2. Create a client using `create_client`.
3. Send both `Send Message` and `Send Streaming Message` requests.
Open a **new terminal window**, activate your virtual environment, and navigate to the `a2a-samples` directory.
Activate virtual environment (Be sure to do this in the same directory where you created the virtual environment):
Activate the virtual environment (be sure to do this in the same directory where you created it):
=== "Mac/Linux"
@ -43,7 +43,7 @@ Let's look at key parts of `test_client.py`:
--8<-- "https://raw.githubusercontent.com/a2aproject/a2a-samples/refs/heads/main/samples/python/agents/helloworld/test_client.py:A2ACardResolver"
```
The `A2ACardResolver` class is a convenience. It first fetches the `AgentCard` from the server's `/.well-known/agent-card.json` endpoint (based on the provided base URL) which is then used to initialize the client.
The `A2ACardResolver` class is a convenience. When `get_agent_card()` is called, it fetches the `AgentCard` from the server's `/.well-known/agent-card.json` endpoint (based on the provided base URL), which is then used to initialize the client.
2. **Initializing the Client & Sending a Non-Streaming Message**:
@ -51,10 +51,9 @@ Let's look at key parts of `test_client.py`:
--8<-- "https://raw.githubusercontent.com/a2aproject/a2a-samples/refs/heads/main/samples/python/agents/helloworld/test_client.py:message_send"
```
- A `ClientFactory` creates a non-streaming client based on the fetched card.
- We construct a `Message` object using `Role.ROLE_USER` and `Part` for the content.
- This is wrapped in a `SendMessageRequest`.
- The client's `send_message` method returns an async generator that yields a sequence of `Task` events from the agent.
- The `create_client` function creates a `Client` based on the information provided by the `AgentCard` and a `ClientConfig`.
- We construct a `Message` using the `new_text_message` helper (passing `role=Role.ROLE_USER`), then wrap it in a `SendMessageRequest`.
- The client's `send_message` method returns an async iterator that yields a single final `Task` or `Message` response from the agent. In this example, it is a `Task`.
3. **Initializing the Client & Sending a Streaming Message**:
@ -62,20 +61,53 @@ Let's look at key parts of `test_client.py`:
--8<-- "https://raw.githubusercontent.com/a2aproject/a2a-samples/refs/heads/main/samples/python/agents/helloworld/test_client.py:message_stream"
```
- A new streaming client is created via `ClientFactory` configured with `streaming=True`.
- We again call `send_message` (which now handles both streaming and non-streaming under the same method name, based on the `ClientConfig` and agent `capabilities`).
- The response dynamically yields `Task` events as they are streamed over the network.
- A separate streaming client is created via `create_client` with `streaming=True` in its `ClientConfig`.
- We again call `send_message`, which now streams events: each iteration of the loop prints a discrete chunk as it arrives over the network.
- Call `await streaming_client.close()` after the loop to release the underlying HTTP connection.
## Expected Output
When you run `test_client.py`, you'll see in protobuf text format outputs for:
When you run `test_client.py`, you'll see output for:
- The non-streaming response (a single final `task` log detailing the history, status, and the generated artifact containing the "Hello, World!" text).
- The streaming response (multiple discrete events including the initial `task`, a `status_update`, and a final `artifact_update` containing the "Hello, World!" text).
- The public agent card, displayed in a formatted summary.
- The non-streaming response: a single `task` in protobuf text format containing the completed status, the generated artifact with "Hello, World!", and the agent's intermediate status message in history.
- The streaming response: four chunks — the initial `task`, a `status_update` for WORKING, an `artifact_update` with the result, and a final `status_update` for COMPLETED.
- The extended agent card, displayed in a formatted summary (with an additional `super_hello_world` skill).
The `id` fields in the output will vary with each run.
```console { .no-copy }
AgentCard
--- General ---
Name : Hello World Agent
Description : Just a hello world agent
Version : 0.0.1
--- Interfaces ---
[0] http://127.0.0.1:9999 (JSONRPC)
--- Capabilities ---
Streaming : True
Push notifications : False
Extended agent card : True
--- I/O Modes ---
Input : text/plain
Output : text/plain
--- Skills ---
----------------------------------------------------
ID : hello_world
Name : Returns hello world
Description : just returns hello world
Tags : hello world
Example : hi
Example : hello world
--- Non-Streaming Call ---
Non-streaming Client initialized.
Response:
// Non-streaming response
task {
id: "xxxxxxxx"
@ -163,10 +195,43 @@ status_update {
state: TASK_STATE_COMPLETED
}
}
AgentCard
--- General ---
Name : Hello World Agent - Extended Edition
Description : The full-featured hello world agent for authenticated users.
Version : 0.0.2
--- Interfaces ---
[0] http://127.0.0.1:9999 (JSONRPC)
--- Capabilities ---
Streaming : True
Push notifications : False
Extended agent card : True
--- I/O Modes ---
Input : text/plain
Output : text/plain
--- Skills ---
----------------------------------------------------
ID : hello_world
Name : Returns hello world
Description : just returns hello world
Tags : hello world
Example : hi
Example : hello world
----------------------------------------------------
ID : super_hello_world
Name : Returns a SUPER Hello World
Description : A more enthusiastic greeting, only for authenticated users.
Tags : hello world, super, extended
Example : super hi
Example : give me a super hello
```
_(Actual IDs like `xxxxxxxx`, `yyyyyyyy`, `zzzzzzzz`, `vvvvvvvv`, `wwwwwwww` will be different UUIDs/request IDs)_
_(Actual IDs like `xxxxxxxx`, `yyyyyyyy`, `zzzzzzzz`, `wwwwwwww`, and `vvvvvvvv` will be different UUIDs in each run.)_
This confirms your server is correctly handling basic A2A interactions with the updated SDK structure!
This confirms your server is correctly handling basic A2A interactions with the updated SDK structure.
Now you can shut down the server by typing Ctrl+C in the terminal window where `__main__.py` is running.
You can now shut down the server by pressing Ctrl+C in the terminal window where `__main__.py` is running.

View File

@ -6,7 +6,7 @@ This example features a "Currency Agent" that uses the Gemini model via LangChai
## Setting up the LangGraph Example
1. Create a [Gemini API Key](https://ai.google.dev/gemini-api/docs/api-key), if you don't already have one.
1. Create a [Gemini API Key](https://ai.google.dev/gemini-api/docs/api-key) if you don't already have one.
2. **Environment Variable:**
@ -64,14 +64,14 @@ The `langgraph` example showcases several important A2A concepts:
```
- The `CurrencyAgentExecutor` (in `samples/langgraph/agent_executor.py`), when its `execute` method is called by the `DefaultRequestHandler`, interacts with the `RequestContext` which contains the current task (if any).
- For `message/send`, the `DefaultRequestHandler` uses the `TaskStore` to persist and retrieve task state across interactions. The response to `message/send` will be a full `Task` object if the agent's execution flow involves multiple steps or results in a persistent task.
- For `Send Message`, the `DefaultRequestHandler` uses the `TaskStore` to persist and retrieve task state across interactions. The response to `Send Message` will be a full `Task` object if the agent's execution flow involves multiple steps or results in a persistent task.
- The `test_client.py`'s `run_single_turn_test` demonstrates getting a `Task` object back and then querying it using `get_task`.
3. **Streaming with `TaskStatusUpdateEvent` and `TaskArtifactUpdateEvent`**:
- The `execute` method in `CurrencyAgentExecutor` is responsible for handling both non-streaming and streaming requests, orchestrated by the `DefaultRequestHandler`.
- As the LangGraph agent processes the request (which might involve calling tools like `get_exchange_rate`), the `CurrencyAgentExecutor` enqueues different types of events onto the `EventQueue`:
- `TaskStatusUpdateEvent`: For intermediate updates (e.g., "Looking up exchange rates...", "Processing the exchange rates..").
- `TaskStatusUpdateEvent`: For intermediate updates (e.g., "Looking up exchange rates...", "Processing the exchange rates...").
- `TaskArtifactUpdateEvent`: When the final answer is ready, it's enqueued as an artifact. The `lastChunk` flag is `True`.
- A final `TaskStatusUpdateEvent` with `state=TaskState.completed` is sent to signify the end of the task, closing the stream.
- The `test_client.py`'s `run_streaming_test` function will print these individual event chunks as they are received from the server.