smarta2a 0.2.5__tar.gz → 0.3.1__tar.gz

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.
Files changed (60) hide show
  1. smarta2a-0.3.1/PKG-INFO +399 -0
  2. smarta2a-0.3.1/README.md +375 -0
  3. smarta2a-0.3.1/documentation/smarta2a_docs/smarta2a_small_banner.png +0 -0
  4. {smarta2a-0.2.5 → smarta2a-0.3.1}/pyproject.toml +2 -2
  5. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/client/a2a_client.py +85 -51
  6. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/client/mcp_client.py +3 -0
  7. smarta2a-0.3.1/smarta2a/client/tools_manager.py +77 -0
  8. smarta2a-0.3.1/smarta2a/examples/openai_airbnb_agent/main.py +33 -0
  9. smarta2a-0.3.1/smarta2a/examples/openai_delegator_agent/__init__.py +0 -0
  10. smarta2a-0.3.1/smarta2a/examples/openai_delegator_agent/main.py +51 -0
  11. smarta2a-0.3.1/smarta2a/examples/openai_weather_agent/__init__.py +0 -0
  12. {smarta2a-0.2.5/smarta2a/examples/openai_agent → smarta2a-0.3.1/smarta2a/examples/openai_weather_agent}/main.py +1 -1
  13. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/model_providers/openai_provider.py +3 -3
  14. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/utils/types.py +6 -0
  15. smarta2a-0.2.5/PKG-INFO +0 -103
  16. smarta2a-0.2.5/README.md +0 -79
  17. smarta2a-0.2.5/smarta2a/client/tools_manager.py +0 -61
  18. {smarta2a-0.2.5 → smarta2a-0.3.1}/.gitignore +0 -0
  19. {smarta2a-0.2.5 → smarta2a-0.3.1}/LICENSE +0 -0
  20. {smarta2a-0.2.5 → smarta2a-0.3.1}/documentation/smarta2a_docs/docs/blog/announcements.md +0 -0
  21. {smarta2a-0.2.5 → smarta2a-0.3.1}/documentation/smarta2a_docs/docs/getting-started/index.md +0 -0
  22. {smarta2a-0.2.5 → smarta2a-0.3.1}/documentation/smarta2a_docs/docs/getting-started/installation.md +0 -0
  23. {smarta2a-0.2.5 → smarta2a-0.3.1}/documentation/smarta2a_docs/docs/getting-started/quickstart.md +0 -0
  24. {smarta2a-0.2.5 → smarta2a-0.3.1}/documentation/smarta2a_docs/docs/index.md +0 -0
  25. {smarta2a-0.2.5 → smarta2a-0.3.1}/documentation/smarta2a_docs/docs/tutorials/example1.md +0 -0
  26. {smarta2a-0.2.5 → smarta2a-0.3.1}/documentation/smarta2a_docs/docs/tutorials/example2.md +0 -0
  27. {smarta2a-0.2.5 → smarta2a-0.3.1}/documentation/smarta2a_docs/mkdocs.yml +0 -0
  28. {smarta2a-0.2.5 → smarta2a-0.3.1}/requirements.txt +0 -0
  29. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/__init__.py +0 -0
  30. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/agent/a2a_agent.py +0 -0
  31. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/agent/a2a_mcp_server.py +0 -0
  32. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/archive/smart_mcp_client.py +0 -0
  33. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/client/__init__.py +0 -0
  34. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/examples/__init__.py +0 -0
  35. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/examples/echo_server/__init__.py +0 -0
  36. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/examples/echo_server/curl.txt +0 -0
  37. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/examples/echo_server/main.py +0 -0
  38. {smarta2a-0.2.5/smarta2a/examples/openai_agent → smarta2a-0.3.1/smarta2a/examples/openai_airbnb_agent}/__init__.py +0 -0
  39. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/history_update_strategies/__init__.py +0 -0
  40. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/history_update_strategies/append_strategy.py +0 -0
  41. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/history_update_strategies/history_update_strategy.py +0 -0
  42. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/model_providers/__init__.py +0 -0
  43. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/model_providers/base_llm_provider.py +0 -0
  44. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/server/__init__.py +0 -0
  45. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/server/handler_registry.py +0 -0
  46. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/server/server.py +0 -0
  47. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/server/state_manager.py +0 -0
  48. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/server/subscription_service.py +0 -0
  49. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/server/task_service.py +0 -0
  50. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/state_stores/__init__.py +0 -0
  51. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/state_stores/base_state_store.py +0 -0
  52. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/state_stores/inmemory_state_store.py +0 -0
  53. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/utils/__init__.py +0 -0
  54. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/utils/prompt_helpers.py +0 -0
  55. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/utils/task_builder.py +0 -0
  56. {smarta2a-0.2.5 → smarta2a-0.3.1}/smarta2a/utils/task_request_builder.py +0 -0
  57. {smarta2a-0.2.5 → smarta2a-0.3.1}/tests/__init__.py +0 -0
  58. {smarta2a-0.2.5 → smarta2a-0.3.1}/tests/test_server.py +0 -0
  59. {smarta2a-0.2.5 → smarta2a-0.3.1}/tests/test_server_history.py +0 -0
  60. {smarta2a-0.2.5 → smarta2a-0.3.1}/tests/test_task_request_builder.py +0 -0
