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
@@ -1,109 +0,0 @@
|
|
1
|
-
# Library imports
|
2
|
-
from typing import Optional, List, Dict, Any, AsyncGenerator, Union
|
3
|
-
from datetime import datetime
|
4
|
-
from collections import defaultdict
|
5
|
-
from uuid import uuid4
|
6
|
-
from fastapi.responses import StreamingResponse
|
7
|
-
from sse_starlette.sse import EventSourceResponse
|
8
|
-
|
9
|
-
# Local imports
|
10
|
-
from smarta2a.server.handler_registry import HandlerRegistry
|
11
|
-
from smarta2a.server.state_manager import StateManager
|
12
|
-
from smarta2a.utils.types import (
|
13
|
-
Message, StateData, SendTaskStreamingRequest, SendTaskStreamingResponse,
|
14
|
-
TaskSendParams, A2AStatus, A2AStreamResponse, TaskStatusUpdateEvent,
|
15
|
-
TaskStatus, TaskState, TaskArtifactUpdateEvent, Artifact, TextPart,
|
16
|
-
FilePart, DataPart, FileContent, MethodNotFoundError, TaskNotFoundError,
|
17
|
-
InternalError
|
18
|
-
)
|
19
|
-
|
20
|
-
class SubscriptionService:
|
21
|
-
def __init__(self, registry: HandlerRegistry, state_mgr: StateManager):
|
22
|
-
self.registry = registry
|
23
|
-
self.state_mgr = state_mgr
|
24
|
-
|
25
|
-
async def subscribe(self, request: SendTaskStreamingRequest, state: Optional[StateData]) -> StreamingResponse:
|
26
|
-
handler = self.registry.get_subscription("tasks/sendSubscribe")
|
27
|
-
if not handler:
|
28
|
-
err = SendTaskStreamingResponse(jsonrpc="2.0", id=request.id, error=MethodNotFoundError()).model_dump_json()
|
29
|
-
return EventSourceResponse(err)
|
30
|
-
|
31
|
-
session_id = state.sessionId if state else request.params.sessionId or str(uuid4())
|
32
|
-
history = state.history.copy() if state else [request.params.message]
|
33
|
-
metadata = state.metadata.copy() if state else (request.params.metadata or {})
|
34
|
-
|
35
|
-
async def event_stream():
|
36
|
-
try:
|
37
|
-
events = handler(request, state) if state else handler(request)
|
38
|
-
async for ev in self._normalize(request.params, events, history.copy(), metadata.copy(), session_id):
|
39
|
-
yield f"data: {ev}\n\n"
|
40
|
-
except Exception as e:
|
41
|
-
err = TaskNotFoundError() if 'not found' in str(e).lower() else InternalError(data=str(e))
|
42
|
-
msg = SendTaskStreamingResponse(jsonrpc="2.0", id=request.id, error=err).model_dump_json()
|
43
|
-
yield f"data: {msg}\n\n"
|
44
|
-
|
45
|
-
return StreamingResponse(event_stream(), media_type="text/event-stream; charset=utf-8")
|
46
|
-
|
47
|
-
async def _normalize(
|
48
|
-
self,
|
49
|
-
params: TaskSendParams,
|
50
|
-
events: AsyncGenerator,
|
51
|
-
history: List[Message],
|
52
|
-
metadata: Dict[str, Any],
|
53
|
-
session_id: str
|
54
|
-
) -> AsyncGenerator[str, None]:
|
55
|
-
artifact_state = defaultdict(lambda: {"index": 0, "last_chunk": False})
|
56
|
-
async for item in events:
|
57
|
-
if isinstance(item, SendTaskStreamingResponse):
|
58
|
-
yield item.model_dump_json()
|
59
|
-
continue
|
60
|
-
|
61
|
-
if isinstance(item, A2AStatus):
|
62
|
-
te = TaskStatusUpdateEvent(
|
63
|
-
id=params.id,
|
64
|
-
status=TaskStatus(state=TaskState(item.status), timestamp=datetime.now()),
|
65
|
-
final=item.final or (item.status.lower() == TaskState.COMPLETED),
|
66
|
-
metadata=item.metadata
|
67
|
-
)
|
68
|
-
yield SendTaskStreamingResponse(jsonrpc="2.0", id=params.id, result=te).model_dump_json()
|
69
|
-
continue
|
70
|
-
|
71
|
-
content_item = item
|
72
|
-
if not isinstance(item, A2AStreamResponse):
|
73
|
-
content_item = A2AStreamResponse(content=item)
|
74
|
-
|
75
|
-
parts: List[Union[TextPart, FilePart, DataPart]] = []
|
76
|
-
cont = content_item.content
|
77
|
-
if isinstance(cont, str): parts.append(TextPart(text=cont))
|
78
|
-
elif isinstance(cont, bytes): parts.append(FilePart(file=FileContent(bytes=cont)))
|
79
|
-
elif isinstance(cont, (TextPart, FilePart, DataPart)): parts.append(cont)
|
80
|
-
elif isinstance(cont, Artifact): parts.extend(cont.parts)
|
81
|
-
elif isinstance(cont, list):
|
82
|
-
for elem in cont:
|
83
|
-
if isinstance(elem, str): parts.append(TextPart(text=elem))
|
84
|
-
elif isinstance(elem, (TextPart, FilePart, DataPart)): parts.append(elem)
|
85
|
-
elif isinstance(elem, Artifact): parts.extend(elem.parts)
|
86
|
-
|
87
|
-
idx = content_item.index
|
88
|
-
state = artifact_state[idx]
|
89
|
-
evt = TaskArtifactUpdateEvent(
|
90
|
-
id=params.id,
|
91
|
-
artifact=Artifact(
|
92
|
-
parts=parts,
|
93
|
-
index=idx,
|
94
|
-
append=content_item.append or (state["index"] == idx),
|
95
|
-
lastChunk=content_item.final or state["last_chunk"],
|
96
|
-
metadata=content_item.metadata
|
97
|
-
)
|
98
|
-
)
|
99
|
-
if content_item.final:
|
100
|
-
state["last_chunk"] = True
|
101
|
-
state["index"] += 1
|
102
|
-
|
103
|
-
agent_msg = Message(role="agent", parts=evt.artifact.parts, metadata=evt.artifact.metadata)
|
104
|
-
new_hist = self.state_mgr.strategy.update_history(history, [agent_msg])
|
105
|
-
metadata = {**metadata, **(evt.artifact.metadata or {})}
|
106
|
-
self.state_mgr.update(StateData(session_id, new_hist, metadata))
|
107
|
-
history = new_hist
|
108
|
-
|
109
|
-
yield SendTaskStreamingResponse(jsonrpc="2.0", id=params.id, result=evt).model_dump_json()
|
@@ -1,103 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: smarta2a
|
3
|
-
Version: 0.3.0
|
4
|
-
Summary: A simple Python framework (built on top of FastAPI) for creating Agents following Google's Agent2Agent 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
|
-
# SmartA2A
|
26
|
-
|
27
|
-
A Python package for creating a server following Google's Agent2Agent protocol
|
28
|
-
|
29
|
-
## Features
|
30
|
-
|
31
|
-
✅ **Full A2A Protocol Compliance** - Implements all required endpoints and response formats
|
32
|
-
|
33
|
-
⚡ **Decorator-Driven Development** - Rapid endpoint configuration with type safety
|
34
|
-
|
35
|
-
🧩 **Automatic Protocol Conversion** - Simple returns become valid A2A responses
|
36
|
-
|
37
|
-
🔀 **Flexible Response Handling** - Support for Tasks, Artifacts, Streaming, and raw protocol types if needed!
|
38
|
-
|
39
|
-
🛡️ **Built-in Validation** - Automatic Pydantic validation of A2A schemas
|
40
|
-
|
41
|
-
⚡ **Single File Setup** - Get compliant in <10 lines of code
|
42
|
-
|
43
|
-
🌍 **Production Ready** - CORS, async support, and error handling included
|
44
|
-
|
45
|
-
## Installation
|
46
|
-
|
47
|
-
```bash
|
48
|
-
pip install smarta2a
|
49
|
-
```
|
50
|
-
|
51
|
-
## Simple Echo Server Implementation
|
52
|
-
|
53
|
-
```python
|
54
|
-
from smarta2a.server import SmartA2A
|
55
|
-
|
56
|
-
app = SmartA2A("EchoServer")
|
57
|
-
|
58
|
-
@app.on_send_task()
|
59
|
-
def handle_task(request):
|
60
|
-
"""Echo the input text back as a completed task"""
|
61
|
-
input_text = request.content[0].text
|
62
|
-
return f"Echo: {input_text}"
|
63
|
-
|
64
|
-
if __name__ == "__main__":
|
65
|
-
app.run()
|
66
|
-
```
|
67
|
-
|
68
|
-
Automatically contructs the response:
|
69
|
-
|
70
|
-
```json
|
71
|
-
{
|
72
|
-
"jsonrpc": "2.0",
|
73
|
-
"id": "test",
|
74
|
-
"result": {
|
75
|
-
"id": "echo-task",
|
76
|
-
"status": {"state": "completed"},
|
77
|
-
"artifacts": [{
|
78
|
-
"parts": [{"type": "text", "text": "Echo: Hello!"}]
|
79
|
-
}]
|
80
|
-
}
|
81
|
-
}
|
82
|
-
```
|
83
|
-
|
84
|
-
## Development
|
85
|
-
|
86
|
-
To set up the development environment:
|
87
|
-
|
88
|
-
```bash
|
89
|
-
# Clone the repository
|
90
|
-
git clone https://github.com/siddharthsma/smarta2a.git
|
91
|
-
cd smarta2a
|
92
|
-
|
93
|
-
# Create and activate virtual environment
|
94
|
-
python -m venv venv
|
95
|
-
source venv/bin/activate # On Windows: venv\Scripts\activate
|
96
|
-
|
97
|
-
# Install development dependencies
|
98
|
-
pip install -e ".[dev]"
|
99
|
-
```
|
100
|
-
|
101
|
-
## License
|
102
|
-
|
103
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
smarta2a-0.3.0.dist-info/RECORD
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
smarta2a/__init__.py,sha256=T_EECYqWrxshix0FbgUv22zlKRX22HFU-HKXcYTOb3w,175
|
2
|
-
smarta2a/agent/a2a_agent.py,sha256=zk6ZZtq4HrnKMDuZKnQPeKploV1IGXSZ1WmVPdIZAeY,1586
|
3
|
-
smarta2a/agent/a2a_mcp_server.py,sha256=X_mxkgYgCA_dSNtCvs0rSlOoWYc-8d3Qyxv0e-a7NKY,1015
|
4
|
-
smarta2a/archive/smart_mcp_client.py,sha256=NjyMR8xvrhy0-iFamj2XQnKp5qzkkFya7EQY4Kzl5dw,2574
|
5
|
-
smarta2a/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
-
smarta2a/client/a2a_client.py,sha256=Or2uF_ZK9WBvL-9QQ6HOTAuJy9yUL3Yyxtwqi8uGMMo,11040
|
7
|
-
smarta2a/client/mcp_client.py,sha256=ANjEzQFXEhKGQtNC9AjLI_IFtjv5twCCQhcB0TrwUpc,3534
|
8
|
-
smarta2a/client/tools_manager.py,sha256=TX4r0KIT9ZZa-P8OQ48ePEGzGJpCchLCr5t5o17Szww,2352
|
9
|
-
smarta2a/examples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
smarta2a/examples/echo_server/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
-
smarta2a/examples/echo_server/curl.txt,sha256=MYBbAgrU3PeCsksrrBc0xgaTD5Dro7xiTsCUz8Ocvt8,247
|
12
|
-
smarta2a/examples/echo_server/main.py,sha256=i_XLQbRAv6XxkJX0vLV3CxHNANG41yAxgP-V-b4Iysc,1261
|
13
|
-
smarta2a/examples/openai_delegator_agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
|
-
smarta2a/examples/openai_delegator_agent/main.py,sha256=8jXBJtzfgoCH45YDaXiTgvitVIDkqnVcX6lNvxQF0xQ,1220
|
15
|
-
smarta2a/examples/openai_weather_agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
16
|
-
smarta2a/examples/openai_weather_agent/main.py,sha256=o8QqLu9JC3zRXRPGWhYdd7mVl3ooys5UwkPCPv2JHmQ,796
|
17
|
-
smarta2a/history_update_strategies/__init__.py,sha256=x5WtiE9rG5ze8d8hA6E6wJOciBhWHa_ZgGgoIAZcXEQ,213
|
18
|
-
smarta2a/history_update_strategies/append_strategy.py,sha256=j7Qbhs69Wwr-HBLB8GJ3-mEPaBSHiBV2xz9ZZi86k2w,312
|
19
|
-
smarta2a/history_update_strategies/history_update_strategy.py,sha256=n2sfIGu8ztKI7gJTwRX26m4tZr28B8Xdhrk6RlBFlI8,373
|
20
|
-
smarta2a/model_providers/__init__.py,sha256=2FhblAUiwG9Xv27yEpuuz0VrnIZ-rlpgIuPwm-UIX5U,147
|
21
|
-
smarta2a/model_providers/base_llm_provider.py,sha256=6QjTUjYEnvHZji4_VWZz6CvLYKLyutxRUfIeH3seQg4,424
|
22
|
-
smarta2a/model_providers/openai_provider.py,sha256=oaJ5Yi5Bh5NGOo_sncevzQkhwqzeakOxVBWibB802Nc,10846
|
23
|
-
smarta2a/server/__init__.py,sha256=f2X454Ll4vJc02V4JLJHTN-h8u0TBm4d_FkiO4t686U,53
|
24
|
-
smarta2a/server/handler_registry.py,sha256=OVRG5dTvxB7qUNXgsqWxVNxIyRljUShSYxb1gtbi5XM,820
|
25
|
-
smarta2a/server/server.py,sha256=WJGQVOprF2Hh_036eW4GJrRr3fLC0S_B3dAfONCgZrs,32180
|
26
|
-
smarta2a/server/state_manager.py,sha256=Uc4BNr2kQvi7MAEh3CmHsKV2bP-Q8bYbGADQ35iHmZo,1350
|
27
|
-
smarta2a/server/subscription_service.py,sha256=fWqNNY0xmRksc_SZl4xt5fOPtZTQacfzou1-RMyaEd4,5188
|
28
|
-
smarta2a/server/task_service.py,sha256=TXVnFeS9ofAqH2z_7BOfk5uDmoZKv9irHHQSIuurI70,7650
|
29
|
-
smarta2a/state_stores/__init__.py,sha256=vafxAqpwvag_cYFH2XKGk3DPmJIWJr4Ioey30yLFkVQ,220
|
30
|
-
smarta2a/state_stores/base_state_store.py,sha256=LFI-LThPLf7M9z_CcXWCswajxMAtMx9tMFFVhZU0fM8,521
|
31
|
-
smarta2a/state_stores/inmemory_state_store.py,sha256=MgFGc7HxccrBxEqhVqKJ3bV-RnV1koU6iJd5m3rhhjA,682
|
32
|
-
smarta2a/utils/__init__.py,sha256=5db5VgDGgbMUGEF-xuyaC3qrgRQkUE9WAITkFSiNqSA,702
|
33
|
-
smarta2a/utils/prompt_helpers.py,sha256=jLETieoeBJLQXcGzwFeoKT5b2pS4tJ5770lPLImtKLo,1439
|
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/types.py,sha256=d04fNubP4BMmN5XTMYahwRHwNX2qcyEeiLzzQbpZppA,13177
|
37
|
-
smarta2a-0.3.0.dist-info/METADATA,sha256=T2O-Z72460TCVmCL_idl2H5Av_Tf7_uwY79zV0PtvoE,2726
|
38
|
-
smarta2a-0.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
39
|
-
smarta2a-0.3.0.dist-info/licenses/LICENSE,sha256=ECMEVHuFkvpEmH-_A9HSxs_UnnsUqpCkiAYNHPCf2z0,1078
|
40
|
-
smarta2a-0.3.0.dist-info/RECORD,,
|
@@ -1,21 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2025 Siddharth 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.
|
File without changes
|