a2a 0.1.0.pre → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.agent-docs/ROADMAP.md +423 -0
- data/.agent-docs/index.md +124 -0
- data/.agent-docs/llms.txt +318 -0
- data/.agent-docs/specification/json.json +2575 -0
- data/.agent-docs/specification.md +1924 -0
- data/.agent-docs/topics/a2a-and-mcp.md +132 -0
- data/.agent-docs/topics/agent-discovery.md +96 -0
- data/.agent-docs/topics/enterprise-ready.md +139 -0
- data/.agent-docs/topics/extensions.md +260 -0
- data/.agent-docs/topics/key-concepts.md +99 -0
- data/.agent-docs/topics/life-of-a-task.md +255 -0
- data/.agent-docs/topics/streaming-and-async.md +111 -0
- data/.agent-docs/topics/what-is-a2a.md +218 -0
- data/.agent-docs/tutorials/index.md +31 -0
- data/.agent-docs/tutorials/python/1-introduction.md +32 -0
- data/.agent-docs/tutorials/python/2-setup.md +55 -0
- data/.agent-docs/tutorials/python/3-agent-skills-and-card.md +48 -0
- data/.agent-docs/tutorials/python/4-agent-executor.md +57 -0
- data/.agent-docs/tutorials/python/5-start-server.md +55 -0
- data/.agent-docs/tutorials/python/6-interact-with-server.md +95 -0
- data/.agent-docs/tutorials/python/7-streaming-and-multiturn.md +97 -0
- data/.agent-docs/tutorials/python/8-next-steps.md +40 -0
- data/.agent-docs/types.ts +1544 -0
- data/.agent-docs/types_mapping.md +196 -0
- data/.claude/commands/gemfile/update.md +52 -0
- data/.claude/settings.local.json +23 -0
- data/.rubocop.yml +25 -4
- data/.tool-versions +1 -1
- data/CHANGELOG.md +86 -2
- data/CLAUDE.md +98 -0
- data/Guardfile +1 -1
- data/README.md +55 -4
- data/Rakefile +1 -3
- data/WARP.md +115 -0
- data/lib/a2a/extensions/additional_properties.rb +121 -0
- data/lib/a2a/extensions/case_transformation.rb +46 -0
- data/lib/a2a/extensions/json_deserialization.rb +51 -0
- data/lib/a2a/types/agent_capabilities.rb +18 -0
- data/lib/a2a/types/agent_card.rb +71 -0
- data/lib/a2a/types/agent_card_signature.rb +17 -0
- data/lib/a2a/types/agent_extension.rb +19 -0
- data/lib/a2a/types/agent_interface.rb +13 -0
- data/lib/a2a/types/agent_provider.rb +12 -0
- data/lib/a2a/types/agent_skill.rb +34 -0
- data/lib/a2a/types/api_key_security_scheme.rb +15 -0
- data/lib/a2a/types/artifact.rb +24 -0
- data/lib/a2a/types/authenticated_extended_card_not_configured_error.rb +43 -0
- data/lib/a2a/types/authorization_code_oauth_flow.rb +22 -0
- data/lib/a2a/types/cancel_task_request.rb +18 -0
- data/lib/a2a/types/cancel_task_response.rb +12 -0
- data/lib/a2a/types/client_credentials_oauth_flow.rb +16 -0
- data/lib/a2a/types/content_type_not_supported_error.rb +42 -0
- data/lib/a2a/types/data_part.rb +12 -0
- data/lib/a2a/types/delete_task_push_notification_config_params.rb +9 -0
- data/lib/a2a/types/delete_task_push_notification_config_request.rb +18 -0
- data/lib/a2a/types/delete_task_push_notification_config_response.rb +13 -0
- data/lib/a2a/types/error.rb +19 -0
- data/lib/a2a/types/error_codes.rb +32 -0
- data/lib/a2a/types/file_base.rb +12 -0
- data/lib/a2a/types/file_part.rb +13 -0
- data/lib/a2a/types/file_with_bytes.rb +9 -0
- data/lib/a2a/types/file_with_uri.rb +9 -0
- data/lib/a2a/types/get_authenticated_extended_card_request.rb +15 -0
- data/lib/a2a/types/get_authenticated_extended_card_response.rb +13 -0
- data/lib/a2a/types/get_task_push_notification_config_params.rb +9 -0
- data/lib/a2a/types/get_task_push_notification_config_request.rb +21 -0
- data/lib/a2a/types/get_task_push_notification_request.rb +18 -0
- data/lib/a2a/types/get_task_push_notification_response.rb +12 -0
- data/lib/a2a/types/get_task_request.rb +18 -0
- data/lib/a2a/types/get_task_response.rb +12 -0
- data/lib/a2a/types/http_auth_security_scheme.rb +18 -0
- data/lib/a2a/types/implicit_oauth_flow.rb +16 -0
- data/lib/a2a/types/invalid_agent_response_error.rb +41 -0
- data/lib/a2a/types/list_task_push_notification_config_params.rb +8 -0
- data/lib/a2a/types/list_task_push_notification_config_request.rb +18 -0
- data/lib/a2a/types/list_task_push_notification_config_response.rb +13 -0
- data/lib/a2a/types/message.rb +35 -0
- data/lib/a2a/types/message_send_configuration.rb +20 -0
- data/lib/a2a/types/message_send_params.rb +16 -0
- data/lib/a2a/types/mutual_tls_security_scheme.rb +9 -0
- data/lib/a2a/types/oauth2_security_scheme.rb +16 -0
- data/lib/a2a/types/oauth_flows.rb +20 -0
- data/lib/a2a/types/openid_connect_security_scheme.rb +12 -0
- data/lib/a2a/types/part.rb +7 -0
- data/lib/a2a/types/part_base.rb +9 -0
- data/lib/a2a/types/password_oauth_flow.rb +16 -0
- data/lib/a2a/types/protocol_struct.rb +12 -0
- data/lib/a2a/types/push_notification_authentication_info.rb +12 -0
- data/lib/a2a/types/push_notification_config.rb +20 -0
- data/lib/a2a/types/push_notification_not_supported_error.rb +42 -0
- data/lib/a2a/types/request.rb +15 -0
- data/lib/a2a/types/security_scheme.rb +11 -0
- data/lib/a2a/types/security_scheme_base.rb +9 -0
- data/lib/a2a/types/send_message_request.rb +18 -0
- data/lib/a2a/types/send_message_response.rb +13 -0
- data/lib/a2a/types/send_streaming_message_request.rb +18 -0
- data/lib/a2a/types/send_streaming_message_response.rb +15 -0
- data/lib/a2a/types/set_task_push_notification_config_request.rb +18 -0
- data/lib/a2a/types/set_task_push_notification_request.rb +18 -0
- data/lib/a2a/types/set_task_push_notification_response.rb +12 -0
- data/lib/a2a/types/task.rb +29 -0
- data/lib/a2a/types/task_artifact_update_event.rb +29 -0
- data/lib/a2a/types/task_id_params.rb +12 -0
- data/lib/a2a/types/task_not_cancelable_error.rb +42 -0
- data/lib/a2a/types/task_not_found_error.rb +42 -0
- data/lib/a2a/types/task_push_notification_config.rb +12 -0
- data/lib/a2a/types/task_query_params.rb +9 -0
- data/lib/a2a/types/task_resubscription_request.rb +18 -0
- data/lib/a2a/types/task_state.rb +7 -0
- data/lib/a2a/types/task_status.rb +15 -0
- data/lib/a2a/types/task_status_update_event.rb +25 -0
- data/lib/a2a/types/text_part.rb +12 -0
- data/lib/a2a/types/transport_protocol.rb +6 -0
- data/lib/a2a/types/unsupported_operation_error.rb +42 -0
- data/lib/a2a/types.rb +25 -0
- data/lib/a2a/version.rb +1 -1
- data/lib/a2a.rb +30 -1
- metadata +128 -299
@@ -0,0 +1,97 @@
|
|
1
|
+
# 7. Streaming & Multi-Turn Interactions (LangGraph Example)
|
2
|
+
|
3
|
+
The Helloworld example demonstrates the basic mechanics of A2A. For more advanced features like robust streaming, task state management, and multi-turn conversations powered by an LLM, we'll turn to the LangGraph example located in [`a2a-samples/samples/python/agents/langgraph/`](https://github.com/a2aproject/a2a-samples/tree/main/samples/python/agents/langgraph).
|
4
|
+
|
5
|
+
This example features a "Currency Agent" that uses the Gemini model via LangChain and LangGraph to answer currency conversion questions.
|
6
|
+
|
7
|
+
## Setting up the LangGraph Example
|
8
|
+
|
9
|
+
1. Create a [Gemini API Key](https://ai.google.dev/gemini-api/docs/api-key), if you don't already have one.
|
10
|
+
|
11
|
+
2. **Environment Variable:**
|
12
|
+
|
13
|
+
Create a `.env` file in the `a2a-samples/samples/python/agents/langgraph/` directory:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
echo "GOOGLE_API_KEY=YOUR_API_KEY_HERE" > .env
|
17
|
+
```
|
18
|
+
|
19
|
+
Replace `YOUR_API_KEY_HERE` with your actual Gemini API key.
|
20
|
+
|
21
|
+
3. **Install Dependencies (if not already covered):**
|
22
|
+
|
23
|
+
The `langgraph` example has its own `pyproject.toml` which includes dependencies like `langchain-google-genai` and `langgraph`. When you installed the SDK from the `a2a-samples` root using `pip install -e .[dev]`, this should have also installed the dependencies for the workspace examples, including `langgraph-example`. If you encounter import errors, ensure your primary SDK installation from the root directory was successful.
|
24
|
+
|
25
|
+
## Running the LangGraph Server
|
26
|
+
|
27
|
+
Navigate to the `a2a-samples/samples/python/agents/langgraph/app` directory in your terminal and ensure your virtual environment (from the SDK root) is activated.
|
28
|
+
|
29
|
+
Start the LangGraph agent server:
|
30
|
+
|
31
|
+
```bash
|
32
|
+
python __main__.py
|
33
|
+
```
|
34
|
+
|
35
|
+
This will start the server, usually on `http://localhost:10000`.
|
36
|
+
|
37
|
+
## Interacting with the LangGraph Agent
|
38
|
+
|
39
|
+
Open a **new terminal window**, activate your virtual environment, and navigate to `a2a-samples/samples/python/agents/langgraph/app`.
|
40
|
+
|
41
|
+
Run its test client:
|
42
|
+
|
43
|
+
```bash
|
44
|
+
python test_client.py
|
45
|
+
```
|
46
|
+
|
47
|
+
Now, you can shut down the server by typing Ctrl+C in the terminal window where `__main__.py` is running.
|
48
|
+
|
49
|
+
## Key Features Demonstrated
|
50
|
+
|
51
|
+
The `langgraph` example showcases several important A2A concepts:
|
52
|
+
|
53
|
+
1. **LLM Integration**:
|
54
|
+
|
55
|
+
- `agent.py` defines `CurrencyAgent`. It uses `ChatGoogleGenerativeAI` and LangGraph's `create_react_agent` to process user queries.
|
56
|
+
- This demonstrates how a real LLM can power the agent's logic.
|
57
|
+
|
58
|
+
2. **Task State Management**:
|
59
|
+
|
60
|
+
- `samples/langgraph/__main__.py` initializes a `DefaultRequestHandler` with an `InMemoryTaskStore`.
|
61
|
+
|
62
|
+
```python { .no-copy }
|
63
|
+
--8<-- "https://raw.githubusercontent.com/a2aproject/a2a-samples/refs/heads/main/samples/python/agents/langgraph/app/__main__.py:DefaultRequestHandler"
|
64
|
+
```
|
65
|
+
|
66
|
+
- 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).
|
67
|
+
- 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.
|
68
|
+
- The `test_client.py`'s `run_single_turn_test` demonstrates getting a `Task` object back and then querying it using `get_task`.
|
69
|
+
|
70
|
+
3. **Streaming with `TaskStatusUpdateEvent` and `TaskArtifactUpdateEvent`**:
|
71
|
+
|
72
|
+
- The `execute` method in `CurrencyAgentExecutor` is responsible for handling both non-streaming and streaming requests, orchestrated by the `DefaultRequestHandler`.
|
73
|
+
- 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`:
|
74
|
+
- `TaskStatusUpdateEvent`: For intermediate updates (e.g., "Looking up exchange rates...", "Processing the exchange rates.."). The `final` flag on these events is `False`.
|
75
|
+
- `TaskArtifactUpdateEvent`: When the final answer is ready, it's enqueued as an artifact. The `lastChunk` flag is `True`.
|
76
|
+
- A final `TaskStatusUpdateEvent` with `state=TaskState.completed` and `final=True` is sent to signify the end of the task for streaming.
|
77
|
+
- The `test_client.py`'s `run_streaming_test` function will print these individual event chunks as they are received from the server.
|
78
|
+
|
79
|
+
4. **Multi-Turn Conversation (`TaskState.input_required`)**:
|
80
|
+
|
81
|
+
- The `CurrencyAgent` can ask for clarification if a query is ambiguous (e.g., user asks "how much is 100 USD?").
|
82
|
+
- When this happens, the `CurrencyAgentExecutor` will enqueue a `TaskStatusUpdateEvent` where `status.state` is `TaskState.input_required` and `status.message` contains the agent's question (e.g., "To which currency would you like to convert?"). This event will have `final=True` for the current interaction stream.
|
83
|
+
- The `test_client.py`'s `run_multi_turn_test` function demonstrates this:
|
84
|
+
- It sends an initial ambiguous query.
|
85
|
+
- The agent responds (via the `DefaultRequestHandler` processing the enqueued events) with a `Task` whose status is `input_required`.
|
86
|
+
- The client then sends a second message, including the `taskId` and `contextId` from the first turn's `Task` response, to provide the missing information ("in GBP"). This continues the same task.
|
87
|
+
|
88
|
+
## Exploring the Code
|
89
|
+
|
90
|
+
Take some time to look through these files:
|
91
|
+
|
92
|
+
- `__main__.py`: Server setup using `A2AStarletteApplication` and `DefaultRequestHandler`. Note the `AgentCard` definition includes `capabilities.streaming=True`.
|
93
|
+
- `agent.py`: The `CurrencyAgent` with LangGraph, LLM model, and tool definitions.
|
94
|
+
- `agent_executor.py`: The `CurrencyAgentExecutor` implementing the `execute` (and `cancel`) method. It uses the `RequestContext` to understand the ongoing task and the `EventQueue` to send back various events (`TaskStatusUpdateEvent`, `TaskArtifactUpdateEvent`, new `Task` object implicitly via the first event if no task exists).
|
95
|
+
- `test_client.py`: Demonstrates various interaction patterns, including retrieving task IDs and using them for multi-turn conversations.
|
96
|
+
|
97
|
+
This example provides a much richer illustration of how A2A facilitates complex, stateful, and asynchronous interactions between agents.
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Next Steps
|
2
|
+
|
3
|
+
Congratulations on completing the A2A Python SDK Tutorial! You've learned how to:
|
4
|
+
|
5
|
+
- Set up your environment for A2A development.
|
6
|
+
- Define Agent Skills and Agent Cards using the SDK's types.
|
7
|
+
- Implement a basic HelloWorld A2A server and client.
|
8
|
+
- Understand and implement streaming capabilities.
|
9
|
+
- Integrate a more complex agent using LangGraph, demonstrating task state management and tool use.
|
10
|
+
|
11
|
+
You now have a solid foundation for building and integrating your own A2A-compliant agents.
|
12
|
+
|
13
|
+
## Where to Go From Here?
|
14
|
+
|
15
|
+
Here are some ideas and resources to continue your A2A journey:
|
16
|
+
|
17
|
+
- **Explore Other Examples:**
|
18
|
+
- Check out the other examples in the [a2a-samples GitHub repository](https://github.com/a2aproject/a2a-samples/tree/main/samples) for more complex agent integrations and features.
|
19
|
+
- **Deepen Your Protocol Understanding:**
|
20
|
+
- 📚 Read the complete [A2A Protocol Documentation site](https://a2a-protocol.org) for a comprehensive overview.
|
21
|
+
- 📝 Review the detailed [A2A Protocol Specification](../../specification.md) to understand the nuances of all data structures and RPC methods.
|
22
|
+
- **Review Key A2A Topics:**
|
23
|
+
- [A2A and MCP](../../topics/a2a-and-mcp.md): Understand how A2A complements the Model Context Protocol for tool usage.
|
24
|
+
- [Enterprise-Ready Features](../../topics/enterprise-ready.md): Learn about security, observability, and other enterprise considerations.
|
25
|
+
- [Streaming & Asynchronous Operations](../../topics/streaming-and-async.md): Get more details on SSE and push notifications.
|
26
|
+
- [Agent Discovery](../../topics/agent-discovery.md): Explore different ways agents can find each other.
|
27
|
+
- **Build Your Own Agent:**
|
28
|
+
- Try creating a new A2A agent using your favorite Python agent framework (like LangChain, CrewAI, AutoGen, Semantic Kernel, or a custom solution).
|
29
|
+
- Implement the `a2a.server.AgentExecutor` interface to bridge your agent's logic with the A2A protocol.
|
30
|
+
- Think about what unique skills your agent could offer and how its Agent Card would represent them.
|
31
|
+
- **Experiment with Advanced Features:**
|
32
|
+
- Implement robust task management with a persistent `TaskStore` if your agent handles long-running or multi-session tasks.
|
33
|
+
- Explore implementing push notifications if your agent's tasks are very long-lived.
|
34
|
+
- Consider more complex input and output modalities (e.g., handling file uploads/downloads, or structured data via `DataPart`).
|
35
|
+
- **Contribute to the A2A Community:**
|
36
|
+
- Join the discussions on the [A2A GitHub Discussions page](https://github.com/a2aproject/A2A/discussions).
|
37
|
+
- Report issues or suggest improvements via [GitHub Issues](https://github.com/a2aproject/A2A/issues).
|
38
|
+
- Consider contributing code, examples, or documentation. See the [CONTRIBUTING.md](https://github.com/a2aproject/A2A/blob/main/CONTRIBUTING.md) guide.
|
39
|
+
|
40
|
+
The A2A protocol aims to foster an ecosystem of interoperable AI agents. By building and sharing A2A-compliant agents, you can be a part of this exciting development!
|