@prometheus-ai/swarm-extension 0.5.1
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.
- package/CHANGELOG.md +11 -0
- package/README.md +472 -0
- package/dist/types/cli.d.ts +7 -0
- package/dist/types/extension.d.ts +12 -0
- package/dist/types/swarm/dag.d.ts +28 -0
- package/dist/types/swarm/executor.d.ts +24 -0
- package/dist/types/swarm/pipeline.d.ts +39 -0
- package/dist/types/swarm/render.d.ts +2 -0
- package/dist/types/swarm/schema.d.ts +22 -0
- package/dist/types/swarm/state.d.ts +33 -0
- package/package.json +64 -0
- package/src/cli.ts +106 -0
- package/src/extension.ts +256 -0
- package/src/swarm/__tests__/executor.test.ts +68 -0
- package/src/swarm/dag.ts +146 -0
- package/src/swarm/executor.ts +111 -0
- package/src/swarm/pipeline.ts +212 -0
- package/src/swarm/render.ts +63 -0
- package/src/swarm/schema.ts +157 -0
- package/src/swarm/state.ts +127 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
# Swarm Extension
|
|
2
|
+
|
|
3
|
+
Multi-agent orchestration for prometheus. Define agent workflows in YAML — pipelines, parallel fan-outs, sequential chains, or any DAG — and run them unattended until completion.
|
|
4
|
+
|
|
5
|
+
Each agent is a full prometheus subagent with access to every tool: bash, python, read, write, edit, grep, find, fetch, web_search, browser. The orchestrator manages lifecycle and ordering; agents communicate through the shared workspace filesystem.
|
|
6
|
+
|
|
7
|
+
Use it for anything: research pipelines, code generation, data processing, content creation, analysis workflows, CI-like automation — any multi-step task that benefits from specialized agents working in coordination.
|
|
8
|
+
|
|
9
|
+
## Setup
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
cd packages/swarm-extension
|
|
13
|
+
bun install
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Running
|
|
17
|
+
|
|
18
|
+
### Standalone (recommended for long-running work)
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# Foreground — runs until complete, no timeout:
|
|
22
|
+
prometheus-swarm path/to/swarm.yaml
|
|
23
|
+
|
|
24
|
+
# Background — survives terminal close:
|
|
25
|
+
nohup prometheus-swarm path/to/swarm.yaml \
|
|
26
|
+
> pipeline.log 2>&1 & disown
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The standalone runner has no timeout. It runs iteration after iteration until the pipeline finishes or you kill it.
|
|
30
|
+
|
|
31
|
+
### Inside prometheus (TUI)
|
|
32
|
+
|
|
33
|
+
Register the extension in your config (`~/.prometheus/config.json` or `.prometheus/config.json`):
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"extensions": ["packages/swarm-extension"]
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
/swarm run path/to/swarm.yaml
|
|
45
|
+
/swarm status <name>
|
|
46
|
+
/swarm help
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Monitoring
|
|
50
|
+
|
|
51
|
+
State persists to `<workspace>/.swarm_<name>/` while the pipeline runs:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
.swarm_<name>/
|
|
55
|
+
state/pipeline.json # Live pipeline + per-agent status
|
|
56
|
+
logs/orchestrator.log # Wave transitions, iteration progress
|
|
57
|
+
logs/<agent>.log # Per-agent timestamps and errors
|
|
58
|
+
context/ # Agent session artifacts
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Check on a running pipeline:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Quick status
|
|
65
|
+
cat workspace/.swarm_mypipeline/state/pipeline.json | python -m json.tool
|
|
66
|
+
|
|
67
|
+
# Watch the orchestrator log
|
|
68
|
+
tail -f workspace/.swarm_mypipeline/logs/orchestrator.log
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## YAML Reference
|
|
74
|
+
|
|
75
|
+
Every swarm is a single YAML file with a top-level `swarm` key:
|
|
76
|
+
|
|
77
|
+
```yaml
|
|
78
|
+
swarm:
|
|
79
|
+
name: my-pipeline # Identifier (state stored in .swarm_<name>/)
|
|
80
|
+
workspace: ./workspace # Working directory (relative to YAML file location)
|
|
81
|
+
mode: pipeline # pipeline | parallel | sequential
|
|
82
|
+
target_count: 10 # Iterations (pipeline mode only, default: 1)
|
|
83
|
+
model: claude-opus-4-6 # Default model for agents without an override (optional)
|
|
84
|
+
|
|
85
|
+
agents:
|
|
86
|
+
first_agent:
|
|
87
|
+
role: short-role-name
|
|
88
|
+
task: |
|
|
89
|
+
Full instructions for this agent.
|
|
90
|
+
extra_context: |
|
|
91
|
+
Optional additional system prompt text.
|
|
92
|
+
reports_to:
|
|
93
|
+
- downstream_agent
|
|
94
|
+
waits_for:
|
|
95
|
+
- upstream_agent
|
|
96
|
+
model: claude-sonnet-4-5 # Optional per-agent override
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Top-Level Fields
|
|
100
|
+
|
|
101
|
+
| Field | Required | Default | Description |
|
|
102
|
+
| -------------- | -------- | --------------- | ------------------------------------------------------------------------------ |
|
|
103
|
+
| `name` | yes | — | Pipeline identifier. State directory is `.swarm_<name>/` |
|
|
104
|
+
| `workspace` | yes | — | Shared working directory. Relative paths resolve from YAML file location |
|
|
105
|
+
| `mode` | no | `sequential` | Execution mode (see below) |
|
|
106
|
+
| `target_count` | no | `1` | How many times to repeat the full pipeline. Only meaningful in `pipeline` mode |
|
|
107
|
+
| `model` | no | session default | Default model for agents that do not set `agents.<name>.model` |
|
|
108
|
+
|
|
109
|
+
### Agent Fields
|
|
110
|
+
|
|
111
|
+
| Field | Required | Description |
|
|
112
|
+
| --------------- | -------- | ----------------------------------------------------------------------- |
|
|
113
|
+
| `role` | yes | Short role identifier — becomes the agent's system prompt |
|
|
114
|
+
| `task` | yes | Complete instructions sent as user prompt. Use YAML `\|` for multi-line |
|
|
115
|
+
| `extra_context` | no | Additional text appended to system prompt |
|
|
116
|
+
| `model` | no | Model override for this agent only |
|
|
117
|
+
| `reports_to` | no | List of agent names that depend on this agent |
|
|
118
|
+
| `waits_for` | no | List of agent names this agent depends on |
|
|
119
|
+
|
|
120
|
+
### Execution Modes
|
|
121
|
+
|
|
122
|
+
**`pipeline`** — Repeat the full agent graph `target_count` times. Each iteration runs all waves in order. Use for accumulative work: "find 50 things, one per iteration."
|
|
123
|
+
|
|
124
|
+
**`sequential`** — Run agents once, chained by declaration order (unless explicit dependencies override). The default mode.
|
|
125
|
+
|
|
126
|
+
**`parallel`** — Run all agents simultaneously (unless explicit dependencies impose ordering).
|
|
127
|
+
|
|
128
|
+
### Dependency Resolution
|
|
129
|
+
|
|
130
|
+
The orchestrator builds a DAG from `waits_for` and `reports_to`, then groups agents into **waves** using topological sort. Agents in the same wave run in parallel; waves execute in sequence.
|
|
131
|
+
|
|
132
|
+
- `waits_for: [a, b]` — this agent won't start until both `a` and `b` finish
|
|
133
|
+
- `reports_to: [x]` — equivalent to `x` having `waits_for: [this_agent]`
|
|
134
|
+
- No explicit deps + `pipeline`/`sequential` mode — agents chain by YAML declaration order
|
|
135
|
+
- No explicit deps + `parallel` mode — all agents run in one wave
|
|
136
|
+
- Cycles are detected and rejected before execution
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Patterns
|
|
141
|
+
|
|
142
|
+
### Pipeline: Iterative Accumulation
|
|
143
|
+
|
|
144
|
+
Run the same agent chain N times. Each iteration builds on the previous one's output. Good for: research collection, data gathering, batch processing, iterative refinement.
|
|
145
|
+
|
|
146
|
+
```yaml
|
|
147
|
+
swarm:
|
|
148
|
+
name: research-collector
|
|
149
|
+
workspace: ./workspace
|
|
150
|
+
mode: pipeline
|
|
151
|
+
target_count: 25
|
|
152
|
+
model: claude-opus-4-6
|
|
153
|
+
|
|
154
|
+
agents:
|
|
155
|
+
finder:
|
|
156
|
+
role: researcher
|
|
157
|
+
task: |
|
|
158
|
+
Find ONE new source on the topic defined in workspace/topic.md.
|
|
159
|
+
|
|
160
|
+
1. Read processed.txt to see what's already been found
|
|
161
|
+
2. Use web_search to find a new, high-quality source
|
|
162
|
+
3. Append the URL to processed.txt
|
|
163
|
+
4. Write the URL to signals/finder_out.txt: FOUND:<url>
|
|
164
|
+
|
|
165
|
+
analyzer:
|
|
166
|
+
role: analyst
|
|
167
|
+
task: |
|
|
168
|
+
Read signals/finder_out.txt for the URL.
|
|
169
|
+
Fetch the page and extract key findings.
|
|
170
|
+
Read tracking/count.txt, increment it, write back.
|
|
171
|
+
Write analysis to analyzed/item_<N>.md
|
|
172
|
+
Write to signals/analyzer_out.txt: DONE:<N>
|
|
173
|
+
|
|
174
|
+
compiler:
|
|
175
|
+
role: technical-writer
|
|
176
|
+
task: |
|
|
177
|
+
Read signals/analyzer_out.txt for the item number.
|
|
178
|
+
Read analyzed/item_<N>.md.
|
|
179
|
+
Append a summary to output/report.md under a new section.
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
After 25 iterations: 25 sources found, analyzed, and compiled into a single report.
|
|
183
|
+
|
|
184
|
+
### Fan-In: Parallel Specialists
|
|
185
|
+
|
|
186
|
+
Multiple agents work independently, one synthesizer combines results. Good for: multi-perspective analysis, parallel code review, comprehensive audits.
|
|
187
|
+
|
|
188
|
+
```yaml
|
|
189
|
+
swarm:
|
|
190
|
+
name: codebase-audit
|
|
191
|
+
workspace: ./workspace
|
|
192
|
+
|
|
193
|
+
agents:
|
|
194
|
+
security:
|
|
195
|
+
role: security-auditor
|
|
196
|
+
task: |
|
|
197
|
+
Audit all code in src/ for security vulnerabilities.
|
|
198
|
+
Write findings to reports/security.md with severity ratings.
|
|
199
|
+
reports_to:
|
|
200
|
+
- lead
|
|
201
|
+
|
|
202
|
+
performance:
|
|
203
|
+
role: performance-analyst
|
|
204
|
+
task: |
|
|
205
|
+
Profile and analyze src/ for performance bottlenecks.
|
|
206
|
+
Write findings to reports/performance.md with benchmarks.
|
|
207
|
+
reports_to:
|
|
208
|
+
- lead
|
|
209
|
+
|
|
210
|
+
architecture:
|
|
211
|
+
role: architecture-reviewer
|
|
212
|
+
task: |
|
|
213
|
+
Review src/ for architectural issues, coupling, and tech debt.
|
|
214
|
+
Write findings to reports/architecture.md with refactoring suggestions.
|
|
215
|
+
reports_to:
|
|
216
|
+
- lead
|
|
217
|
+
|
|
218
|
+
lead:
|
|
219
|
+
role: engineering-lead
|
|
220
|
+
task: |
|
|
221
|
+
Read all reports in reports/.
|
|
222
|
+
Create a prioritized action plan in output/action_plan.md.
|
|
223
|
+
Rank issues by impact and effort.
|
|
224
|
+
waits_for:
|
|
225
|
+
- security
|
|
226
|
+
- performance
|
|
227
|
+
- architecture
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Execution: security + performance + architecture run in parallel (wave 1), lead starts after all three complete (wave 2).
|
|
231
|
+
|
|
232
|
+
### Sequential Chain: Staged Handoff
|
|
233
|
+
|
|
234
|
+
Linear progression through distinct phases. Good for: content pipelines, multi-stage processing, review chains.
|
|
235
|
+
|
|
236
|
+
```yaml
|
|
237
|
+
swarm:
|
|
238
|
+
name: blog-post
|
|
239
|
+
workspace: ./workspace
|
|
240
|
+
mode: sequential
|
|
241
|
+
|
|
242
|
+
agents:
|
|
243
|
+
researcher:
|
|
244
|
+
role: researcher
|
|
245
|
+
task: |
|
|
246
|
+
Research the topic in topic.md using web_search.
|
|
247
|
+
Write raw findings and source links to research/notes.md
|
|
248
|
+
|
|
249
|
+
writer:
|
|
250
|
+
role: technical-writer
|
|
251
|
+
task: |
|
|
252
|
+
Read research/notes.md.
|
|
253
|
+
Write a complete blog post draft to drafts/post.md.
|
|
254
|
+
Include code examples where relevant.
|
|
255
|
+
|
|
256
|
+
editor:
|
|
257
|
+
role: editor
|
|
258
|
+
task: |
|
|
259
|
+
Read drafts/post.md.
|
|
260
|
+
Fix grammar, improve flow, tighten prose.
|
|
261
|
+
Rewrite to drafts/post.md.
|
|
262
|
+
|
|
263
|
+
reviewer:
|
|
264
|
+
role: senior-reviewer
|
|
265
|
+
task: |
|
|
266
|
+
Read drafts/post.md.
|
|
267
|
+
Check technical accuracy against research/notes.md.
|
|
268
|
+
Add an editorial note at top if issues found, otherwise
|
|
269
|
+
copy to output/final.md.
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Execution: researcher -> writer -> editor -> reviewer, one after another.
|
|
273
|
+
|
|
274
|
+
### Diamond: Fan-Out Then Fan-In
|
|
275
|
+
|
|
276
|
+
One planner, parallel workers, one integrator. Good for: divide-and-conquer, modular code generation, multi-file refactors.
|
|
277
|
+
|
|
278
|
+
```yaml
|
|
279
|
+
swarm:
|
|
280
|
+
name: feature-implementation
|
|
281
|
+
workspace: ./workspace
|
|
282
|
+
|
|
283
|
+
agents:
|
|
284
|
+
planner:
|
|
285
|
+
role: architect
|
|
286
|
+
task: |
|
|
287
|
+
Read the feature spec in spec.md.
|
|
288
|
+
Break it into independent implementation tasks.
|
|
289
|
+
Write the plan to plan.md with file assignments.
|
|
290
|
+
reports_to:
|
|
291
|
+
- api
|
|
292
|
+
- ui
|
|
293
|
+
- tests
|
|
294
|
+
|
|
295
|
+
api:
|
|
296
|
+
role: backend-developer
|
|
297
|
+
task: |
|
|
298
|
+
Read plan.md for your assigned files.
|
|
299
|
+
Implement the API layer. Write to src/api/.
|
|
300
|
+
reports_to:
|
|
301
|
+
- integrator
|
|
302
|
+
|
|
303
|
+
ui:
|
|
304
|
+
role: frontend-developer
|
|
305
|
+
task: |
|
|
306
|
+
Read plan.md for your assigned files.
|
|
307
|
+
Implement the UI components. Write to src/ui/.
|
|
308
|
+
reports_to:
|
|
309
|
+
- integrator
|
|
310
|
+
|
|
311
|
+
tests:
|
|
312
|
+
role: test-engineer
|
|
313
|
+
task: |
|
|
314
|
+
Read plan.md for the full feature scope.
|
|
315
|
+
Write integration tests to tests/.
|
|
316
|
+
reports_to:
|
|
317
|
+
- integrator
|
|
318
|
+
|
|
319
|
+
integrator:
|
|
320
|
+
role: tech-lead
|
|
321
|
+
task: |
|
|
322
|
+
Read plan.md and review all code in src/ and tests/.
|
|
323
|
+
Wire everything together. Fix any integration issues.
|
|
324
|
+
Run the tests and fix failures.
|
|
325
|
+
Write status to output/done.md.
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
Execution: planner (wave 1) -> api + ui + tests in parallel (wave 2) -> integrator (wave 3).
|
|
329
|
+
|
|
330
|
+
### Hybrid: Mixed Dependencies
|
|
331
|
+
|
|
332
|
+
Any DAG is valid. Combine patterns freely.
|
|
333
|
+
|
|
334
|
+
```yaml
|
|
335
|
+
swarm:
|
|
336
|
+
name: data-pipeline
|
|
337
|
+
workspace: ./workspace
|
|
338
|
+
mode: pipeline
|
|
339
|
+
target_count: 10
|
|
340
|
+
|
|
341
|
+
agents:
|
|
342
|
+
scraper_a:
|
|
343
|
+
role: web-scraper
|
|
344
|
+
task: |
|
|
345
|
+
Scrape data source A. Write to raw/source_a.json
|
|
346
|
+
reports_to:
|
|
347
|
+
- transformer
|
|
348
|
+
|
|
349
|
+
scraper_b:
|
|
350
|
+
role: web-scraper
|
|
351
|
+
task: |
|
|
352
|
+
Scrape data source B. Write to raw/source_b.json
|
|
353
|
+
reports_to:
|
|
354
|
+
- transformer
|
|
355
|
+
|
|
356
|
+
transformer:
|
|
357
|
+
role: data-engineer
|
|
358
|
+
task: |
|
|
359
|
+
Read raw/source_a.json and raw/source_b.json.
|
|
360
|
+
Clean, normalize, merge. Write to processed/merged.json
|
|
361
|
+
reports_to:
|
|
362
|
+
- loader
|
|
363
|
+
- validator
|
|
364
|
+
|
|
365
|
+
validator:
|
|
366
|
+
role: qa-analyst
|
|
367
|
+
task: |
|
|
368
|
+
Read processed/merged.json.
|
|
369
|
+
Validate schema, check for anomalies.
|
|
370
|
+
Write report to qa/validation.md
|
|
371
|
+
|
|
372
|
+
loader:
|
|
373
|
+
role: data-engineer
|
|
374
|
+
task: |
|
|
375
|
+
Read processed/merged.json.
|
|
376
|
+
Append to output/dataset.jsonl
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Execution per iteration: scraper_a + scraper_b (wave 1) -> transformer (wave 2) -> loader + validator (wave 3).
|
|
380
|
+
|
|
381
|
+
---
|
|
382
|
+
|
|
383
|
+
## Writing Agent Tasks
|
|
384
|
+
|
|
385
|
+
### What Agents Can Do
|
|
386
|
+
|
|
387
|
+
Each agent is a full prometheus session. It can:
|
|
388
|
+
|
|
389
|
+
- **bash/python**: Run commands, scripts, install packages, process data
|
|
390
|
+
- **read/write/edit**: Create and modify files in the workspace
|
|
391
|
+
- **grep/find**: Search the workspace (or anywhere on disk)
|
|
392
|
+
- **web_search**: Search the internet (via configured provider)
|
|
393
|
+
- **fetch**: Download web pages, APIs, documents
|
|
394
|
+
- **browser**: Navigate websites, scrape dynamic content, take screenshots
|
|
395
|
+
|
|
396
|
+
### Inter-Agent Communication
|
|
397
|
+
|
|
398
|
+
The orchestrator starts and stops agents in the right order. It does **not** pass data between them. Agents communicate through files in the shared workspace.
|
|
399
|
+
|
|
400
|
+
Design your own protocol. Common patterns:
|
|
401
|
+
|
|
402
|
+
**Signal files** — lightweight status flags an agent writes when done:
|
|
403
|
+
|
|
404
|
+
```
|
|
405
|
+
signals/finder_out.txt -> "FOUND:https://example.com"
|
|
406
|
+
signals/analyzer_out.txt -> "DONE:42"
|
|
407
|
+
signals/reviewer_out.txt -> "APPROVED" or "REJECTED:reason"
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
**Structured output** — detailed results other agents read:
|
|
411
|
+
|
|
412
|
+
```
|
|
413
|
+
analyzed/item_1.md -> Full analysis document
|
|
414
|
+
results/report.json -> Machine-readable data
|
|
415
|
+
output/final.docx -> Accumulated deliverable
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
**Tracking files** — prevent duplicate work across pipeline iterations:
|
|
419
|
+
|
|
420
|
+
```
|
|
421
|
+
processed.txt -> Items already handled (one per line)
|
|
422
|
+
tracking/count.txt -> Current item counter
|
|
423
|
+
tracking/status.json -> Cumulative state
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### Tips for Reliable Agents
|
|
427
|
+
|
|
428
|
+
- **Be explicit about paths.** Agents start fresh each iteration — they don't remember previous runs. Tell them exactly where to read input and write output.
|
|
429
|
+
- **Check existing state.** In pipeline mode, tell agents to read tracking files before doing work: "Read processed.txt to avoid duplicates."
|
|
430
|
+
- **Use numbered outputs.** `item_1.md`, `item_2.md` etc. so iterations don't clobber each other.
|
|
431
|
+
- **Handle failure.** Tell agents what to do when things go wrong: "If the source lacks depth, write SKIP to signals/out.txt and explain why."
|
|
432
|
+
- **Keep signal files simple.** One line, parseable format. Complex data goes in structured output files.
|
|
433
|
+
- **Scope the task tightly.** An agent that tries to do five things will do zero well. One clear objective per agent.
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
## Models
|
|
438
|
+
|
|
439
|
+
Any model configured in prometheus works. Set a swarm default and optionally override per agent:
|
|
440
|
+
|
|
441
|
+
```yaml
|
|
442
|
+
swarm:
|
|
443
|
+
model: claude-opus-4-6
|
|
444
|
+
agents:
|
|
445
|
+
writer:
|
|
446
|
+
role: technical-writer
|
|
447
|
+
task: |
|
|
448
|
+
Write the draft.
|
|
449
|
+
reviewer:
|
|
450
|
+
role: reviewer
|
|
451
|
+
model: claude-sonnet-4-5
|
|
452
|
+
task: |
|
|
453
|
+
Review the draft.
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
Precedence: `agents.<name>.model` → `swarm.model` → session default. Check `packages/ai/src/models.json` for available model IDs.
|
|
457
|
+
|
|
458
|
+
---
|
|
459
|
+
|
|
460
|
+
## Architecture
|
|
461
|
+
|
|
462
|
+
```
|
|
463
|
+
src/extension.ts TUI entry point (registers /swarm command)
|
|
464
|
+
src/cli.ts Standalone runner (no TUI, no timeout)
|
|
465
|
+
src/swarm/
|
|
466
|
+
schema.ts YAML parsing + validation
|
|
467
|
+
dag.ts Dependency graph, cycle detection, topological sort
|
|
468
|
+
executor.ts Spawns agents via prometheus's runSubprocess
|
|
469
|
+
pipeline.ts Iteration loop + wave controller
|
|
470
|
+
state.ts Filesystem state persistence
|
|
471
|
+
render.ts Progress display formatting
|
|
472
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swarm Extension — Multi-agent pipeline orchestration from YAML definitions.
|
|
3
|
+
*
|
|
4
|
+
* Registers:
|
|
5
|
+
* - /swarm run <file.yaml> — Execute a swarm pipeline
|
|
6
|
+
* - /swarm status — Show current pipeline status
|
|
7
|
+
*
|
|
8
|
+
* Usage: Add this extension's directory to your extensions config,
|
|
9
|
+
* then use /swarm in any prometheus session.
|
|
10
|
+
*/
|
|
11
|
+
import type { ExtensionAPI } from "@prometheus-ai/agent";
|
|
12
|
+
export default function swarmExtension(pi: ExtensionAPI): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directed Acyclic Graph operations for swarm agent dependencies.
|
|
3
|
+
*
|
|
4
|
+
* Builds a dependency graph from waits_for / reports_to relationships,
|
|
5
|
+
* detects cycles, and produces execution waves via topological sort.
|
|
6
|
+
*/
|
|
7
|
+
import type { SwarmDefinition } from "./schema";
|
|
8
|
+
/**
|
|
9
|
+
* Build a dependency map: agent name → set of agents it depends on.
|
|
10
|
+
*
|
|
11
|
+
* Dependencies come from:
|
|
12
|
+
* 1. Explicit `waits_for` declarations
|
|
13
|
+
* 2. Implicit from `reports_to` (if A reports_to B, then B depends on A)
|
|
14
|
+
* 3. For pipeline/sequential mode with no explicit deps: chain by YAML declaration order
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildDependencyGraph(def: SwarmDefinition): Map<string, Set<string>>;
|
|
17
|
+
/**
|
|
18
|
+
* Detect cycles in the dependency graph.
|
|
19
|
+
* Returns the names of agents involved in cycles, or null if acyclic.
|
|
20
|
+
*/
|
|
21
|
+
export declare function detectCycles(deps: Map<string, Set<string>>): string[] | null;
|
|
22
|
+
/**
|
|
23
|
+
* Build execution waves from dependency graph via topological sort.
|
|
24
|
+
*
|
|
25
|
+
* Each wave contains agents whose dependencies are all in earlier waves.
|
|
26
|
+
* Agents within a wave can execute in parallel.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildExecutionWaves(deps: Map<string, Set<string>>): string[][];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AgentProgress, ModelRegistry, Settings, SingleResult } from "@prometheus-ai/agent";
|
|
2
|
+
import type { SwarmAgent } from "./schema";
|
|
3
|
+
import type { StateTracker } from "./state";
|
|
4
|
+
export interface SwarmExecutorOptions {
|
|
5
|
+
workspace: string;
|
|
6
|
+
swarmName: string;
|
|
7
|
+
iteration: number;
|
|
8
|
+
modelOverride?: string;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
onProgress?: (agentName: string, progress: AgentProgress) => void;
|
|
11
|
+
modelRegistry?: ModelRegistry;
|
|
12
|
+
settings?: Settings;
|
|
13
|
+
stateTracker: StateTracker;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Execute a single swarm agent as an prometheus subagent.
|
|
17
|
+
*
|
|
18
|
+
* The agent receives:
|
|
19
|
+
* - System prompt: built from role + extra_context
|
|
20
|
+
* - User prompt (task): the full task instructions from the YAML
|
|
21
|
+
* - Working directory: the swarm workspace
|
|
22
|
+
* - Full tool access (bash, python, read, write, edit, grep, find, fetch, web_search, browser)
|
|
23
|
+
*/
|
|
24
|
+
export declare function executeSwarmAgent(agent: SwarmAgent, index: number, options: SwarmExecutorOptions): Promise<SingleResult>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline controller for swarm execution.
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates execution waves within each iteration:
|
|
5
|
+
* - Agents in the same wave execute in parallel
|
|
6
|
+
* - Waves execute sequentially (wave N+1 starts after wave N completes)
|
|
7
|
+
* - For pipeline mode, iterations repeat the full DAG execution
|
|
8
|
+
*/
|
|
9
|
+
import type { ModelRegistry, Settings, SingleResult } from "@prometheus-ai/agent";
|
|
10
|
+
import type { SwarmDefinition } from "./schema";
|
|
11
|
+
import type { StateTracker } from "./state";
|
|
12
|
+
export interface PipelineOptions {
|
|
13
|
+
workspace: string;
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
onProgress?: (state: PipelineProgress) => void;
|
|
16
|
+
modelRegistry?: ModelRegistry;
|
|
17
|
+
settings?: Settings;
|
|
18
|
+
}
|
|
19
|
+
export interface PipelineProgress {
|
|
20
|
+
iteration: number;
|
|
21
|
+
targetCount: number;
|
|
22
|
+
currentWave: number;
|
|
23
|
+
totalWaves: number;
|
|
24
|
+
agents: Record<string, {
|
|
25
|
+
status: string;
|
|
26
|
+
iteration: number;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
export interface PipelineResult {
|
|
30
|
+
status: "completed" | "failed" | "aborted";
|
|
31
|
+
iterations: number;
|
|
32
|
+
agentResults: Map<string, SingleResult[]>;
|
|
33
|
+
errors: string[];
|
|
34
|
+
}
|
|
35
|
+
export declare class PipelineController {
|
|
36
|
+
#private;
|
|
37
|
+
constructor(def: SwarmDefinition, waves: string[][], stateTracker: StateTracker);
|
|
38
|
+
run(options: PipelineOptions): Promise<PipelineResult>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type SwarmMode = "pipeline" | "parallel" | "sequential";
|
|
2
|
+
export interface SwarmAgent {
|
|
3
|
+
name: string;
|
|
4
|
+
role: string;
|
|
5
|
+
task: string;
|
|
6
|
+
extraContext?: string;
|
|
7
|
+
reportsTo: string[];
|
|
8
|
+
waitsFor: string[];
|
|
9
|
+
model?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SwarmDefinition {
|
|
12
|
+
name: string;
|
|
13
|
+
workspace: string;
|
|
14
|
+
mode: SwarmMode;
|
|
15
|
+
targetCount: number;
|
|
16
|
+
model?: string;
|
|
17
|
+
agents: Map<string, SwarmAgent>;
|
|
18
|
+
/** Preserves YAML declaration order for implicit pipeline sequencing. */
|
|
19
|
+
agentOrder: string[];
|
|
20
|
+
}
|
|
21
|
+
export declare function parseSwarmYaml(content: string): SwarmDefinition;
|
|
22
|
+
export declare function validateSwarmDefinition(def: SwarmDefinition): string[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type PipelineStatus = "idle" | "running" | "completed" | "failed" | "aborted";
|
|
2
|
+
export type AgentStatus = "pending" | "waiting" | "running" | "completed" | "failed";
|
|
3
|
+
export interface AgentState {
|
|
4
|
+
name: string;
|
|
5
|
+
status: AgentStatus;
|
|
6
|
+
iteration: number;
|
|
7
|
+
wave: number;
|
|
8
|
+
startedAt?: number;
|
|
9
|
+
completedAt?: number;
|
|
10
|
+
error?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SwarmState {
|
|
13
|
+
name: string;
|
|
14
|
+
status: PipelineStatus;
|
|
15
|
+
mode: string;
|
|
16
|
+
iteration: number;
|
|
17
|
+
targetCount: number;
|
|
18
|
+
agents: Record<string, AgentState>;
|
|
19
|
+
startedAt: number;
|
|
20
|
+
completedAt?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare class StateTracker {
|
|
23
|
+
#private;
|
|
24
|
+
constructor(workspaceDir: string, name: string);
|
|
25
|
+
get swarmDir(): string;
|
|
26
|
+
get state(): Readonly<SwarmState>;
|
|
27
|
+
init(agentNames: string[], targetCount: number, mode: string): Promise<void>;
|
|
28
|
+
updateAgent(name: string, update: Partial<AgentState>): Promise<void>;
|
|
29
|
+
updatePipeline(update: Partial<SwarmState>): Promise<void>;
|
|
30
|
+
appendLog(agentName: string, message: string): Promise<void>;
|
|
31
|
+
appendOrchestratorLog(message: string): Promise<void>;
|
|
32
|
+
load(): Promise<SwarmState | null>;
|
|
33
|
+
}
|