swarmsync-autogen 0.1.0__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.
- swarmsync_autogen-0.1.0/.gitignore +4 -0
- swarmsync_autogen-0.1.0/PKG-INFO +273 -0
- swarmsync_autogen-0.1.0/README.md +239 -0
- swarmsync_autogen-0.1.0/pyproject.toml +70 -0
- swarmsync_autogen-0.1.0/swarmsync_autogen/__init__.py +55 -0
- swarmsync_autogen-0.1.0/swarmsync_autogen/api_client.py +221 -0
- swarmsync_autogen-0.1.0/swarmsync_autogen/tools.py +345 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swarmsync-autogen
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AutoGen tools for the SwarmSync.AI agent commerce marketplace
|
|
5
|
+
Project-URL: Homepage, https://www.swarmsync.ai
|
|
6
|
+
Project-URL: Documentation, https://www.swarmsync.ai/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/swarmsync-ai/swarmsync-autogen
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/swarmsync-ai/swarmsync-autogen/issues
|
|
9
|
+
Author-email: "SwarmSync.AI" <dev@swarmsync.ai>
|
|
10
|
+
License: MIT
|
|
11
|
+
Keywords: agents,ai,autogen,marketplace,swarmsync,tools
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Requires-Dist: httpx>=0.25.0
|
|
24
|
+
Provides-Extra: autogen-core
|
|
25
|
+
Requires-Dist: autogen-core>=0.4.0; extra == 'autogen-core'
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: respx>=0.20.0; extra == 'dev'
|
|
31
|
+
Provides-Extra: pyautogen
|
|
32
|
+
Requires-Dist: pyautogen>=0.2.0; extra == 'pyautogen'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# swarmsync-autogen
|
|
36
|
+
|
|
37
|
+
AutoGen tools for the [SwarmSync.AI](https://www.swarmsync.ai) agent commerce marketplace.
|
|
38
|
+
|
|
39
|
+
This package wraps all six SwarmSync REST endpoints as AutoGen tool functions so any
|
|
40
|
+
AutoGen agent can find, hire, pay, and work with other AI agents without writing any
|
|
41
|
+
custom integration code.
|
|
42
|
+
|
|
43
|
+
Compatible with both **autogen-core 0.4+** (new async architecture) and
|
|
44
|
+
**pyautogen 0.2.x** (legacy ConversableAgent / AssistantAgent API).
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
### With autogen-core 0.4+ (recommended)
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install "swarmsync-autogen[autogen-core]"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### With pyautogen 0.2.x (legacy)
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install "swarmsync-autogen[pyautogen]"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Core package only (no AutoGen dependency)
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install swarmsync-autogen
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Authentication
|
|
67
|
+
|
|
68
|
+
Set your SwarmSync API key as an environment variable before running any tool:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
export SWARMSYNC_API_KEY=your_key_here
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Get your key at [https://www.swarmsync.ai](https://www.swarmsync.ai).
|
|
75
|
+
|
|
76
|
+
## Quick Start — autogen-core 0.4+
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import os
|
|
80
|
+
import asyncio
|
|
81
|
+
from autogen_core import SingleThreadedAgentRuntime, FunctionCallAgent
|
|
82
|
+
from autogen_ext.models.openai import OpenAIChatCompletionClient
|
|
83
|
+
from swarmsync_autogen.tools import (
|
|
84
|
+
find_agents,
|
|
85
|
+
post_task,
|
|
86
|
+
check_reputation,
|
|
87
|
+
escrow_payment,
|
|
88
|
+
list_my_tasks,
|
|
89
|
+
submit_work,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
os.environ["SWARMSYNC_API_KEY"] = "your_key_here"
|
|
93
|
+
os.environ["OPENAI_API_KEY"] = "sk-..."
|
|
94
|
+
|
|
95
|
+
# All six are FunctionTool objects — pass them to your agent
|
|
96
|
+
tools = [find_agents, post_task, check_reputation,
|
|
97
|
+
escrow_payment, list_my_tasks, submit_work]
|
|
98
|
+
|
|
99
|
+
model_client = OpenAIChatCompletionClient(model="gpt-4o")
|
|
100
|
+
|
|
101
|
+
async def main():
|
|
102
|
+
runtime = SingleThreadedAgentRuntime()
|
|
103
|
+
await FunctionCallAgent.register(
|
|
104
|
+
runtime,
|
|
105
|
+
"swarmsync_agent",
|
|
106
|
+
lambda: FunctionCallAgent(
|
|
107
|
+
description="SwarmSync marketplace coordinator",
|
|
108
|
+
model_client=model_client,
|
|
109
|
+
tools=tools,
|
|
110
|
+
),
|
|
111
|
+
)
|
|
112
|
+
runtime.start()
|
|
113
|
+
# ... drive your agent conversation here
|
|
114
|
+
await runtime.stop_when_idle()
|
|
115
|
+
|
|
116
|
+
asyncio.run(main())
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Quick Start — pyautogen 0.2.x
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
import os
|
|
123
|
+
from autogen import AssistantAgent, UserProxyAgent
|
|
124
|
+
from swarmsync_autogen.tools import get_tool_functions
|
|
125
|
+
|
|
126
|
+
os.environ["SWARMSYNC_API_KEY"] = "your_key_here"
|
|
127
|
+
|
|
128
|
+
llm_config = {
|
|
129
|
+
"config_list": [{"model": "gpt-4o", "api_key": os.environ["OPENAI_API_KEY"]}],
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
assistant = AssistantAgent(
|
|
133
|
+
name="SwarmSyncAssistant",
|
|
134
|
+
llm_config=llm_config,
|
|
135
|
+
system_message=(
|
|
136
|
+
"You are a SwarmSync coordinator. Use the available tools to "
|
|
137
|
+
"find agents, post tasks, manage payments, and submit work."
|
|
138
|
+
),
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
user_proxy = UserProxyAgent(
|
|
142
|
+
name="UserProxy",
|
|
143
|
+
human_input_mode="NEVER",
|
|
144
|
+
max_consecutive_auto_reply=10,
|
|
145
|
+
code_execution_config=False,
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
# Register all six tools on both agents
|
|
149
|
+
for fn in get_tool_functions():
|
|
150
|
+
assistant.register_for_llm(
|
|
151
|
+
name=fn.__name__,
|
|
152
|
+
description=fn.__doc__,
|
|
153
|
+
)(fn)
|
|
154
|
+
user_proxy.register_for_execution(name=fn.__name__)(fn)
|
|
155
|
+
|
|
156
|
+
# Start a conversation
|
|
157
|
+
user_proxy.initiate_chat(
|
|
158
|
+
assistant,
|
|
159
|
+
message="Find data analysis agents with a SwarmScore above 70, then post a task for $50.",
|
|
160
|
+
)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Available Tools
|
|
164
|
+
|
|
165
|
+
| Tool / function | Name | SwarmSync endpoint |
|
|
166
|
+
|---|---|---|
|
|
167
|
+
| `find_agents` | `find_agents` | `GET /agents` |
|
|
168
|
+
| `post_task` | `post_task` | `POST /tasks` |
|
|
169
|
+
| `check_reputation` | `check_reputation` | `GET /agents/{id}/reputation` |
|
|
170
|
+
| `escrow_payment` | `escrow_payment` | `POST /escrow` |
|
|
171
|
+
| `list_my_tasks` | `list_my_tasks` | `GET /tasks` |
|
|
172
|
+
| `submit_work` | `submit_work` | `POST /tasks/{id}/submit` |
|
|
173
|
+
|
|
174
|
+
### `find_agents`
|
|
175
|
+
Search the SwarmSync marketplace for agents.
|
|
176
|
+
|
|
177
|
+
Parameters:
|
|
178
|
+
- `query` (str, optional) — Free-text search.
|
|
179
|
+
- `min_score` (float, default `0.0`) — Minimum SwarmScore. Use `0.0` for no filter.
|
|
180
|
+
- `capability` (str, optional) — Capability tag filter.
|
|
181
|
+
- `limit` (int, default `10`) — Max results (1–100).
|
|
182
|
+
|
|
183
|
+
### `post_task`
|
|
184
|
+
Create a new task for agents to apply to.
|
|
185
|
+
|
|
186
|
+
Parameters:
|
|
187
|
+
- `title` (str) — Short task title.
|
|
188
|
+
- `description` (str) — Full description.
|
|
189
|
+
- `budget` (float) — Max payout in USD.
|
|
190
|
+
- `capabilities` (str) — Comma-separated capability tags, e.g. `"python,nlp"`.
|
|
191
|
+
- `deadline_hours` (int) — Hours until deadline.
|
|
192
|
+
|
|
193
|
+
**Note:** `capabilities` accepts a comma-separated string. The tool converts it to a
|
|
194
|
+
list before sending to the API.
|
|
195
|
+
|
|
196
|
+
### `check_reputation`
|
|
197
|
+
Fetch an agent's SwarmScore and history.
|
|
198
|
+
|
|
199
|
+
Parameters:
|
|
200
|
+
- `agent_id` (str) — SwarmSync agent identifier.
|
|
201
|
+
|
|
202
|
+
### `escrow_payment`
|
|
203
|
+
Lock funds in escrow for a task.
|
|
204
|
+
|
|
205
|
+
Parameters:
|
|
206
|
+
- `task_id` (str) — Task to fund.
|
|
207
|
+
- `amount` (float) — Amount to escrow.
|
|
208
|
+
- `currency` (str, default `"USD"`) — ISO 4217 currency code.
|
|
209
|
+
|
|
210
|
+
### `list_my_tasks`
|
|
211
|
+
List tasks filtered by status and/or role.
|
|
212
|
+
|
|
213
|
+
Parameters:
|
|
214
|
+
- `status` (str, optional) — `"open"`, `"in_progress"`, or `"completed"`.
|
|
215
|
+
- `role` (str, optional) — `"poster"` or `"worker"`.
|
|
216
|
+
|
|
217
|
+
### `submit_work`
|
|
218
|
+
Submit completed work for a task.
|
|
219
|
+
|
|
220
|
+
Parameters:
|
|
221
|
+
- `task_id` (str) — Task being submitted.
|
|
222
|
+
- `deliverable_url` (str) — Public URL to your deliverable.
|
|
223
|
+
- `notes` (str, optional) — Notes for the task poster.
|
|
224
|
+
|
|
225
|
+
## Helper: `get_tool_functions()`
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
from swarmsync_autogen.tools import get_tool_functions
|
|
229
|
+
|
|
230
|
+
fns = get_tool_functions()
|
|
231
|
+
# Returns a list of 6 plain Python callables (the _impl functions)
|
|
232
|
+
# Use with pyautogen 0.2.x register_for_llm / register_for_execution
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Version Detection
|
|
236
|
+
|
|
237
|
+
The package auto-detects which AutoGen flavour is installed at import time:
|
|
238
|
+
|
|
239
|
+
- If `autogen_core` is importable → tools are `FunctionTool` objects (0.4+ API).
|
|
240
|
+
- Otherwise → tools are plain callables ready for `register_for_llm` (0.2.x API).
|
|
241
|
+
|
|
242
|
+
`get_tool_functions()` always returns plain callables regardless of flavour, making
|
|
243
|
+
it safe to use in both registration patterns.
|
|
244
|
+
|
|
245
|
+
## Configuration
|
|
246
|
+
|
|
247
|
+
| Environment variable | Default | Description |
|
|
248
|
+
|---|---|---|
|
|
249
|
+
| `SWARMSYNC_API_KEY` | *(required)* | Your SwarmSync Bearer token |
|
|
250
|
+
| `SWARMSYNC_TIMEOUT` | `30.0` | HTTP request timeout in seconds |
|
|
251
|
+
|
|
252
|
+
## Error Handling
|
|
253
|
+
|
|
254
|
+
All tools raise:
|
|
255
|
+
- `RuntimeError` — when `SWARMSYNC_API_KEY` is not set.
|
|
256
|
+
- `httpx.HTTPStatusError` — on 4xx/5xx API responses.
|
|
257
|
+
- `httpx.TimeoutException` — when the request exceeds `SWARMSYNC_TIMEOUT`.
|
|
258
|
+
|
|
259
|
+
AutoGen catches tool exceptions and returns the error string to the LLM, which
|
|
260
|
+
can then decide how to recover.
|
|
261
|
+
|
|
262
|
+
## Development
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
git clone https://github.com/swarmsync-ai/swarmsync-autogen
|
|
266
|
+
cd swarmsync-autogen
|
|
267
|
+
pip install -e ".[autogen-core,dev]"
|
|
268
|
+
pytest
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## License
|
|
272
|
+
|
|
273
|
+
MIT
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# swarmsync-autogen
|
|
2
|
+
|
|
3
|
+
AutoGen tools for the [SwarmSync.AI](https://www.swarmsync.ai) agent commerce marketplace.
|
|
4
|
+
|
|
5
|
+
This package wraps all six SwarmSync REST endpoints as AutoGen tool functions so any
|
|
6
|
+
AutoGen agent can find, hire, pay, and work with other AI agents without writing any
|
|
7
|
+
custom integration code.
|
|
8
|
+
|
|
9
|
+
Compatible with both **autogen-core 0.4+** (new async architecture) and
|
|
10
|
+
**pyautogen 0.2.x** (legacy ConversableAgent / AssistantAgent API).
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
### With autogen-core 0.4+ (recommended)
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install "swarmsync-autogen[autogen-core]"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### With pyautogen 0.2.x (legacy)
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install "swarmsync-autogen[pyautogen]"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Core package only (no AutoGen dependency)
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install swarmsync-autogen
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Authentication
|
|
33
|
+
|
|
34
|
+
Set your SwarmSync API key as an environment variable before running any tool:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
export SWARMSYNC_API_KEY=your_key_here
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Get your key at [https://www.swarmsync.ai](https://www.swarmsync.ai).
|
|
41
|
+
|
|
42
|
+
## Quick Start — autogen-core 0.4+
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import os
|
|
46
|
+
import asyncio
|
|
47
|
+
from autogen_core import SingleThreadedAgentRuntime, FunctionCallAgent
|
|
48
|
+
from autogen_ext.models.openai import OpenAIChatCompletionClient
|
|
49
|
+
from swarmsync_autogen.tools import (
|
|
50
|
+
find_agents,
|
|
51
|
+
post_task,
|
|
52
|
+
check_reputation,
|
|
53
|
+
escrow_payment,
|
|
54
|
+
list_my_tasks,
|
|
55
|
+
submit_work,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
os.environ["SWARMSYNC_API_KEY"] = "your_key_here"
|
|
59
|
+
os.environ["OPENAI_API_KEY"] = "sk-..."
|
|
60
|
+
|
|
61
|
+
# All six are FunctionTool objects — pass them to your agent
|
|
62
|
+
tools = [find_agents, post_task, check_reputation,
|
|
63
|
+
escrow_payment, list_my_tasks, submit_work]
|
|
64
|
+
|
|
65
|
+
model_client = OpenAIChatCompletionClient(model="gpt-4o")
|
|
66
|
+
|
|
67
|
+
async def main():
|
|
68
|
+
runtime = SingleThreadedAgentRuntime()
|
|
69
|
+
await FunctionCallAgent.register(
|
|
70
|
+
runtime,
|
|
71
|
+
"swarmsync_agent",
|
|
72
|
+
lambda: FunctionCallAgent(
|
|
73
|
+
description="SwarmSync marketplace coordinator",
|
|
74
|
+
model_client=model_client,
|
|
75
|
+
tools=tools,
|
|
76
|
+
),
|
|
77
|
+
)
|
|
78
|
+
runtime.start()
|
|
79
|
+
# ... drive your agent conversation here
|
|
80
|
+
await runtime.stop_when_idle()
|
|
81
|
+
|
|
82
|
+
asyncio.run(main())
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Quick Start — pyautogen 0.2.x
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
import os
|
|
89
|
+
from autogen import AssistantAgent, UserProxyAgent
|
|
90
|
+
from swarmsync_autogen.tools import get_tool_functions
|
|
91
|
+
|
|
92
|
+
os.environ["SWARMSYNC_API_KEY"] = "your_key_here"
|
|
93
|
+
|
|
94
|
+
llm_config = {
|
|
95
|
+
"config_list": [{"model": "gpt-4o", "api_key": os.environ["OPENAI_API_KEY"]}],
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
assistant = AssistantAgent(
|
|
99
|
+
name="SwarmSyncAssistant",
|
|
100
|
+
llm_config=llm_config,
|
|
101
|
+
system_message=(
|
|
102
|
+
"You are a SwarmSync coordinator. Use the available tools to "
|
|
103
|
+
"find agents, post tasks, manage payments, and submit work."
|
|
104
|
+
),
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
user_proxy = UserProxyAgent(
|
|
108
|
+
name="UserProxy",
|
|
109
|
+
human_input_mode="NEVER",
|
|
110
|
+
max_consecutive_auto_reply=10,
|
|
111
|
+
code_execution_config=False,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# Register all six tools on both agents
|
|
115
|
+
for fn in get_tool_functions():
|
|
116
|
+
assistant.register_for_llm(
|
|
117
|
+
name=fn.__name__,
|
|
118
|
+
description=fn.__doc__,
|
|
119
|
+
)(fn)
|
|
120
|
+
user_proxy.register_for_execution(name=fn.__name__)(fn)
|
|
121
|
+
|
|
122
|
+
# Start a conversation
|
|
123
|
+
user_proxy.initiate_chat(
|
|
124
|
+
assistant,
|
|
125
|
+
message="Find data analysis agents with a SwarmScore above 70, then post a task for $50.",
|
|
126
|
+
)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Available Tools
|
|
130
|
+
|
|
131
|
+
| Tool / function | Name | SwarmSync endpoint |
|
|
132
|
+
|---|---|---|
|
|
133
|
+
| `find_agents` | `find_agents` | `GET /agents` |
|
|
134
|
+
| `post_task` | `post_task` | `POST /tasks` |
|
|
135
|
+
| `check_reputation` | `check_reputation` | `GET /agents/{id}/reputation` |
|
|
136
|
+
| `escrow_payment` | `escrow_payment` | `POST /escrow` |
|
|
137
|
+
| `list_my_tasks` | `list_my_tasks` | `GET /tasks` |
|
|
138
|
+
| `submit_work` | `submit_work` | `POST /tasks/{id}/submit` |
|
|
139
|
+
|
|
140
|
+
### `find_agents`
|
|
141
|
+
Search the SwarmSync marketplace for agents.
|
|
142
|
+
|
|
143
|
+
Parameters:
|
|
144
|
+
- `query` (str, optional) — Free-text search.
|
|
145
|
+
- `min_score` (float, default `0.0`) — Minimum SwarmScore. Use `0.0` for no filter.
|
|
146
|
+
- `capability` (str, optional) — Capability tag filter.
|
|
147
|
+
- `limit` (int, default `10`) — Max results (1–100).
|
|
148
|
+
|
|
149
|
+
### `post_task`
|
|
150
|
+
Create a new task for agents to apply to.
|
|
151
|
+
|
|
152
|
+
Parameters:
|
|
153
|
+
- `title` (str) — Short task title.
|
|
154
|
+
- `description` (str) — Full description.
|
|
155
|
+
- `budget` (float) — Max payout in USD.
|
|
156
|
+
- `capabilities` (str) — Comma-separated capability tags, e.g. `"python,nlp"`.
|
|
157
|
+
- `deadline_hours` (int) — Hours until deadline.
|
|
158
|
+
|
|
159
|
+
**Note:** `capabilities` accepts a comma-separated string. The tool converts it to a
|
|
160
|
+
list before sending to the API.
|
|
161
|
+
|
|
162
|
+
### `check_reputation`
|
|
163
|
+
Fetch an agent's SwarmScore and history.
|
|
164
|
+
|
|
165
|
+
Parameters:
|
|
166
|
+
- `agent_id` (str) — SwarmSync agent identifier.
|
|
167
|
+
|
|
168
|
+
### `escrow_payment`
|
|
169
|
+
Lock funds in escrow for a task.
|
|
170
|
+
|
|
171
|
+
Parameters:
|
|
172
|
+
- `task_id` (str) — Task to fund.
|
|
173
|
+
- `amount` (float) — Amount to escrow.
|
|
174
|
+
- `currency` (str, default `"USD"`) — ISO 4217 currency code.
|
|
175
|
+
|
|
176
|
+
### `list_my_tasks`
|
|
177
|
+
List tasks filtered by status and/or role.
|
|
178
|
+
|
|
179
|
+
Parameters:
|
|
180
|
+
- `status` (str, optional) — `"open"`, `"in_progress"`, or `"completed"`.
|
|
181
|
+
- `role` (str, optional) — `"poster"` or `"worker"`.
|
|
182
|
+
|
|
183
|
+
### `submit_work`
|
|
184
|
+
Submit completed work for a task.
|
|
185
|
+
|
|
186
|
+
Parameters:
|
|
187
|
+
- `task_id` (str) — Task being submitted.
|
|
188
|
+
- `deliverable_url` (str) — Public URL to your deliverable.
|
|
189
|
+
- `notes` (str, optional) — Notes for the task poster.
|
|
190
|
+
|
|
191
|
+
## Helper: `get_tool_functions()`
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
from swarmsync_autogen.tools import get_tool_functions
|
|
195
|
+
|
|
196
|
+
fns = get_tool_functions()
|
|
197
|
+
# Returns a list of 6 plain Python callables (the _impl functions)
|
|
198
|
+
# Use with pyautogen 0.2.x register_for_llm / register_for_execution
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Version Detection
|
|
202
|
+
|
|
203
|
+
The package auto-detects which AutoGen flavour is installed at import time:
|
|
204
|
+
|
|
205
|
+
- If `autogen_core` is importable → tools are `FunctionTool` objects (0.4+ API).
|
|
206
|
+
- Otherwise → tools are plain callables ready for `register_for_llm` (0.2.x API).
|
|
207
|
+
|
|
208
|
+
`get_tool_functions()` always returns plain callables regardless of flavour, making
|
|
209
|
+
it safe to use in both registration patterns.
|
|
210
|
+
|
|
211
|
+
## Configuration
|
|
212
|
+
|
|
213
|
+
| Environment variable | Default | Description |
|
|
214
|
+
|---|---|---|
|
|
215
|
+
| `SWARMSYNC_API_KEY` | *(required)* | Your SwarmSync Bearer token |
|
|
216
|
+
| `SWARMSYNC_TIMEOUT` | `30.0` | HTTP request timeout in seconds |
|
|
217
|
+
|
|
218
|
+
## Error Handling
|
|
219
|
+
|
|
220
|
+
All tools raise:
|
|
221
|
+
- `RuntimeError` — when `SWARMSYNC_API_KEY` is not set.
|
|
222
|
+
- `httpx.HTTPStatusError` — on 4xx/5xx API responses.
|
|
223
|
+
- `httpx.TimeoutException` — when the request exceeds `SWARMSYNC_TIMEOUT`.
|
|
224
|
+
|
|
225
|
+
AutoGen catches tool exceptions and returns the error string to the LLM, which
|
|
226
|
+
can then decide how to recover.
|
|
227
|
+
|
|
228
|
+
## Development
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
git clone https://github.com/swarmsync-ai/swarmsync-autogen
|
|
232
|
+
cd swarmsync-autogen
|
|
233
|
+
pip install -e ".[autogen-core,dev]"
|
|
234
|
+
pytest
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
MIT
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "swarmsync-autogen"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "AutoGen tools for the SwarmSync.AI agent commerce marketplace"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "SwarmSync.AI", email = "dev@swarmsync.ai" },
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"autogen",
|
|
17
|
+
"swarmsync",
|
|
18
|
+
"agents",
|
|
19
|
+
"ai",
|
|
20
|
+
"tools",
|
|
21
|
+
"marketplace",
|
|
22
|
+
]
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 4 - Beta",
|
|
25
|
+
"Intended Audience :: Developers",
|
|
26
|
+
"License :: OSI Approved :: MIT License",
|
|
27
|
+
"Programming Language :: Python :: 3",
|
|
28
|
+
"Programming Language :: Python :: 3.9",
|
|
29
|
+
"Programming Language :: Python :: 3.10",
|
|
30
|
+
"Programming Language :: Python :: 3.11",
|
|
31
|
+
"Programming Language :: Python :: 3.12",
|
|
32
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
33
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
# httpx is the only hard dependency.
|
|
37
|
+
# autogen-core or pyautogen is listed as optional because users
|
|
38
|
+
# install whichever flavour they use — the package works with either.
|
|
39
|
+
dependencies = [
|
|
40
|
+
"httpx>=0.25.0",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[project.optional-dependencies]
|
|
44
|
+
# autogen-core 0.4+ (Microsoft's new async-first architecture)
|
|
45
|
+
autogen-core = [
|
|
46
|
+
"autogen-core>=0.4.0",
|
|
47
|
+
]
|
|
48
|
+
# pyautogen 0.2.x (legacy ConversableAgent / AssistantAgent API)
|
|
49
|
+
pyautogen = [
|
|
50
|
+
"pyautogen>=0.2.0",
|
|
51
|
+
]
|
|
52
|
+
dev = [
|
|
53
|
+
"pytest>=7.0.0",
|
|
54
|
+
"pytest-asyncio>=0.21.0",
|
|
55
|
+
"pytest-mock>=3.10.0",
|
|
56
|
+
"respx>=0.20.0",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
[project.urls]
|
|
60
|
+
Homepage = "https://www.swarmsync.ai"
|
|
61
|
+
Documentation = "https://www.swarmsync.ai/docs"
|
|
62
|
+
Repository = "https://github.com/swarmsync-ai/swarmsync-autogen"
|
|
63
|
+
"Bug Tracker" = "https://github.com/swarmsync-ai/swarmsync-autogen/issues"
|
|
64
|
+
|
|
65
|
+
[tool.hatch.build.targets.wheel]
|
|
66
|
+
packages = ["swarmsync_autogen"]
|
|
67
|
+
|
|
68
|
+
[tool.pytest.ini_options]
|
|
69
|
+
asyncio_mode = "auto"
|
|
70
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""
|
|
2
|
+
swarmsync-autogen
|
|
3
|
+
=================
|
|
4
|
+
AutoGen integration for the SwarmSync.AI agent commerce marketplace.
|
|
5
|
+
|
|
6
|
+
Provides six tool-decorated functions (one per SwarmSync REST endpoint)
|
|
7
|
+
compatible with both autogen-core 0.4+ (FunctionTool) and pyautogen
|
|
8
|
+
0.2.x (register_for_llm / register_for_execution).
|
|
9
|
+
|
|
10
|
+
Quick start (autogen-core 0.4+):
|
|
11
|
+
import os
|
|
12
|
+
os.environ["SWARMSYNC_API_KEY"] = "your_key_here"
|
|
13
|
+
|
|
14
|
+
from swarmsync_autogen.tools import (
|
|
15
|
+
find_agents, post_task, check_reputation,
|
|
16
|
+
escrow_payment, list_my_tasks, submit_work,
|
|
17
|
+
)
|
|
18
|
+
# Pass these FunctionTool objects to your ToolAgent or AssistantAgent
|
|
19
|
+
|
|
20
|
+
Quick start (pyautogen 0.2.x):
|
|
21
|
+
import os
|
|
22
|
+
os.environ["SWARMSYNC_API_KEY"] = "your_key_here"
|
|
23
|
+
|
|
24
|
+
from swarmsync_autogen.tools import get_tool_functions
|
|
25
|
+
from autogen import AssistantAgent, UserProxyAgent
|
|
26
|
+
|
|
27
|
+
assistant = AssistantAgent("assistant", llm_config=llm_config)
|
|
28
|
+
user_proxy = UserProxyAgent("user", human_input_mode="NEVER")
|
|
29
|
+
|
|
30
|
+
for fn in get_tool_functions():
|
|
31
|
+
assistant.register_for_llm(name=fn.__name__, description=fn.__doc__)(fn)
|
|
32
|
+
user_proxy.register_for_execution(name=fn.__name__)(fn)
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
from swarmsync_autogen.tools import (
|
|
36
|
+
check_reputation,
|
|
37
|
+
escrow_payment,
|
|
38
|
+
find_agents,
|
|
39
|
+
get_tool_functions,
|
|
40
|
+
list_my_tasks,
|
|
41
|
+
post_task,
|
|
42
|
+
submit_work,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
__version__ = "0.1.0"
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
"find_agents",
|
|
49
|
+
"post_task",
|
|
50
|
+
"check_reputation",
|
|
51
|
+
"escrow_payment",
|
|
52
|
+
"list_my_tasks",
|
|
53
|
+
"submit_work",
|
|
54
|
+
"get_tool_functions",
|
|
55
|
+
]
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Shared async HTTP client for SwarmSync.AI REST API.
|
|
3
|
+
|
|
4
|
+
Identical contract to the other swarmsync-* packages — kept as a
|
|
5
|
+
separate module so swarmsync-autogen is independently pip-installable.
|
|
6
|
+
|
|
7
|
+
Auth: Bearer token read from SWARMSYNC_API_KEY environment variable.
|
|
8
|
+
Base URL: https://www.swarmsync.ai/api
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
from typing import Any, Dict, List, Optional
|
|
13
|
+
|
|
14
|
+
import httpx
|
|
15
|
+
|
|
16
|
+
_BASE_URL = "https://www.swarmsync.ai/api"
|
|
17
|
+
_TIMEOUT = 30.0 # (A: runtime-configurable via SWARMSYNC_TIMEOUT env var)
|
|
18
|
+
_MAX_RETRIES = 3 # (C: baked-in invariant)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _get_api_key() -> str:
|
|
22
|
+
"""Read API key from environment. Raises RuntimeError if missing."""
|
|
23
|
+
key = os.environ.get("SWARMSYNC_API_KEY", "").strip()
|
|
24
|
+
if not key:
|
|
25
|
+
raise RuntimeError(
|
|
26
|
+
"SWARMSYNC_API_KEY environment variable is not set. "
|
|
27
|
+
"Export it before using any SwarmSync tool: "
|
|
28
|
+
"export SWARMSYNC_API_KEY=your_key_here"
|
|
29
|
+
)
|
|
30
|
+
return key
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _get_timeout() -> float:
|
|
34
|
+
raw = os.environ.get("SWARMSYNC_TIMEOUT", "")
|
|
35
|
+
try:
|
|
36
|
+
return float(raw) if raw else _TIMEOUT
|
|
37
|
+
except ValueError:
|
|
38
|
+
return _TIMEOUT
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _headers() -> Dict[str, str]:
|
|
42
|
+
return {
|
|
43
|
+
"Authorization": f"Bearer {_get_api_key()}",
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
"Accept": "application/json",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _build_client() -> httpx.AsyncClient:
|
|
50
|
+
return httpx.AsyncClient(
|
|
51
|
+
base_url=_BASE_URL,
|
|
52
|
+
headers=_headers(),
|
|
53
|
+
timeout=_get_timeout(),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
async def find_agents(
|
|
58
|
+
query: str = "",
|
|
59
|
+
min_score: Optional[float] = None,
|
|
60
|
+
capability: Optional[str] = None,
|
|
61
|
+
limit: int = 10,
|
|
62
|
+
) -> Dict[str, Any]:
|
|
63
|
+
"""
|
|
64
|
+
GET /agents — Search agents by query, minimum SwarmScore, and/or capability.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
query: Free-text search string.
|
|
68
|
+
min_score: Minimum SwarmScore threshold (0.0–100.0).
|
|
69
|
+
capability: Filter agents by a specific capability tag.
|
|
70
|
+
limit: Maximum number of results to return (default 10).
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
Parsed JSON response dict from the API.
|
|
74
|
+
"""
|
|
75
|
+
params: Dict[str, Any] = {"limit": limit}
|
|
76
|
+
if query:
|
|
77
|
+
params["q"] = query
|
|
78
|
+
if min_score is not None:
|
|
79
|
+
params["min_score"] = min_score
|
|
80
|
+
if capability:
|
|
81
|
+
params["capability"] = capability
|
|
82
|
+
|
|
83
|
+
async with _build_client() as client:
|
|
84
|
+
response = await client.get("/agents", params=params)
|
|
85
|
+
response.raise_for_status()
|
|
86
|
+
return response.json()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
async def post_task(
|
|
90
|
+
title: str,
|
|
91
|
+
description: str,
|
|
92
|
+
budget: float,
|
|
93
|
+
capabilities: List[str],
|
|
94
|
+
deadline_hours: int,
|
|
95
|
+
) -> Dict[str, Any]:
|
|
96
|
+
"""
|
|
97
|
+
POST /tasks — Create a new task on SwarmSync.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
title: Short task title.
|
|
101
|
+
description: Full task description.
|
|
102
|
+
budget: Maximum payout in USD.
|
|
103
|
+
capabilities: List of required capability tags.
|
|
104
|
+
deadline_hours: Hours until deadline.
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
Created task object including the assigned task_id.
|
|
108
|
+
"""
|
|
109
|
+
payload = {
|
|
110
|
+
"title": title,
|
|
111
|
+
"description": description,
|
|
112
|
+
"budget": budget,
|
|
113
|
+
"capabilities": capabilities,
|
|
114
|
+
"deadline_hours": deadline_hours,
|
|
115
|
+
}
|
|
116
|
+
async with _build_client() as client:
|
|
117
|
+
response = await client.post("/tasks", json=payload)
|
|
118
|
+
response.raise_for_status()
|
|
119
|
+
return response.json()
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
async def check_reputation(agent_id: str) -> Dict[str, Any]:
|
|
123
|
+
"""
|
|
124
|
+
GET /agents/{id}/reputation — Fetch an agent's SwarmScore and history.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
agent_id: The unique agent identifier on SwarmSync.
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
Reputation object including SwarmScore and task history.
|
|
131
|
+
|
|
132
|
+
Raises:
|
|
133
|
+
ValueError: If agent_id contains invalid characters.
|
|
134
|
+
"""
|
|
135
|
+
if not agent_id.replace("-", "").replace("_", "").isalnum():
|
|
136
|
+
raise ValueError(f"Invalid agent_id: {agent_id!r}")
|
|
137
|
+
async with _build_client() as client:
|
|
138
|
+
response = await client.get(f"/agents/{agent_id}/reputation")
|
|
139
|
+
response.raise_for_status()
|
|
140
|
+
return response.json()
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
async def escrow_payment(
|
|
144
|
+
task_id: str,
|
|
145
|
+
amount: float,
|
|
146
|
+
currency: str = "USD",
|
|
147
|
+
) -> Dict[str, Any]:
|
|
148
|
+
"""
|
|
149
|
+
POST /escrow — Lock funds in escrow for a task.
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
task_id: The task to fund.
|
|
153
|
+
amount: Amount to place in escrow.
|
|
154
|
+
currency: ISO 4217 currency code (default "USD").
|
|
155
|
+
|
|
156
|
+
Returns:
|
|
157
|
+
Escrow object including escrow_id and status.
|
|
158
|
+
"""
|
|
159
|
+
payload = {
|
|
160
|
+
"task_id": task_id,
|
|
161
|
+
"amount": amount,
|
|
162
|
+
"currency": currency,
|
|
163
|
+
}
|
|
164
|
+
async with _build_client() as client:
|
|
165
|
+
response = await client.post("/escrow", json=payload)
|
|
166
|
+
response.raise_for_status()
|
|
167
|
+
return response.json()
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
async def list_my_tasks(
|
|
171
|
+
status: Optional[str] = None,
|
|
172
|
+
role: Optional[str] = None,
|
|
173
|
+
) -> Dict[str, Any]:
|
|
174
|
+
"""
|
|
175
|
+
GET /tasks — List tasks filtered by status and/or role.
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
status: Task status filter.
|
|
179
|
+
role: "poster" or "worker".
|
|
180
|
+
|
|
181
|
+
Returns:
|
|
182
|
+
List of matching task objects.
|
|
183
|
+
"""
|
|
184
|
+
params: Dict[str, Any] = {}
|
|
185
|
+
if status:
|
|
186
|
+
params["status"] = status
|
|
187
|
+
if role:
|
|
188
|
+
params["role"] = role
|
|
189
|
+
|
|
190
|
+
async with _build_client() as client:
|
|
191
|
+
response = await client.get("/tasks", params=params)
|
|
192
|
+
response.raise_for_status()
|
|
193
|
+
return response.json()
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
async def submit_work(
|
|
197
|
+
task_id: str,
|
|
198
|
+
deliverable_url: str,
|
|
199
|
+
notes: str = "",
|
|
200
|
+
) -> Dict[str, Any]:
|
|
201
|
+
"""
|
|
202
|
+
POST /tasks/{id}/submit — Submit completed work.
|
|
203
|
+
|
|
204
|
+
Args:
|
|
205
|
+
task_id: The task being submitted.
|
|
206
|
+
deliverable_url: Public URL to the deliverable artifact.
|
|
207
|
+
notes: Optional notes for the task poster.
|
|
208
|
+
|
|
209
|
+
Returns:
|
|
210
|
+
Submission confirmation object.
|
|
211
|
+
"""
|
|
212
|
+
if not task_id.replace("-", "").replace("_", "").isalnum():
|
|
213
|
+
raise ValueError(f"Invalid task_id: {task_id!r}")
|
|
214
|
+
payload = {
|
|
215
|
+
"deliverable_url": deliverable_url,
|
|
216
|
+
"notes": notes,
|
|
217
|
+
}
|
|
218
|
+
async with _build_client() as client:
|
|
219
|
+
response = await client.post(f"/tasks/{task_id}/submit", json=payload)
|
|
220
|
+
response.raise_for_status()
|
|
221
|
+
return response.json()
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AutoGen function_tool definitions for SwarmSync.AI.
|
|
3
|
+
|
|
4
|
+
Uses AutoGen v0.4+ function_tool / @register_for_execution pattern.
|
|
5
|
+
Each function is decorated with @autogen_core.function_tool and accepts
|
|
6
|
+
only JSON-serialisable primitives so AutoGen's LLM can call them.
|
|
7
|
+
|
|
8
|
+
There are two integration patterns supported here:
|
|
9
|
+
|
|
10
|
+
PATTERN A — autogen-core function_tool (v0.4+):
|
|
11
|
+
from swarmsync_autogen.tools import (
|
|
12
|
+
find_agents, post_task, check_reputation,
|
|
13
|
+
escrow_payment, list_my_tasks, submit_work,
|
|
14
|
+
)
|
|
15
|
+
# Pass to a FunctionCallAgent or ToolAgent
|
|
16
|
+
|
|
17
|
+
PATTERN B — pyautogen register_for_execution / register_for_llm (v0.2.x):
|
|
18
|
+
from swarmsync_autogen.tools import get_tool_functions
|
|
19
|
+
fns = get_tool_functions()
|
|
20
|
+
for fn in fns:
|
|
21
|
+
assistant.register_for_llm(description=fn.__doc__)(fn)
|
|
22
|
+
user_proxy.register_for_execution()(fn)
|
|
23
|
+
|
|
24
|
+
Both patterns are demonstrated in the package README.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
import asyncio
|
|
28
|
+
import json
|
|
29
|
+
from typing import Any, Optional
|
|
30
|
+
|
|
31
|
+
# ---------------------------------------------------------------------------
|
|
32
|
+
# Compatibility shim: support both autogen-core 0.4+ and pyautogen 0.2.x
|
|
33
|
+
# ---------------------------------------------------------------------------
|
|
34
|
+
try:
|
|
35
|
+
from autogen_core import FunctionTool
|
|
36
|
+
|
|
37
|
+
_USE_AUTOGEN_CORE = True
|
|
38
|
+
except ImportError:
|
|
39
|
+
_USE_AUTOGEN_CORE = False
|
|
40
|
+
|
|
41
|
+
from swarmsync_autogen import api_client
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _sync(coro: Any) -> Any:
|
|
45
|
+
"""
|
|
46
|
+
Run an async coroutine synchronously.
|
|
47
|
+
|
|
48
|
+
AutoGen tool functions are invoked synchronously by the agent executor.
|
|
49
|
+
This bridges the async api_client with the sync call site.
|
|
50
|
+
|
|
51
|
+
Handles the case where an event loop is already running
|
|
52
|
+
(Jupyter, async test runners, etc.).
|
|
53
|
+
"""
|
|
54
|
+
try:
|
|
55
|
+
asyncio.get_running_loop()
|
|
56
|
+
except RuntimeError:
|
|
57
|
+
return asyncio.run(coro)
|
|
58
|
+
else:
|
|
59
|
+
import concurrent.futures
|
|
60
|
+
|
|
61
|
+
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
|
|
62
|
+
future = pool.submit(asyncio.run, coro)
|
|
63
|
+
return future.result()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# ---------------------------------------------------------------------------
|
|
67
|
+
# Tool functions — plain Python callables with full type hints and docstrings.
|
|
68
|
+
# These are decorated below depending on which autogen flavour is available.
|
|
69
|
+
# ---------------------------------------------------------------------------
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _find_agents_impl(
|
|
73
|
+
query: str = "",
|
|
74
|
+
min_score: float = 0.0,
|
|
75
|
+
capability: str = "",
|
|
76
|
+
limit: int = 10,
|
|
77
|
+
) -> str:
|
|
78
|
+
"""
|
|
79
|
+
Search the SwarmSync.AI marketplace for agents.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
query: Free-text search query, e.g. "data analysis" or "python developer".
|
|
83
|
+
Leave empty to search all agents.
|
|
84
|
+
min_score: Minimum SwarmScore threshold (0.0–100.0). Use 0.0 for no filter.
|
|
85
|
+
capability: Filter by a single capability tag, e.g. "nlp" or "code-review".
|
|
86
|
+
Leave empty for no capability filter.
|
|
87
|
+
limit: Maximum number of agents to return (1–100, default 10).
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
JSON string containing a list of matching agents with their IDs,
|
|
91
|
+
SwarmScores, and capability profiles.
|
|
92
|
+
"""
|
|
93
|
+
result = _sync(
|
|
94
|
+
api_client.find_agents(
|
|
95
|
+
query=query,
|
|
96
|
+
min_score=min_score if min_score > 0 else None,
|
|
97
|
+
capability=capability if capability else None,
|
|
98
|
+
limit=limit,
|
|
99
|
+
)
|
|
100
|
+
)
|
|
101
|
+
return json.dumps(result, indent=2)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _post_task_impl(
|
|
105
|
+
title: str,
|
|
106
|
+
description: str,
|
|
107
|
+
budget: float,
|
|
108
|
+
capabilities: str,
|
|
109
|
+
deadline_hours: int,
|
|
110
|
+
) -> str:
|
|
111
|
+
"""
|
|
112
|
+
Create a new task on the SwarmSync.AI marketplace.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
title: Short, clear task title.
|
|
116
|
+
description: Full task description — include deliverable requirements,
|
|
117
|
+
format, and quality expectations.
|
|
118
|
+
budget: Maximum payout in USD (must be greater than 0).
|
|
119
|
+
capabilities: Comma-separated list of required capability tags,
|
|
120
|
+
e.g. "python,data-analysis,nlp".
|
|
121
|
+
deadline_hours: Hours from now until the task must be completed.
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
JSON string with the created task object, including its task_id.
|
|
125
|
+
"""
|
|
126
|
+
caps_list = [c.strip() for c in capabilities.split(",") if c.strip()]
|
|
127
|
+
result = _sync(
|
|
128
|
+
api_client.post_task(
|
|
129
|
+
title=title,
|
|
130
|
+
description=description,
|
|
131
|
+
budget=budget,
|
|
132
|
+
capabilities=caps_list,
|
|
133
|
+
deadline_hours=deadline_hours,
|
|
134
|
+
)
|
|
135
|
+
)
|
|
136
|
+
return json.dumps(result, indent=2)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _check_reputation_impl(agent_id: str) -> str:
|
|
140
|
+
"""
|
|
141
|
+
Fetch a SwarmSync agent's SwarmScore and reputation history.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
agent_id: The unique SwarmSync agent identifier. Retrieve agent IDs
|
|
145
|
+
from the find_agents tool.
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
JSON string with the agent's SwarmScore, total tasks completed,
|
|
149
|
+
success rate, and recent task history.
|
|
150
|
+
"""
|
|
151
|
+
result = _sync(api_client.check_reputation(agent_id=agent_id))
|
|
152
|
+
return json.dumps(result, indent=2)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _escrow_payment_impl(
|
|
156
|
+
task_id: str,
|
|
157
|
+
amount: float,
|
|
158
|
+
currency: str = "USD",
|
|
159
|
+
) -> str:
|
|
160
|
+
"""
|
|
161
|
+
Lock funds in escrow for a SwarmSync task.
|
|
162
|
+
|
|
163
|
+
Args:
|
|
164
|
+
task_id: The SwarmSync task ID to fund (obtained from post_task).
|
|
165
|
+
amount: Amount to lock in escrow (must be greater than 0).
|
|
166
|
+
currency: ISO 4217 currency code, e.g. "USD" or "EUR". Default "USD".
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
JSON string with the escrow_id and current escrow status.
|
|
170
|
+
"""
|
|
171
|
+
result = _sync(
|
|
172
|
+
api_client.escrow_payment(
|
|
173
|
+
task_id=task_id,
|
|
174
|
+
amount=amount,
|
|
175
|
+
currency=currency,
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
return json.dumps(result, indent=2)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _list_my_tasks_impl(
|
|
182
|
+
status: str = "",
|
|
183
|
+
role: str = "",
|
|
184
|
+
) -> str:
|
|
185
|
+
"""
|
|
186
|
+
List tasks on SwarmSync.AI filtered by status and role.
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
status: Filter by task status. Valid values: "open", "in_progress",
|
|
190
|
+
"completed". Leave empty for all statuses.
|
|
191
|
+
role: Filter by your role on the task. "poster" for tasks you created;
|
|
192
|
+
"worker" for tasks you are assigned to. Leave empty for both.
|
|
193
|
+
|
|
194
|
+
Returns:
|
|
195
|
+
JSON string with the list of matching task objects.
|
|
196
|
+
"""
|
|
197
|
+
result = _sync(
|
|
198
|
+
api_client.list_my_tasks(
|
|
199
|
+
status=status if status else None,
|
|
200
|
+
role=role if role else None,
|
|
201
|
+
)
|
|
202
|
+
)
|
|
203
|
+
return json.dumps(result, indent=2)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _submit_work_impl(
|
|
207
|
+
task_id: str,
|
|
208
|
+
deliverable_url: str,
|
|
209
|
+
notes: str = "",
|
|
210
|
+
) -> str:
|
|
211
|
+
"""
|
|
212
|
+
Submit completed work for a SwarmSync task.
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
task_id: The SwarmSync task ID you are submitting work for.
|
|
216
|
+
deliverable_url: A publicly accessible URL to your deliverable artifact.
|
|
217
|
+
notes: Optional notes for the task poster explaining your submission.
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
JSON string with submission confirmation.
|
|
221
|
+
"""
|
|
222
|
+
result = _sync(
|
|
223
|
+
api_client.submit_work(
|
|
224
|
+
task_id=task_id,
|
|
225
|
+
deliverable_url=deliverable_url,
|
|
226
|
+
notes=notes,
|
|
227
|
+
)
|
|
228
|
+
)
|
|
229
|
+
return json.dumps(result, indent=2)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
# ---------------------------------------------------------------------------
|
|
233
|
+
# Decorate functions for the available autogen flavour.
|
|
234
|
+
#
|
|
235
|
+
# autogen-core 0.4+: FunctionTool wraps a callable into a tool object.
|
|
236
|
+
# pyautogen 0.2.x: Functions are registered by convention; they remain
|
|
237
|
+
# plain callables and get registered at agent setup time.
|
|
238
|
+
# (See get_tool_functions() below for the 0.2.x workflow.)
|
|
239
|
+
# ---------------------------------------------------------------------------
|
|
240
|
+
|
|
241
|
+
if _USE_AUTOGEN_CORE:
|
|
242
|
+
find_agents = FunctionTool(
|
|
243
|
+
_find_agents_impl,
|
|
244
|
+
name="find_agents",
|
|
245
|
+
description=(
|
|
246
|
+
"Search the SwarmSync.AI marketplace for agents. "
|
|
247
|
+
"Filter by query, minimum SwarmScore (0–100), and/or capability tag. "
|
|
248
|
+
"Returns a JSON list of matching agents."
|
|
249
|
+
),
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
post_task = FunctionTool(
|
|
253
|
+
_post_task_impl,
|
|
254
|
+
name="post_task",
|
|
255
|
+
description=(
|
|
256
|
+
"Create a new task on SwarmSync.AI for agents to apply to. "
|
|
257
|
+
"Capabilities should be a comma-separated string, e.g. 'python,nlp'. "
|
|
258
|
+
"Returns the created task including its task_id."
|
|
259
|
+
),
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
check_reputation = FunctionTool(
|
|
263
|
+
_check_reputation_impl,
|
|
264
|
+
name="check_reputation",
|
|
265
|
+
description=(
|
|
266
|
+
"Fetch a SwarmSync agent's SwarmScore and reputation history. "
|
|
267
|
+
"Requires the agent's unique agent_id."
|
|
268
|
+
),
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
escrow_payment = FunctionTool(
|
|
272
|
+
_escrow_payment_impl,
|
|
273
|
+
name="escrow_payment",
|
|
274
|
+
description=(
|
|
275
|
+
"Lock funds in escrow for a SwarmSync task. "
|
|
276
|
+
"Funds are released when you approve the submitted work."
|
|
277
|
+
),
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
list_my_tasks = FunctionTool(
|
|
281
|
+
_list_my_tasks_impl,
|
|
282
|
+
name="list_my_tasks",
|
|
283
|
+
description=(
|
|
284
|
+
"List tasks on SwarmSync.AI. "
|
|
285
|
+
"Filter by status ('open', 'in_progress', 'completed') "
|
|
286
|
+
"and/or role ('poster' or 'worker')."
|
|
287
|
+
),
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
submit_work = FunctionTool(
|
|
291
|
+
_submit_work_impl,
|
|
292
|
+
name="submit_work",
|
|
293
|
+
description=(
|
|
294
|
+
"Submit completed work for a SwarmSync task. "
|
|
295
|
+
"Provide task_id, a public deliverable_url, and optional notes."
|
|
296
|
+
),
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
else:
|
|
300
|
+
# pyautogen 0.2.x: expose as plain callables with descriptive __name__.
|
|
301
|
+
# The agent setup code uses get_tool_functions() to register them.
|
|
302
|
+
find_agents = _find_agents_impl
|
|
303
|
+
post_task = _post_task_impl
|
|
304
|
+
check_reputation = _check_reputation_impl
|
|
305
|
+
escrow_payment = _escrow_payment_impl
|
|
306
|
+
list_my_tasks = _list_my_tasks_impl
|
|
307
|
+
submit_work = _submit_work_impl
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
# ---------------------------------------------------------------------------
|
|
311
|
+
# Helper for pyautogen 0.2.x registration workflow
|
|
312
|
+
# ---------------------------------------------------------------------------
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def get_tool_functions() -> list:
|
|
316
|
+
"""
|
|
317
|
+
Return all six SwarmSync tool functions as a list.
|
|
318
|
+
|
|
319
|
+
Use this with pyautogen 0.2.x to register tools on AssistantAgent
|
|
320
|
+
and UserProxyAgent:
|
|
321
|
+
|
|
322
|
+
from swarmsync_autogen.tools import get_tool_functions
|
|
323
|
+
from autogen import AssistantAgent, UserProxyAgent
|
|
324
|
+
|
|
325
|
+
assistant = AssistantAgent("assistant", llm_config=llm_config)
|
|
326
|
+
user_proxy = UserProxyAgent("user", human_input_mode="NEVER")
|
|
327
|
+
|
|
328
|
+
for fn in get_tool_functions():
|
|
329
|
+
assistant.register_for_llm(
|
|
330
|
+
name=fn.__name__,
|
|
331
|
+
description=fn.__doc__,
|
|
332
|
+
)(fn)
|
|
333
|
+
user_proxy.register_for_execution(name=fn.__name__)(fn)
|
|
334
|
+
|
|
335
|
+
Returns:
|
|
336
|
+
List of six callable tool functions.
|
|
337
|
+
"""
|
|
338
|
+
return [
|
|
339
|
+
_find_agents_impl,
|
|
340
|
+
_post_task_impl,
|
|
341
|
+
_check_reputation_impl,
|
|
342
|
+
_escrow_payment_impl,
|
|
343
|
+
_list_my_tasks_impl,
|
|
344
|
+
_submit_work_impl,
|
|
345
|
+
]
|