openswarm-ai 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.
Files changed (57) hide show
  1. openswarm_ai-0.1.0/.gitignore +63 -0
  2. openswarm_ai-0.1.0/.mcp.json +11 -0
  3. openswarm_ai-0.1.0/LICENSE +21 -0
  4. openswarm_ai-0.1.0/PKG-INFO +414 -0
  5. openswarm_ai-0.1.0/README.md +391 -0
  6. openswarm_ai-0.1.0/examples/team.yaml +29 -0
  7. openswarm_ai-0.1.0/opencode.json +13 -0
  8. openswarm_ai-0.1.0/pyproject.toml +45 -0
  9. openswarm_ai-0.1.0/setup.cfg +4 -0
  10. openswarm_ai-0.1.0/src/openswarm/__init__.py +3 -0
  11. openswarm_ai-0.1.0/src/openswarm/__main__.py +5 -0
  12. openswarm_ai-0.1.0/src/openswarm/cli/__init__.py +0 -0
  13. openswarm_ai-0.1.0/src/openswarm/cli/app.py +185 -0
  14. openswarm_ai-0.1.0/src/openswarm/cli/interactive.py +119 -0
  15. openswarm_ai-0.1.0/src/openswarm/cli/utils.py +32 -0
  16. openswarm_ai-0.1.0/src/openswarm/config/__init__.py +4 -0
  17. openswarm_ai-0.1.0/src/openswarm/config/discovery.py +23 -0
  18. openswarm_ai-0.1.0/src/openswarm/config/loader.py +73 -0
  19. openswarm_ai-0.1.0/src/openswarm/config/models.py +81 -0
  20. openswarm_ai-0.1.0/src/openswarm/core/__init__.py +15 -0
  21. openswarm_ai-0.1.0/src/openswarm/core/agent.py +144 -0
  22. openswarm_ai-0.1.0/src/openswarm/core/message.py +26 -0
  23. openswarm_ai-0.1.0/src/openswarm/core/orchestrator.py +34 -0
  24. openswarm_ai-0.1.0/src/openswarm/core/task.py +28 -0
  25. openswarm_ai-0.1.0/src/openswarm/core/team.py +36 -0
  26. openswarm_ai-0.1.0/src/openswarm/llm/__init__.py +3 -0
  27. openswarm_ai-0.1.0/src/openswarm/llm/client.py +97 -0
  28. openswarm_ai-0.1.0/src/openswarm/mcp/__init__.py +0 -0
  29. openswarm_ai-0.1.0/src/openswarm/mcp/server.py +219 -0
  30. openswarm_ai-0.1.0/src/openswarm/workflow/__init__.py +26 -0
  31. openswarm_ai-0.1.0/src/openswarm/workflow/base.py +28 -0
  32. openswarm_ai-0.1.0/src/openswarm/workflow/collaborative.py +113 -0
  33. openswarm_ai-0.1.0/src/openswarm/workflow/hierarchical.py +248 -0
  34. openswarm_ai-0.1.0/src/openswarm/workflow/pipeline.py +64 -0
  35. openswarm_ai-0.1.0/src/openswarm_ai.egg-info/PKG-INFO +414 -0
  36. openswarm_ai-0.1.0/src/openswarm_ai.egg-info/SOURCES.txt +55 -0
  37. openswarm_ai-0.1.0/src/openswarm_ai.egg-info/dependency_links.txt +1 -0
  38. openswarm_ai-0.1.0/src/openswarm_ai.egg-info/entry_points.txt +3 -0
  39. openswarm_ai-0.1.0/src/openswarm_ai.egg-info/requires.txt +14 -0
  40. openswarm_ai-0.1.0/src/openswarm_ai.egg-info/top_level.txt +1 -0
  41. openswarm_ai-0.1.0/test-configs/content-pipeline.yaml +29 -0
  42. openswarm_ai-0.1.0/test-configs/dev-team.yaml +32 -0
  43. openswarm_ai-0.1.0/test-configs/review-panel.yaml +39 -0
  44. openswarm_ai-0.1.0/tests/conftest.py +125 -0
  45. openswarm_ai-0.1.0/tests/test_agent.py +145 -0
  46. openswarm_ai-0.1.0/tests/test_cli.py +119 -0
  47. openswarm_ai-0.1.0/tests/test_collaborative.py +172 -0
  48. openswarm_ai-0.1.0/tests/test_config.py +156 -0
  49. openswarm_ai-0.1.0/tests/test_interactive.py +156 -0
  50. openswarm_ai-0.1.0/tests/test_llm_client.py +89 -0
  51. openswarm_ai-0.1.0/tests/test_mcp.py +289 -0
  52. openswarm_ai-0.1.0/tests/test_message.py +34 -0
  53. openswarm_ai-0.1.0/tests/test_orchestrator.py +55 -0
  54. openswarm_ai-0.1.0/tests/test_pipeline.py +128 -0
  55. openswarm_ai-0.1.0/tests/test_task.py +25 -0
  56. openswarm_ai-0.1.0/tests/test_team.py +37 -0
  57. openswarm_ai-0.1.0/tests/test_workflow.py +223 -0