@@ -0,0 +1,399 @@
1
+ Metadata-Version: 2.4
2
+ Name: smarta2a
3
+ Version: 0.3.1
4
+ Summary: a Python framework that helps you build servers and AI agents that communicate using the A2A protocol
5
+ Project-URL: Homepage, https://github.com/siddharthsma/smarta2a
6
+ Project-URL: Bug Tracker, https://github.com/siddharthsma/smarta2a/issues
7
+ Author-email: Siddharth Ambegaonkar <siddharthsma@gmail.com>
8
+ License-File: LICENSE
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.8
13
+ Requires-Dist: anyio>=4.9.0
14
+ Requires-Dist: fastapi>=0.115.12
15
+ Requires-Dist: httpx>=0.28.1
16
+ Requires-Dist: mcp>=0.1.0
17
+ Requires-Dist: openai>=1.0.0
18
+ Requires-Dist: pydantic>=2.11.3
19
+ Requires-Dist: sse-starlette>=2.2.1
20
+ Requires-Dist: starlette>=0.46.2
21
+ Requires-Dist: typing-extensions>=4.13.2
22
+ Requires-Dist: uvicorn>=0.34.1
23
+ Description-Content-Type: text/markdown
24
+
25
+ <picture>
26
+ <img alt="SmartA2A Logo" src="documentation/smarta2a_docs/smarta2a_small_banner.png" width="100%">
27
+ </picture>
28
+
29
+ <div>
30
+ <br>
31
+ </div>
32
+
33
+ ![PyPI](https://img.shields.io/pypi/v/Smarta2a.svg)
34
+ ![Downloads](https://static.pepy.tech/badge/Smarta2a)
35
+ ![GitHub Repo stars](https://img.shields.io/github/stars/siddharthsma/smarta2a?style=social)
36
+
37
+ **SmartA2A** is a Python framework that helps you build servers and AI agents that communicate using the [A2A (Agent2Agent) protocol](https://developers.googleblog.com/en/a2a-a-new-era-of-agent-interoperability/). A2A defines a common language that enables agents to exchange information and collaborate effectively across systems.
38
+
39
+ SmartA2A abstracts the complexities of the protocol, so you can focus on what matters—your agent's logic and behavior. It supports two primary use cases:
40
+
41
+ ### ✅ 1. Build A2A-Compliant Servers
42
+
43
+ Use SmartA2A to expose key A2A methods through a simple decorator-based API. This allows you to:
44
+
45
+ - Build compliant server endpoints quickly
46
+ - Integrate your own agent logic using any framework (e.g., LangGraph, Google ADK, or custom code)
47
+ - Stay fully aligned with the A2A spec without boilerplate
48
+
49
+ ### 🤖 2. Create Full-Fledged Agents with Minimal Code
50
+
51
+ SmartA2A can also be used to create standalone agents that:
52
+
53
+ - Speak the A2A protocol out of the box
54
+ - Collaborate with other agents seamlessly
55
+ - Connect to any MCP server you choose
56
+ - Require only a few lines of setup
57
+
58
+ SmartA2A makes it easy to build interoperable, communication-ready AI systems—whether you're extending existing frameworks or starting from scratch.
59
+
60
+ ---
61
+
62
+ ## Installation
63
+
64
+ ```bash
65
+ pip install -U smarta2a
66
+ ```
67
+
68
+ ## Examples
69
+
70
+ There are 3 cool examples for you to try out - eacher cooler than the next!
71
+
72
+ 1. The first is a simple Echo server implementation that demonstrates the FastAPI'esk style in which you can create a A2A compliant server. If you're using another Agent framework like LangGraph you can easily use it it tandem with this server.
73
+
74
+ 2. This is where things start to get real interesting - you can easily create an LLM and MCP powered Agent in just a few lines of code. In this case a US weather agent.
75
+
76
+ 3. If you get here, this is where things things start to get really awesome. You will create a multi-agent system where a delegator agent delelgates tasks to the weather agent you created before and to an Airbnb agent. You can now plan your stay based on the weather!
77
+
78
+ Note that you can find all the examples in the examples folder.
79
+
80
+ ### Simple Echo Server Implementation
81
+
82
+ Here's a simple example of an echo server that demonstrates the core features of SmartA2A:
83
+
84
+ ```python
85
+ from smarta2a.server import SmartA2A
86
+ from smarta2a.utils.types import A2AResponse, TaskStatus, TaskState, TextPart, FileContent, FilePart
87
+ from smarta2a.state_stores.inmemory_state_store import InMemoryStateStore
88
+
89
+ # Initialize the server with an in-memory state store
90
+ state_store = InMemoryStateStore()
91
+ app = SmartA2A("EchoServer", state_store=state_store)
92
+
93
+ @app.on_send_task()
94
+ async def handle_task(request, state):
95
+ """Echo the input text back as a completed task. If you were using something like LangGraph you could call your graph.invoke method here """
96
+ input_text = request.content[0].text
97
+ return f"Response to task: {input_text}"
98
+
99
+ @app.on_send_subscribe_task()
100
+ async def handle_subscribe_task(request, state):
101
+ """Subscribe to the task and stream multiple responses"""
102
+ input_text = request.content[0].text
103
+ yield f"First response to the task: {input_text}"
104
+ yield f"Second response to the task: {input_text}"
105
+ yield f"Third response to the task: {input_text}"
106
+
107
+ @app.task_get()
108
+ def handle_get_task(request):
109
+ """Get the task status"""
110
+ return f"Task: {request.id}"
111
+
112
+ @app.task_cancel()
113
+ def handle_cancel_task(request):
114
+ """Cancel the task"""
115
+ return f"Task cancelled: {request.id}"
116
+ ```
117
+
118
+ This example shows:
119
+ - Setting up a basic A2A server with state management
120
+ - Handling synchronous task requests with text and file responses
121
+ - Implementing streaming responses for subscription tasks
122
+ - Basic task management (get and cancel operations)
123
+
124
+ To run the echo server:
125
+ ```bash
126
+ uvicorn path.to.echo_server.main.py:app
127
+ ```
128
+
129
+ You can test the echo server using curl commands:
130
+
131
+ ```bash
132
+ # Test sending a task
133
+ curl -X POST http://localhost:8000/ \
134
+ -H "Content-Type: application/json" \
135
+ -d '{
136
+ "jsonrpc": "2.0",
137
+ "id": "1",
138
+ "method": "tasks/send",
139
+ "params": {
140
+ "id": "task1",
141
+ "message": {
142
+ "role": "user",
143
+ "parts": [{"type": "text", "text": "Hello, echo server!"}]
144
+ }
145
+ }
146
+ }'
147
+
148
+ # Test subscribing to a task
149
+ curl -X POST http://localhost:8000/ \
150
+ -H "Content-Type: application/json" \
151
+ -d '{
152
+ "jsonrpc": "2.0",
153
+ "id": "2",
154
+ "method": "tasks/sendSubscribe",
155
+ "params": {
156
+ "id": "task2",
157
+ "message": {
158
+ "role": "user",
159
+ "parts": [{"type": "text", "text": "Hello, streaming echo!"}]
160
+ }
161
+ }
162
+ }'
163
+ ```
164
+
165
+ ### Weather Agent Example
166
+
167
+ Here's an example of a weather agent that uses OpenAI's GPT model to handle weather-related queries. Note that you will need to setup the weather MCP server as a pre-requisite as specified by the [MCP Quick-start server tutorial](https://modelcontextprotocol.io/quickstart/server). You will also need to add your OpenAI API key to the .env file.
168
+
169
+ ```python
170
+ from dotenv import load_dotenv
171
+ import os
172
+ import uvicorn
173
+ from smarta2a.agent.a2a_agent import A2AAgent
174
+ from smarta2a.model_providers.openai_provider import OpenAIProvider
175
+
176
+ # Load environment variables from the .env file
177
+ load_dotenv()
178
+
179
+ # Initialize OpenAI provider with weather-specific configuration
180
+ openai_provider = OpenAIProvider(
181
+ api_key=os.getenv("OPENAI_API_KEY"),
182
+ model="gpt-4o-mini",
183
+ base_system_prompt="You are a cheerful assistant that specialises in helping with weather related queries",
184
+ mcp_server_urls_or_paths=["/path/to/weather.py"], # Path to your weather service
185
+ )
186
+
187
+ # Create and run the agent
188
+ agent = A2AAgent(
189
+ name="openai_agent",
190
+ model_provider=openai_provider,
191
+ )
192
+
193
+ if __name__ == "__main__":
194
+ uvicorn.run(agent.get_app(), host="0.0.0.0", port=8000)
195
+ ```
196
+
197
+ This example demonstrates:
198
+ - Setting up an AI agent with OpenAI integration
199
+ - Configuring a specialized system prompt for weather queries
200
+ - Connecting to external weather services via MCP
201
+ - Running the agent as a standalone server
202
+
203
+ To run the weather agent:
204
+ ```bash
205
+ python path/to/weather_agent/main.py
206
+ ```
207
+
208
+ To test the weather agent, ensure:
209
+ 1. Your weather MCP server is running
210
+ 2. Your OpenAI API key is set in the .env file
211
+ 3. The agent is running as shown above
212
+
213
+ Then test it with curl:
214
+
215
+ ```bash
216
+ # Test weather query
217
+ curl -X POST http://localhost:8000/ \
218
+ -H "Content-Type: application/json" \
219
+ -d '{
220
+ "jsonrpc": "2.0",
221
+ "id": "1",
222
+ "method": "tasks/send",
223
+ "params": {
224
+ "id": "weather1",
225
+ "message": {
226
+ "role": "user",
227
+ "parts": [{"type": "text", "text": "What is the weather in New York?"}]
228
+ }
229
+ }
230
+ }'
231
+ ```
232
+
233
+ ### Multi-agent Weather-Aware Stay Planner
234
+
235
+ This example demonstrates how to create a multi-agent system where a delegator agent coordinates between a weather agent and an Airbnb agent to help plan stays based on weather conditions. You'll need to run three agents:
236
+
237
+ 1. The weather agent (from the previous example)
238
+ 2. An Airbnb agent that connects to the Airbnb MCP server
239
+ 3. A delegator agent that coordinates between them
240
+
241
+ First, let's create the Airbnb agent:
242
+
243
+ ```python
244
+ from dotenv import load_dotenv
245
+ import os
246
+ import uvicorn
247
+ from smarta2a.agent.a2a_agent import A2AAgent
248
+ from smarta2a.model_providers.openai_provider import OpenAIProvider
249
+
250
+ # Load environment variables
251
+ load_dotenv()
252
+
253
+ # Initialize OpenAI provider with Airbnb-specific configuration
254
+ openai_provider = OpenAIProvider(
255
+ api_key=os.getenv("OPENAI_API_KEY"),
256
+ model="gpt-4o-mini",
257
+ base_system_prompt="You are a cheerful assistant that specialises in helping with Airbnb related queries",
258
+ mcp_server_urls_or_paths=["@openbnb/mcp-server-airbnb --ignore-robots-txt"]
259
+ )
260
+
261
+ # Create and run the Airbnb agent
262
+ agent = A2AAgent(
263
+ name="airbnb_agent",
264
+ model_provider=openai_provider,
265
+ )
266
+
267
+ if __name__ == "__main__":
268
+ uvicorn.run(agent.get_app(), host="0.0.0.0", port=8002)
269
+ ```
270
+
271
+ Now, let's create the delegator agent that coordinates between the weather and Airbnb agents:
272
+
273
+ ```python
274
+ from dotenv import load_dotenv
275
+ import os
276
+ import uvicorn
277
+ from smarta2a.agent.a2a_agent import A2AAgent
278
+ from smarta2a.model_providers.openai_provider import OpenAIProvider
279
+ from smarta2a.utils.types import AgentCard, AgentCapabilities, AgentSkill
280
+
281
+ # Load environment variables
282
+ load_dotenv()
283
+
284
+ # Define the weather agent's capabilities
285
+ weather_agent_card = AgentCard(
286
+ name="weather_agent",
287
+ description="A weather agent that can help with weather related queries",
288
+ version="0.1.0",
289
+ url="http://localhost:8000",
290
+ capabilities=AgentCapabilities(),
291
+ skills=[
292
+ AgentSkill(
293
+ id="weather_forecasting",
294
+ name="Weather Forecasting",
295
+ description="Can get weather forecast for a given location"
296
+ ),
297
+ AgentSkill(
298
+ id="weather_alerts",
299
+ name="Weather Alerts",
300
+ description="Can get weather alerts for a US state"
301
+ )
302
+ ]
303
+ )
304
+
305
+ # Define the Airbnb agent's capabilities
306
+ airbnb_agent_card = AgentCard(
307
+ name="airbnb_agent",
308
+ description="An Airbnb agent that can help with accommodation queries",
309
+ version="0.1.0",
310
+ url="http://localhost:8002",
311
+ capabilities=AgentCapabilities(),
312
+ skills=[
313
+ AgentSkill(
314
+ id="search_listings",
315
+ name="Search Listings",
316
+ description="Search for Airbnb listings by location, dates, and guests"
317
+ ),
318
+ AgentSkill(
319
+ id="get_listing_details",
320
+ name="Get Listing Details",
321
+ description="Get detailed information about specific Airbnb listings"
322
+ )
323
+ ]
324
+ )
325
+
326
+ # Initialize OpenAI provider with both agent cards
327
+ openai_provider = OpenAIProvider(
328
+ api_key=os.getenv("OPENAI_API_KEY"),
329
+ model="gpt-4o-mini",
330
+ agent_cards=[weather_agent_card, airbnb_agent_card]
331
+ )
332
+
333
+ # Create and run the delegator agent
334
+ agent = A2AAgent(
335
+ name="delegator_agent",
336
+ model_provider=openai_provider,
337
+ )
338
+
339
+ if __name__ == "__main__":
340
+ uvicorn.run(agent.get_app(), host="0.0.0.0", port=8001)
341
+ ```
342
+
343
+ To run the multi-agent system:
344
+
345
+ 1. Start the weather agent:
346
+ ```bash
347
+ python path/to/weather_agent/main.py
348
+ ```
349
+
350
+ 2. Start the Airbnb agent: No need to do anything - just ensure that node and npx are installed on your machine
351
+
352
+
353
+ 3. Start the delegator agent:
354
+ ```bash
355
+ python path/to/delegator_agent/main.py
356
+ ```
357
+
358
+ You can then test the system with a curl command:
359
+
360
+ ```bash
361
+ # Test multi-agent planning
362
+ curl -X POST http://localhost:8001/ \
363
+ -H "Content-Type: application/json" \
364
+ -d '{
365
+ "jsonrpc": "2.0",
366
+ "id": "1",
367
+ "method": "tasks/send",
368
+ "params": {
369
+ "id": "plan1",
370
+ "message": {
371
+ "role": "user",
372
+ "parts": [{"type": "text", "text": "I want to go someplace sunny in California. Just me and my wife. Can you check the weather forecast in the major cities and give me some airbnb recommendations that are appropriate. I want to stay from the 7th of May and checking out on the 10th of May. I'm not fussed about the budget."}]
373
+ }
374
+ }
375
+ }'
376
+ ```
377
+
378
+ This example demonstrates:
379
+ - Creating specialized agents for different domains (weather and Airbnb)
380
+ - Defining agent capabilities and skills using AgentCard
381
+ - Setting up a delegator agent that can coordinate between multiple agents
382
+ - Running multiple agents on different ports
383
+ - Making complex queries that require coordination between agents
384
+
385
+ ---
386
+
387
+ ## Roadmap
388
+
389
+ There's still a lot more to come ...
390
+
391
+ - Documentation site with tutorials, explanation of concepts, blog and a contribution guide
392
+ - Support for more LLM providers
393
+ - Support for more memory types
394
+ - Authorization and observability framework built-in
395
+ - Many more !
396
+
397
+ ## License
398
+
399
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.