smarta2a 0.3.0__py3-none-any.whl → 0.4.0__py3-none-any.whl
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.
- smarta2a/agent/a2a_agent.py +25 -15
- smarta2a/agent/a2a_human.py +56 -0
- smarta2a/archive/smart_mcp_client.py +47 -0
- smarta2a/archive/subscription_service.py +85 -0
- smarta2a/{server → archive}/task_service.py +17 -8
- smarta2a/client/a2a_client.py +35 -8
- smarta2a/client/mcp_client.py +3 -0
- smarta2a/history_update_strategies/rolling_window_strategy.py +16 -0
- smarta2a/model_providers/__init__.py +1 -1
- smarta2a/model_providers/base_llm_provider.py +3 -3
- smarta2a/model_providers/openai_provider.py +126 -89
- smarta2a/nats-server.conf +12 -0
- smarta2a/server/json_rpc_request_processor.py +130 -0
- smarta2a/server/nats_client.py +49 -0
- smarta2a/server/request_handler.py +667 -0
- smarta2a/server/send_task_handler.py +174 -0
- smarta2a/server/server.py +124 -726
- smarta2a/server/state_manager.py +173 -19
- smarta2a/server/webhook_request_processor.py +112 -0
- smarta2a/state_stores/base_state_store.py +3 -3
- smarta2a/state_stores/inmemory_state_store.py +21 -7
- smarta2a/utils/agent_discovery_manager.py +121 -0
- smarta2a/utils/prompt_helpers.py +1 -1
- smarta2a/utils/tools_manager.py +108 -0
- smarta2a/utils/types.py +18 -3
- smarta2a-0.4.0.dist-info/METADATA +402 -0
- smarta2a-0.4.0.dist-info/RECORD +41 -0
- smarta2a-0.4.0.dist-info/licenses/LICENSE +35 -0
- smarta2a/client/tools_manager.py +0 -62
- smarta2a/examples/__init__.py +0 -0
- smarta2a/examples/echo_server/__init__.py +0 -0
- smarta2a/examples/echo_server/curl.txt +0 -1
- smarta2a/examples/echo_server/main.py +0 -39
- smarta2a/examples/openai_delegator_agent/__init__.py +0 -0
- smarta2a/examples/openai_delegator_agent/main.py +0 -41
- smarta2a/examples/openai_weather_agent/__init__.py +0 -0
- smarta2a/examples/openai_weather_agent/main.py +0 -32
- smarta2a/server/subscription_service.py +0 -109
- smarta2a-0.3.0.dist-info/METADATA +0 -103
- smarta2a-0.3.0.dist-info/RECORD +0 -40
- smarta2a-0.3.0.dist-info/licenses/LICENSE +0 -21
- {smarta2a-0.3.0.dist-info → smarta2a-0.4.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,402 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: smarta2a
|
3
|
+
Version: 0.4.0
|
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
|
+

|
34
|
+

|
35
|
+

|
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 an A2A compliant server. If you're using another Agent framework like LangGraph you can easily use it in 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 responses (btw also handles files!)
|
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 weather agent:
|
351
|
+
```bash
|
352
|
+
python path/to/airbnb_agent/main.py
|
353
|
+
```
|
354
|
+
|
355
|
+
|
356
|
+
3. Start the delegator agent:
|
357
|
+
```bash
|
358
|
+
python path/to/delegator_agent/main.py
|
359
|
+
```
|
360
|
+
|
361
|
+
You can then test the system with a curl command:
|
362
|
+
|
363
|
+
```bash
|
364
|
+
# Test multi-agent planning
|
365
|
+
curl -X POST http://localhost:8001/ \
|
366
|
+
-H "Content-Type: application/json" \
|
367
|
+
-d '{
|
368
|
+
"jsonrpc": "2.0",
|
369
|
+
"id": "1",
|
370
|
+
"method": "tasks/send",
|
371
|
+
"params": {
|
372
|
+
"id": "plan1",
|
373
|
+
"message": {
|
374
|
+
"role": "user",
|
375
|
+
"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."}]
|
376
|
+
}
|
377
|
+
}
|
378
|
+
}'
|
379
|
+
```
|
380
|
+
|
381
|
+
This example demonstrates:
|
382
|
+
- Creating specialized agents for different domains (weather and Airbnb)
|
383
|
+
- Defining agent capabilities and skills using AgentCard
|
384
|
+
- Setting up a delegator agent that can coordinate between multiple agents
|
385
|
+
- Running multiple agents on different ports
|
386
|
+
- Making complex queries that require coordination between agents
|
387
|
+
|
388
|
+
---
|
389
|
+
|
390
|
+
## Roadmap
|
391
|
+
|
392
|
+
There's still a lot more to come ...
|
393
|
+
|
394
|
+
- Documentation site with tutorials, explanation of concepts, blog and a contribution guide
|
395
|
+
- Support for more LLM providers
|
396
|
+
- Support for more memory types
|
397
|
+
- Authorization and observability framework built-in
|
398
|
+
- Many more !
|
399
|
+
|
400
|
+
## License
|
401
|
+
|
402
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
@@ -0,0 +1,41 @@
|
|
1
|
+
smarta2a/__init__.py,sha256=T_EECYqWrxshix0FbgUv22zlKRX22HFU-HKXcYTOb3w,175
|
2
|
+
smarta2a/nats-server.conf,sha256=4Nm2NdijEXxRU0c7jlFE0g8KGMsBDMB4gDC0kdUDt_o,295
|
3
|
+
smarta2a/agent/a2a_agent.py,sha256=EurcxpV14e3OPWCMutYL0EXMHb5ZKQqAHEGZZF6pNgg,1892
|
4
|
+
smarta2a/agent/a2a_human.py,sha256=tXrEtl0OqZEXZfmPTLnbbAiREMTmlqA42XIf7KocqMU,1850
|
5
|
+
smarta2a/agent/a2a_mcp_server.py,sha256=X_mxkgYgCA_dSNtCvs0rSlOoWYc-8d3Qyxv0e-a7NKY,1015
|
6
|
+
smarta2a/archive/smart_mcp_client.py,sha256=0s2OWFKWSv-_UF7rb9fOrsh1OIYsYOsGukkXXp_E1cU,4158
|
7
|
+
smarta2a/archive/subscription_service.py,sha256=vftmZD94HbdjPFa_1UBvsBm-WkW-s3ZCVq60fF7OCgA,4109
|
8
|
+
smarta2a/archive/task_service.py,sha256=ptf-oMHy98Rw4XSxyK1-lpqc1JtkCkEEHTmwAaunet4,8199
|
9
|
+
smarta2a/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
+
smarta2a/client/a2a_client.py,sha256=apDkKFtq61T79LpkbkzVTKWA0mSjR_eTNdGPUYozyvk,12100
|
11
|
+
smarta2a/client/mcp_client.py,sha256=PM4D1CgOycxK5kJEJTGpKq0eXFjZ69-2720TuRUkyGc,3627
|
12
|
+
smarta2a/history_update_strategies/__init__.py,sha256=x5WtiE9rG5ze8d8hA6E6wJOciBhWHa_ZgGgoIAZcXEQ,213
|
13
|
+
smarta2a/history_update_strategies/append_strategy.py,sha256=j7Qbhs69Wwr-HBLB8GJ3-mEPaBSHiBV2xz9ZZi86k2w,312
|
14
|
+
smarta2a/history_update_strategies/history_update_strategy.py,sha256=n2sfIGu8ztKI7gJTwRX26m4tZr28B8Xdhrk6RlBFlI8,373
|
15
|
+
smarta2a/history_update_strategies/rolling_window_strategy.py,sha256=7Ch042JWt4TM_r1-sFKlSIxHj8VX1P3ZoqjCvIdeSqA,540
|
16
|
+
smarta2a/model_providers/__init__.py,sha256=hJj0w00JjqTiBgJmHmOWwL6MU_hwmro9xTiX3XYf6ts,148
|
17
|
+
smarta2a/model_providers/base_llm_provider.py,sha256=iQUqjnypl0f2M929iU0WhHoxAE4ek-NUFJPbEnNQ8-4,412
|
18
|
+
smarta2a/model_providers/openai_provider.py,sha256=YGHF6IIsBBE-Otiq9q9hSd49sh5unxqINRh9q3nKPQI,12088
|
19
|
+
smarta2a/server/__init__.py,sha256=f2X454Ll4vJc02V4JLJHTN-h8u0TBm4d_FkiO4t686U,53
|
20
|
+
smarta2a/server/handler_registry.py,sha256=OVRG5dTvxB7qUNXgsqWxVNxIyRljUShSYxb1gtbi5XM,820
|
21
|
+
smarta2a/server/json_rpc_request_processor.py,sha256=qRB3sfj_n9ImkIOCdaUKMsDmKcO7CiMhaZ4VdQS7Mb4,6993
|
22
|
+
smarta2a/server/nats_client.py,sha256=akyNg1hLd9XYoLSH_qQVs8uoiTQerztgvqu_3TifSgE,1617
|
23
|
+
smarta2a/server/request_handler.py,sha256=5KMtfpHQX6bOgk1DJbhs1fUCQ5tSvMYXWzheT3IW2Bo,26374
|
24
|
+
smarta2a/server/send_task_handler.py,sha256=fiBeCCHCu9c2H4EJOUc0t3EZgpHVFJy4B_6qZOC140s,6336
|
25
|
+
smarta2a/server/server.py,sha256=grE2n-MAyaBR5rUro2ZJ0kI6sBFplHvRFL5MMe1DsPs,7094
|
26
|
+
smarta2a/server/state_manager.py,sha256=-AgnhtAnrugSxncGgqskXJnQnAOjwNUg7xuyDvQ7V4s,6668
|
27
|
+
smarta2a/server/webhook_request_processor.py,sha256=_0XoUDmueSl9CvFQE-1zgKRSts-EW8QxbmolPTfFER8,5306
|
28
|
+
smarta2a/state_stores/__init__.py,sha256=vafxAqpwvag_cYFH2XKGk3DPmJIWJr4Ioey30yLFkVQ,220
|
29
|
+
smarta2a/state_stores/base_state_store.py,sha256=_3LInM-qepKwwdypJTDNs9-DozBNrKVycwPwUm7bYdU,512
|
30
|
+
smarta2a/state_stores/inmemory_state_store.py,sha256=nEBBUiiqhEluP2MYJjFUImcjIwLJEvL8BWwMbLCb8Fw,1268
|
31
|
+
smarta2a/utils/__init__.py,sha256=5db5VgDGgbMUGEF-xuyaC3qrgRQkUE9WAITkFSiNqSA,702
|
32
|
+
smarta2a/utils/agent_discovery_manager.py,sha256=6KpRSQH_EDUOZbF4wFRsZneZGIPLXFP4VjWPN4Ydv-A,4172
|
33
|
+
smarta2a/utils/prompt_helpers.py,sha256=M3UUjFQEspEAnNm54Dip0-D7mMFFZLrP_s_89ZPe6fs,1438
|
34
|
+
smarta2a/utils/task_builder.py,sha256=wqSyfVHNTaXuGESu09dhlaDi7D007gcN3-8tH-nPQ40,5159
|
35
|
+
smarta2a/utils/task_request_builder.py,sha256=6cOGOqj2Rg43xWM03GRJQzlIZHBptsMCJRp7oD-TDAQ,3362
|
36
|
+
smarta2a/utils/tools_manager.py,sha256=yOiJ6tyxfKDJDM2C0FoVuqh3nNNee75iRw_M7LmZdzA,4319
|
37
|
+
smarta2a/utils/types.py,sha256=kzA6Vv5xXfu1sJuxhEXrglI9e9S6eZVIljMnsrQVyN0,13650
|
38
|
+
smarta2a-0.4.0.dist-info/METADATA,sha256=lCSXmNz7iNptUspp9o0I1teAFLcSSUr5iufmwHh5jhk,12987
|
39
|
+
smarta2a-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
40
|
+
smarta2a-0.4.0.dist-info/licenses/LICENSE,sha256=lDbqrxVnzDMY5KJ8JS1WhvkWE8TJaw-O-CHDy-ecsJA,2095
|
41
|
+
smarta2a-0.4.0.dist-info/RECORD,,
|
@@ -0,0 +1,35 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Siddharth Sameer Ambegaonkar
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the “Software”), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
23
|
+
---
|
24
|
+
|
25
|
+
**Commons Clause License Condition v1.0**
|
26
|
+
|
27
|
+
The Software is provided under the MIT License, as supplemented by the following condition:
|
28
|
+
|
29
|
+
The grant of rights under the MIT License does not include, and the following condition is added to the MIT License:
|
30
|
+
|
31
|
+
*Notwithstanding any other provision of the License, the License does not grant the right to Sell the Software.*
|
32
|
+
|
33
|
+
For purposes of the foregoing, “Sell” means practicing any or all of the rights granted to you under the License to provide to third parties, for a fee or other consideration (including without limitation fees for hosting or consulting/support services related to the Software), a product or service whose value derives, entirely or substantially, from the functionality of the Software. Any licensee who provides any such product or service is deemed to be in violation of this condition and may not exercise any of the rights granted under the License.
|
34
|
+
|
35
|
+
This condition is intended to supplement, not replace, the License.
|
smarta2a/client/tools_manager.py
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
# Library imports
|
2
|
-
import json
|
3
|
-
from typing import List, Dict, Any, Union, Literal
|
4
|
-
|
5
|
-
# Local imports
|
6
|
-
from smarta2a.client.mcp_client import MCPClient
|
7
|
-
from smarta2a.client.a2a_client import A2AClient
|
8
|
-
from smarta2a.utils.types import AgentCard, Tool
|
9
|
-
|
10
|
-
class ToolsManager:
|
11
|
-
"""
|
12
|
-
Manages loading, describing, and invoking tools from various providers.
|
13
|
-
Acts as a wrapper around the MCP and A2A clients.
|
14
|
-
"""
|
15
|
-
def __init__(self):
|
16
|
-
self.tools_list: List[Any] = []
|
17
|
-
self.clients: Dict[str, Union[MCPClient, A2AClient]] = {}
|
18
|
-
|
19
|
-
async def load_mcp_tools(self, urls_or_paths: List[str]) -> None:
|
20
|
-
for url in urls_or_paths:
|
21
|
-
mcp_client = await MCPClient.create(url)
|
22
|
-
tools = await mcp_client.list_tools()
|
23
|
-
for tool in tools:
|
24
|
-
self.tools_list.append(tool)
|
25
|
-
self.clients[tool.name] = mcp_client
|
26
|
-
|
27
|
-
async def load_a2a_tools(self, agent_cards: List[AgentCard]) -> None:
|
28
|
-
for agent_card in agent_cards:
|
29
|
-
a2a_client = A2AClient(agent_card)
|
30
|
-
tools_list = await a2a_client.list_tools()
|
31
|
-
tools = [Tool(**tool_dict) for tool_dict in tools_list]
|
32
|
-
for tool in tools:
|
33
|
-
self.tools_list.append(tool)
|
34
|
-
self.clients[tool.name] = a2a_client
|
35
|
-
|
36
|
-
def get_tools(self) -> List[Any]:
|
37
|
-
return self.tools_list
|
38
|
-
|
39
|
-
|
40
|
-
def describe_tools(self, client_type: Literal["mcp", "a2a"]) -> str:
|
41
|
-
lines = []
|
42
|
-
for tool in self.tools_list:
|
43
|
-
schema = json.dumps(tool.inputSchema, indent=2) # Fix: use inputSchema
|
44
|
-
if client_type == "mcp":
|
45
|
-
lines.append(
|
46
|
-
f"- **{tool.name}**: {tool.description}\n Parameters schema:\n ```json\n{schema}\n```"
|
47
|
-
)
|
48
|
-
elif client_type == "a2a":
|
49
|
-
lines.append(
|
50
|
-
f"- **{tool.name}**: {tool.description}\n Parameters schema:\n ```json\n{schema}\n```"
|
51
|
-
)
|
52
|
-
|
53
|
-
return "\n".join(lines)
|
54
|
-
|
55
|
-
def get_client(self, tool_name: str) -> Any:
|
56
|
-
return self.clients.get(tool_name)
|
57
|
-
|
58
|
-
async def call_tool(self, tool_name: str, args: Dict[str, Any]) -> Any:
|
59
|
-
client = self.get_client(tool_name)
|
60
|
-
if not client:
|
61
|
-
raise ValueError(f"Tool not found: {tool_name}")
|
62
|
-
return await client.call_tool(tool_name, args)
|
smarta2a/examples/__init__.py
DELETED
File without changes
|
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
curl -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, "method": “tasks/send”, "params": {"id": "test-task-1","message": {"role": "user","parts": [{"type": "text", "text": "Test message"}]}} }' http://localhost:8000/
|
@@ -1,39 +0,0 @@
|
|
1
|
-
from smarta2a.server import SmartA2A
|
2
|
-
from smarta2a.utils.types import A2AResponse, TaskStatus, TaskState, TextPart, FileContent, FilePart
|
3
|
-
from smarta2a.state_stores.inmemory_state_store import InMemoryStateStore
|
4
|
-
|
5
|
-
state_store = InMemoryStateStore()
|
6
|
-
app = SmartA2A("EchoServer", state_store=state_store)
|
7
|
-
|
8
|
-
@app.on_send_task()
|
9
|
-
async def handle_task(request, state):
|
10
|
-
"""Echo the input text back as a completed task"""
|
11
|
-
input_text = request.content[0].text
|
12
|
-
#return f"Response to task: {input_text}"
|
13
|
-
return A2AResponse(
|
14
|
-
content=[TextPart(type="text", text="Response to task: " + input_text), FilePart(type="file", file=FileContent(name="test.txt", bytes="test"))],
|
15
|
-
status="working"
|
16
|
-
)
|
17
|
-
|
18
|
-
@app.on_send_subscribe_task()
|
19
|
-
async def handle_subscribe_task(request, state):
|
20
|
-
"""Subscribe to the task"""
|
21
|
-
input_text = request.content[0].text
|
22
|
-
yield f"First response to the task: {input_text}"
|
23
|
-
yield f"Second response to the task: {input_text}"
|
24
|
-
yield f"Third response to the task: {input_text}"
|
25
|
-
|
26
|
-
@app.task_get()
|
27
|
-
def handle_get_task(request):
|
28
|
-
"""Get the task"""
|
29
|
-
return f"Task: {request.id}"
|
30
|
-
|
31
|
-
@app.task_cancel()
|
32
|
-
def handle_cancel_task(request):
|
33
|
-
"""Cancel the task"""
|
34
|
-
return f"Task cancelled: {request.id}"
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
File without changes
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# Imports
|
2
|
-
from dotenv import load_dotenv
|
3
|
-
import os
|
4
|
-
import uvicorn
|
5
|
-
from smarta2a.agent.a2a_agent import A2AAgent
|
6
|
-
from smarta2a.model_providers.openai_provider import OpenAIProvider
|
7
|
-
from smarta2a.utils.types import AgentCard, AgentCapabilities, AgentSkill
|
8
|
-
|
9
|
-
|
10
|
-
# Load environment variables from the .env file
|
11
|
-
load_dotenv()
|
12
|
-
|
13
|
-
# Fetch the value using os.getenv
|
14
|
-
api_key = os.getenv("OPENAI_API_KEY")
|
15
|
-
|
16
|
-
weather_agent_card = AgentCard(
|
17
|
-
name="weather_agent",
|
18
|
-
description="A weather agent that can help with weather related queries",
|
19
|
-
version="0.1.0",
|
20
|
-
url="http://localhost:8000",
|
21
|
-
capabilities=AgentCapabilities(),
|
22
|
-
skills=[AgentSkill(id="weather_forecasting", name="Weather Forecasting", description="Can get weather forecast for a given latitude and longitude"),
|
23
|
-
AgentSkill(id="weather_alerts", name="Weather Alerts", description="Can get weather alerts for a US state")]
|
24
|
-
)
|
25
|
-
|
26
|
-
|
27
|
-
openai_provider = OpenAIProvider(
|
28
|
-
api_key=api_key,
|
29
|
-
model="gpt-4o-mini",
|
30
|
-
agent_cards=[weather_agent_card]
|
31
|
-
)
|
32
|
-
|
33
|
-
# Create the agent
|
34
|
-
agent = A2AAgent(
|
35
|
-
name="openai_agent",
|
36
|
-
model_provider=openai_provider,
|
37
|
-
)
|
38
|
-
|
39
|
-
# Entry point
|
40
|
-
if __name__ == "__main__":
|
41
|
-
uvicorn.run(agent.get_app(), host="0.0.0.0", port=8080)
|
File without changes
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# Imports
|
2
|
-
from dotenv import load_dotenv
|
3
|
-
import os
|
4
|
-
import uvicorn
|
5
|
-
from smarta2a.agent.a2a_agent import A2AAgent
|
6
|
-
from smarta2a.model_providers.openai_provider import OpenAIProvider
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# Load environment variables from the .env file
|
11
|
-
load_dotenv()
|
12
|
-
|
13
|
-
# Fetch the value using os.getenv
|
14
|
-
api_key = os.getenv("OPENAI_API_KEY")
|
15
|
-
|
16
|
-
|
17
|
-
openai_provider = OpenAIProvider(
|
18
|
-
api_key=api_key,
|
19
|
-
model="gpt-4o-mini",
|
20
|
-
base_system_prompt="You are a cheerful assistant that specialises in helping with weather related queries",
|
21
|
-
mcp_server_urls_or_paths=["/Users/apple/Desktop/Code/weather/weather.py"],
|
22
|
-
)
|
23
|
-
|
24
|
-
# Create the agent
|
25
|
-
agent = A2AAgent(
|
26
|
-
name="openai_agent",
|
27
|
-
model_provider=openai_provider,
|
28
|
-
)
|
29
|
-
|
30
|
-
# Entry point
|
31
|
-
if __name__ == "__main__":
|
32
|
-
uvicorn.run(agent.get_app(), host="0.0.0.0", port=8000)
|