@@ -0,0 +1,63 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Distribution / packaging
7
+ dist/
8
+ build/
9
+ *.egg-info/
10
+ *.egg
11
+ .eggs/
12
+ sdist/
13
+ wheels/
14
+ *.whl
15
+
16
+ # Virtual environments
17
+ .venv/
18
+ venv/
19
+ ENV/
20
+
21
+ # Environment variables
22
+ .env
23
+ .env.*
24
+ !.env.example
25
+
26
+ # IDE
27
+ .idea/
28
+ .vscode/
29
+ *.swp
30
+ *.swo
31
+ *~
32
+ .project
33
+ .classpath
34
+ .settings/
35
+
36
+ # Testing / coverage
37
+ .pytest_cache/
38
+ htmlcov/
39
+ .coverage
40
+ .coverage.*
41
+ coverage.xml
42
+ *.cover
43
+ .hypothesis/
44
+
45
+ # Type checking
46
+ .mypy_cache/
47
+ .pytype/
48
+
49
+ # Linting
50
+ .ruff_cache/
51
+
52
+ # Claude Code
53
+ CLAUDE.md
54
+
55
+ # OS files
56
+ .DS_Store
57
+ Thumbs.db
58
+
59
+ # Logs
60
+ *.log
61
+
62
+ # Jupyter
63
+ .ipynb_checkpoints/
@@ -0,0 +1,11 @@
1
+ {
2
+ "mcpServers": {
3
+ "openswarm": {
4
+ "command": "python",
5
+ "args": ["-m", "openswarm.mcp.server"],
6
+ "env": {
7
+ "PYTHONPATH": "src"
8
+ }
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Erfan Momeni
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.
@@ -0,0 +1,414 @@
1
+ Metadata-Version: 2.4
2
+ Name: openswarm-ai
3
+ Version: 0.1.0
4
+ Summary: Multi-agent orchestration framework
5
+ Author-email: Erfan Momeni <erfamm5@gmail.com>
6
+ License: MIT
7
+ Requires-Python: >=3.12
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: litellm>=1.40.0
11
+ Requires-Dist: typer>=0.12.0
12
+ Requires-Dist: pydantic>=2.0
13
+ Requires-Dist: pyyaml>=6.0
14
+ Requires-Dist: rich>=13.0
15
+ Requires-Dist: prompt-toolkit>=3.0
16
+ Provides-Extra: mcp
17
+ Requires-Dist: mcp[cli]>=1.0; extra == "mcp"
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest>=8.0; extra == "dev"
20
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
21
+ Requires-Dist: ruff>=0.4; extra == "dev"
22
+ Dynamic: license-file
23
+
24
+ # OpenSwarm
25
+
26
+ Design AI teams in YAML. Cheap models do bulk work, expensive models make decisions — you control who does what.
27
+
28
+ ```yaml
29
+ agents:
30
+ - name: "senior"
31
+ model: claude-sonnet-4-20250514
32
+ role: senior
33
+ rules: ["Break down tasks", "Review junior's output"]
34
+
35
+ - name: "junior"
36
+ model: deepseek-chat
37
+ role: junior
38
+ rules: ["Execute assigned tasks", "Write tests"]
39
+ ```
40
+
41
+ ```bash
42
+ swarm run "Build user auth API" --config team.yaml
43
+ ```
44
+
45
+ Senior breaks it down, delegates to Junior, reviews results, assembles final output. One command.
46
+
47
+ ## Install
48
+
49
+ ```bash
50
+ pip install openswarm-ai
51
+
52
+ # With MCP server support
53
+ pip install openswarm-ai[mcp]
54
+ ```
55
+
56
+ ## Integration
57
+
58
+ The easiest way to use OpenSwarm — add a `team.yaml` to your project and let your AI IDE delegate to your agent team automatically.
59
+
60
+ ### Supported
61
+
62
+ | Tool | Integration | Status |
63
+ |------|------------|--------|
64
+ | **Claude Code** | MCP server (auto-discovery via `.mcp.json`) | Ready |
65
+ | **OpenCode** | MCP server (auto-discovery via `opencode.json`) | Ready |
66
+ | **Cursor** | MCP server (via Cursor settings) | Ready |
67
+ | **Windsurf** | MCP server (via `~/.codeium/windsurf/mcp_config.json`) | Ready |
68
+ | **GitHub Copilot** | MCP server (via VS Code `settings.json`) | Ready |
69
+
70
+ Any tool that supports MCP works with OpenSwarm — the setup is the same pattern everywhere.
71
+
72
+ ### Setup (one-time)
73
+
74
+ ```bash
75
+ pip install openswarm-ai[mcp]
76
+ ```
77
+
78
+ Then register the MCP server with your tool:
79
+
80
+ <details>
81
+ <summary><strong>Claude Code</strong></summary>
82
+
83
+ ```bash
84
+ claude mcp add openswarm -- openswarm-mcp
85
+ ```
86
+ </details>
87
+
88
+ <details>
89
+ <summary><strong>OpenCode</strong></summary>
90
+
91
+ Add to your `opencode.json`:
92
+
93
+ ```json
94
+ {
95
+ "mcp": {
96
+ "openswarm": {
97
+ "type": "local",
98
+ "command": ["openswarm-mcp"],
99
+ "timeout": 300000
100
+ }
101
+ }
102
+ }
103
+ ```
104
+ </details>
105
+
106
+ <details>
107
+ <summary><strong>Cursor</strong></summary>
108
+
109
+ Go to **Cursor Settings → MCP → Add new MCP server**:
110
+
111
+ - Name: `openswarm`
112
+ - Type: `command`
113
+ - Command: `openswarm-mcp`
114
+ </details>
115
+
116
+ <details>
117
+ <summary><strong>Windsurf</strong></summary>
118
+
119
+ Add to `~/.codeium/windsurf/mcp_config.json`:
120
+
121
+ ```json
122
+ {
123
+ "mcpServers": {
124
+ "openswarm": {
125
+ "command": "openswarm-mcp",
126
+ "args": []
127
+ }
128
+ }
129
+ }
130
+ ```
131
+ </details>
132
+
133
+ <details>
134
+ <summary><strong>GitHub Copilot (VS Code)</strong></summary>
135
+
136
+ Add to VS Code `settings.json`:
137
+
138
+ ```json
139
+ {
140
+ "github.copilot.chat.mcp.servers": {
141
+ "openswarm": {
142
+ "command": "openswarm-mcp",
143
+ "args": []
144
+ }
145
+ }
146
+ }
147
+ ```
148
+ </details>
149
+
150
+ ### Usage (per project)
151
+
152
+ Add a `team.yaml` to your project root — like `CLAUDE.md`, but for your agent team:
153
+
154
+ ```yaml
155
+ # team.yaml
156
+ team:
157
+ name: "backend-team"
158
+ goal: "Build and maintain backend services"
159
+ workflow: hierarchical
160
+ lead: "senior"
161
+
162
+ agents:
163
+ - name: "senior"
164
+ role: senior
165
+ model: claude-sonnet-4-20250514
166
+ host: https://api.anthropic.com
167
+ api_key: ${ANTHROPIC_API_KEY}
168
+ max_tokens: 4096
169
+ rules: ["Break down tasks", "Review output"]
170
+
171
+ - name: "junior"
172
+ role: junior
173
+ model: deepseek-chat
174
+ host: https://api.deepseek.com/v1
175
+ api_key: ${DEEPSEEK_API_KEY}
176
+ max_tokens: 2048
177
+ rules: ["Execute assigned tasks", "Write tests"]
178
+ ```
179
+
180
+ That's it. The MCP server auto-discovers `team.yaml` from the working directory. Claude Code and OpenCode see the tools and delegate when the task matches — no special prompting needed.
181
+
182
+ ### MCP Tools
183
+
184
+ | Tool | Description |
185
+ |------|-------------|
186
+ | `openswarm_run(task, team?)` | Delegate a task to an agent team (auto-selects if one team exists) |
187
+ | `openswarm_teams()` | List available teams (local + global) |
188
+ | `openswarm_team_info(team)` | Show team details — agents, models, workflow |
189
+
190
+ The server also discovers teams from `openswarm/*.yaml` in the project and `~/.openswarm/teams/` globally.
191
+
192
+ ## CLI Usage
193
+
194
+ ```bash
195
+ # Run with config file
196
+ swarm run "Build a REST API" --config team.yaml
197
+
198
+ # Run with named team (looks up ~/.openswarm/teams/<name>.yaml)
199
+ swarm run "Fix the login bug" --team backend
200
+
201
+ # Verbose — see inter-agent messages in real-time
202
+ swarm run "Refactor auth module" --config team.yaml -v
203
+
204
+ # List all configured teams
205
+ swarm team-list
206
+
207
+ # Show team details
208
+ swarm team-info backend
209
+
210
+ # Run as module
211
+ python -m openswarm run "Do the thing" --config team.yaml
212
+ ```
213
+
214
+ ### Interactive Mode (experimental)
215
+
216
+ Interactive REPL for chatting with your team. We're actively improving this as a separate effort.
217
+
218
+ ```bash
219
+ swarm interactive --team backend
220
+ swarm interactive --team backend -v # with real-time message display
221
+ ```
222
+
223
+ Slash commands: `/quit`, `/team`, `/history`, `/clear`. Ctrl+C cancels current task without exiting.
224
+
225
+ ## Team Config
226
+
227
+ ```yaml
228
+ team:
229
+ name: "backend-team"
230
+ goal: "Build and maintain backend services"
231
+ workflow: hierarchical
232
+ lead: "senior"
233
+ max_rounds: 10
234
+
235
+ agents:
236
+ - name: "senior"
237
+ role: senior
238
+ model: claude-sonnet-4-20250514
239
+ host: https://api.anthropic.com
240
+ api_key: ${ANTHROPIC_API_KEY}
241
+ max_tokens: 4096
242
+ temperature: 0.7
243
+ rules:
244
+ - "Break down tasks and delegate to junior"
245
+ - "Review output before marking done"
246
+
247
+ - name: "junior"
248
+ role: junior
249
+ model: deepseek-chat
250
+ host: https://api.deepseek.com/v1
251
+ api_key: ${DEEPSEEK_API_KEY}
252
+ max_tokens: 2048
253
+ temperature: 0.3
254
+ rules:
255
+ - "Execute assigned tasks"
256
+ - "Write tests for all code"
257
+ ```
258
+
259
+ ### Agent Config Fields
260
+
261
+ | Field | Default | Description |
262
+ |-------|---------|-------------|
263
+ | `name` | required | Agent identifier |
264
+ | `role` | required | Agent role description |
265
+ | `model` | required | LLM model name |
266
+ | `host` | required | API endpoint URL |
267
+ | `api_key` | required | API key (supports `${ENV_VAR}` syntax) |
268
+ | `max_tokens` | `4096` | Max tokens per response (≥ 1) |
269
+ | `temperature` | `0.7` | Sampling temperature (0.0–2.0) |
270
+ | `max_history` | `40` | Max messages kept in agent history (≥ 1) |
271
+ | `rules` | `[]` | Agent behavior rules |
272
+
273
+ ## How It Works
274
+
275
+ ```
276
+ User: "Build user auth API"
277
+
278
+ Senior (Claude): decomposes task
279
+ ├── "Write User model" → Junior (DeepSeek)
280
+ ├── "Write endpoints" → Junior (DeepSeek)
281
+ └── "Design JWT strategy" → Senior handles directly
282
+
283
+ Junior returns code → Senior reviews → requests fixes or approves
284
+
285
+ Final result → User
286
+ ```
287
+
288
+ ## Workflow Types
289
+
290
+ | Type | How it works | Best for |
291
+ |------|-------------|----------|
292
+ | **hierarchical** | Lead delegates, reviews, requests revisions, assembles | Dev teams, review workflows |
293
+ | **pipeline** | Sequential: A → B → C — each agent transforms output | Content pipelines, data processing |
294
+ | **collaborative** | All agents discuss → consensus | Brainstorming, code review, decision-making |
295
+
296
+ ### Pipeline Workflow
297
+
298
+ Sequential chain where each agent receives the previous agent's output:
299
+
300
+ ```yaml
301
+ team:
302
+ name: "content-pipeline"
303
+ goal: "Write and polish articles"
304
+ workflow: pipeline
305
+
306
+ agents:
307
+ - name: "writer"
308
+ role: writer
309
+ # ...
310
+ - name: "editor"
311
+ role: editor
312
+ # ...
313
+ - name: "reviewer"
314
+ role: reviewer
315
+ # ...
316
+ ```
317
+
318
+ Agents execute in config list order. No lead required.
319
+
320
+ ### Collaborative Workflow
321
+
322
+ All agents see the task simultaneously and discuss in rounds. First agent in the list acts as moderator. Early exit if all agents agree. Moderator synthesizes the final answer.
323
+
324
+ ```yaml
325
+ team:
326
+ name: "review-panel"
327
+ goal: "Review and decide on architecture"
328
+ workflow: collaborative
329
+ max_rounds: 5
330
+
331
+ agents:
332
+ - name: "moderator"
333
+ role: architect
334
+ # ... (first agent = moderator)
335
+ - name: "backend"
336
+ role: backend-specialist
337
+ # ...
338
+ - name: "frontend"
339
+ role: frontend-specialist
340
+ # ...
341
+ ```
342
+
343
+ Requires at least 2 agents. No `lead` field needed.
344
+
345
+ ## Error Handling
346
+
347
+ - LLM calls retry once on transient errors (rate limits, timeouts, connection issues)
348
+ - Permanent errors (bad API key, invalid model) fail immediately with a clear message
349
+ - `swarm run` shows clean error output instead of tracebacks
350
+ - Config validation catches problems at load time (missing lead agent, invalid temperature/token values)
351
+
352
+ ## Environment Variables
353
+
354
+ | Variable | Default | Purpose |
355
+ |----------|---------|---------|
356
+ | `OPENSWARM_CONFIG_DIR` | `~/.openswarm` | Config directory |
357
+ | `OPENSWARM_LOG_LEVEL` | `INFO` | Log level |
358
+
359
+ ## Development
360
+
361
+ ```bash
362
+ python -m venv .venv && source .venv/bin/activate
363
+ pip install -e ".[dev]"
364
+ pytest tests/ -v
365
+ ruff check src/ tests/ && ruff format src/ tests/
366
+ ```
367
+
368
+ ## Why OpenSwarm? Cost Comparison
369
+
370
+ Running everything through one expensive model wastes money. Most coding tasks — writing boilerplate, implementing endpoints, writing tests — don't need the most capable model. OpenSwarm lets you route work to the right model.
371
+
372
+ ### Example: "Build user auth API"
373
+
374
+ **Without OpenSwarm** — Claude Code does everything with Claude Sonnet:
375
+
376
+ | Step | Model | Input tokens | Output tokens | Cost |
377
+ |------|-------|-------------|---------------|------|
378
+ | Decompose task | Sonnet | ~2,000 | ~500 | $0.009 |
379
+ | Write User model | Sonnet | ~3,000 | ~1,500 | $0.019 |
380
+ | Write endpoints | Sonnet | ~4,000 | ~2,000 | $0.024 |
381
+ | Write tests | Sonnet | ~5,000 | ~2,500 | $0.030 |
382
+ | Review & fix | Sonnet | ~6,000 | ~1,500 | $0.027 |
383
+ | **Total** | | **~20,000** | **~8,000** | **~$0.109** |
384
+
385
+ *Sonnet: $3/M input, $15/M output*
386
+
387
+ **With OpenSwarm** — Senior (Sonnet) delegates bulk work to Junior (DeepSeek):
388
+
389
+ | Step | Model | Input tokens | Output tokens | Cost |
390
+ |------|-------|-------------|---------------|------|
391
+ | Decompose + delegate | Sonnet | ~2,000 | ~500 | $0.009 |
392
+ | Write User model | DeepSeek | ~3,000 | ~1,500 | $0.001 |
393
+ | Write endpoints | DeepSeek | ~4,000 | ~2,000 | $0.002 |
394
+ | Write tests | DeepSeek | ~5,000 | ~2,500 | $0.002 |
395
+ | Review & approve | Sonnet | ~4,000 | ~500 | $0.020 |
396
+ | **Total** | | **~18,000** | **~7,000** | **~$0.034** |
397
+
398
+ *DeepSeek: $0.14/M input, $0.28/M output*
399
+
400
+ **Result: ~70% cost reduction** on the same task, with the expensive model only doing what it's good at — architecture and review.
401
+
402
+ ### At scale
403
+
404
+ | Scenario | Without OpenSwarm | With OpenSwarm | Savings |
405
+ |----------|------------------|----------------|---------|
406
+ | 10 features/day | ~$1.09 | ~$0.34 | 69% |
407
+ | 100 features/day | ~$10.90 | ~$3.40 | 69% |
408
+ | With Opus as lead | ~$3.00 | ~$0.85 | 72% |
409
+
410
+ The more work you can route to cheap models, the more you save. Senior handles ~20% of tokens but makes the decisions that matter.
411
+
412
+ ## License
413
+
414
+ MIT