fableforge-agent-swarm 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.
- fableforge_agent_swarm-0.1.0/.github/workflows/release.yml +38 -0
- fableforge_agent_swarm-0.1.0/.gitignore +15 -0
- fableforge_agent_swarm-0.1.0/LICENSE +21 -0
- fableforge_agent_swarm-0.1.0/PKG-INFO +281 -0
- fableforge_agent_swarm-0.1.0/README.md +263 -0
- fableforge_agent_swarm-0.1.0/__init__.py +0 -0
- fableforge_agent_swarm-0.1.0/pyproject.toml +35 -0
- fableforge_agent_swarm-0.1.0/src/agent_swarm/__init__.py +41 -0
- fableforge_agent_swarm-0.1.0/src/agent_swarm/agents.py +424 -0
- fableforge_agent_swarm-0.1.0/src/agent_swarm/cli.py +255 -0
- fableforge_agent_swarm-0.1.0/src/agent_swarm/models.py +169 -0
- fableforge_agent_swarm-0.1.0/src/agent_swarm/orchestrator.py +586 -0
- fableforge_agent_swarm-0.1.0/src/agent_swarm/transition_matrix.py +379 -0
- fableforge_agent_swarm-0.1.0/tests/__init__.py +0 -0
- fableforge_agent_swarm-0.1.0/tests/test_orchestrator.py +505 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: Release to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
id-token: write
|
|
10
|
+
packages: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build-and-publish:
|
|
14
|
+
name: Build and publish to PyPI
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
environment:
|
|
17
|
+
name: pypi
|
|
18
|
+
url: https://pypi.org/p/fableforge-agent-swarm
|
|
19
|
+
permissions:
|
|
20
|
+
id-token: write
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- name: Checkout code
|
|
24
|
+
uses: actions/checkout@v4
|
|
25
|
+
|
|
26
|
+
- name: Set up Python
|
|
27
|
+
uses: actions/setup-python@v5
|
|
28
|
+
with:
|
|
29
|
+
python-version: '3.12'
|
|
30
|
+
|
|
31
|
+
- name: Install build dependencies
|
|
32
|
+
run: python -m pip install --upgrade build
|
|
33
|
+
|
|
34
|
+
- name: Build package
|
|
35
|
+
run: python -m build
|
|
36
|
+
|
|
37
|
+
- name: Publish package to PyPI
|
|
38
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 FableForge Contributors
|
|
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,281 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fableforge-agent-swarm
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Orchestrate micro-agent swarms using Markov transition matrices as handoff patterns
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: click>=8.0
|
|
9
|
+
Requires-Dist: litellm>=1.0
|
|
10
|
+
Requires-Dist: numpy>=1.24
|
|
11
|
+
Requires-Dist: pydantic>=2.0
|
|
12
|
+
Requires-Dist: pyyaml>=6.0
|
|
13
|
+
Requires-Dist: rich>=13.0
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
|
|
16
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# AgentSwarm
|
|
20
|
+
|
|
21
|
+
[](LICENSE) [](https://www.python.org/downloads/) [](tests/)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
Orchestrate micro-agent swarms using **Markov transition matrices** derived from real Fable5 trace data.
|
|
25
|
+
|
|
26
|
+
## Overview
|
|
27
|
+
|
|
28
|
+
AgentSwarm models agent coordination as a Markov chain: each agent's next tool call is predicted by transition probabilities learned from real coding sessions. Instead of hardcoded orchestration logic, the swarm uses probabilistic handoff patterns that mirror how skilled developers switch between reading, editing, running commands, and verifying.
|
|
29
|
+
|
|
30
|
+
### Key Transition Probabilities (Fable5 Data)
|
|
31
|
+
|
|
32
|
+
| Transition | Probability | Interpretation |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| Bash → Bash | 0.59 | Agents loop on shell commands |
|
|
35
|
+
| Bash → Edit | 0.18 | Shell work leads to file edits |
|
|
36
|
+
| Read → Bash | 0.37 | Reading triggers command execution |
|
|
37
|
+
| Read → Edit | 0.22 | Reading precedes editing |
|
|
38
|
+
| Edit → Bash | 0.34 | Edits trigger verification |
|
|
39
|
+
| Edit → Read | 0.28 | Edits lead to re-reading |
|
|
40
|
+
|
|
41
|
+
## Architecture
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
┌─────────────────────────────────────────────┐
|
|
45
|
+
│ SwarmOrchestrator │
|
|
46
|
+
│ ┌──────────┐ TransitionMatrix ┌──────┐ │
|
|
47
|
+
│ │ Planner │ ──────────────────→ │Reader│ │
|
|
48
|
+
│ └────┬─────┘ └──┬───┘ │
|
|
49
|
+
│ │ │ │
|
|
50
|
+
│ ▼ ▼ │
|
|
51
|
+
│ ┌──────────┐ handoff() ┌──────┐ │
|
|
52
|
+
│ │ Editor │ ←──────────────── │Bash │ │
|
|
53
|
+
│ └────┬─────┘ └──┬───┘ │
|
|
54
|
+
│ │ │ │
|
|
55
|
+
│ ▼ │ │
|
|
56
|
+
│ ┌──────────┐ │ │
|
|
57
|
+
│ │Verifier │ ←──────────────────────┘ │
|
|
58
|
+
│ └──────────┘ │
|
|
59
|
+
└─────────────────────────────────────────────┘
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
### Installation
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install agent-swarm
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
For development:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
git clone https://github.com/example/agent-swarm.git
|
|
74
|
+
cd agent-swarm
|
|
75
|
+
pip install -e ".[dev]"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Run a Task
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
swarm run "Fix the authentication bug in auth.py"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Check Status
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
swarm status
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Visualize the Swarm
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
swarm visualize
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Build Custom Transition Matrix
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
swarm build-matrix traces.jsonl -o my_matrix.json
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Programmatic Usage
|
|
103
|
+
|
|
104
|
+
### Basic Usage
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from agent_swarm import SwarmOrchestrator, TransitionMatrix
|
|
108
|
+
|
|
109
|
+
# Use the default matrix (derived from Fable5 data)
|
|
110
|
+
orchestrator = SwarmOrchestrator()
|
|
111
|
+
|
|
112
|
+
# Or load from trace data
|
|
113
|
+
tm = TransitionMatrix.from_traces("my_traces.jsonl")
|
|
114
|
+
orchestrator = SwarmOrchestrator(transition_matrix=tm)
|
|
115
|
+
|
|
116
|
+
# Run a task through the swarm
|
|
117
|
+
result = orchestrator.run("Implement user authentication")
|
|
118
|
+
print(result.summary())
|
|
119
|
+
print(f"Total handoffs: {result.total_handoffs}")
|
|
120
|
+
print(f"Final agent: {result.final_agent}")
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Spawn and Coordinate Agents
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from agent_swarm import SwarmOrchestrator
|
|
127
|
+
|
|
128
|
+
orchestrator = SwarmOrchestrator()
|
|
129
|
+
|
|
130
|
+
# Spawn individual agents
|
|
131
|
+
reader = orchestrator.spawn_agent("reader")
|
|
132
|
+
editor = orchestrator.spawn_agent("editor")
|
|
133
|
+
|
|
134
|
+
# Coordinate a task
|
|
135
|
+
task = orchestrator.coordinate("Fix the login bug")
|
|
136
|
+
|
|
137
|
+
# Predict the next agent
|
|
138
|
+
next_agent = orchestrator.predict_next_agent("reader", current_tool="read")
|
|
139
|
+
# → "editor" or "bash" (based on transition probabilities)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Handoffs with Transition Data
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
# Hand off between agents with context enrichment
|
|
146
|
+
handoff = orchestrator.handoff(
|
|
147
|
+
from_agent="reader",
|
|
148
|
+
to_agent="editor",
|
|
149
|
+
context={"findings": "Auth bug is in token validation", "files": ["auth.py"]},
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
# The handoff record includes transition data
|
|
153
|
+
print(handoff.context["handoff_probability"]) # e.g., 0.35
|
|
154
|
+
print(handoff.context["handoff_pattern"]) # Tool call sequence
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Agent Execution
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
from agent_swarm.agents import create_agent
|
|
161
|
+
|
|
162
|
+
# Create and execute with an agent
|
|
163
|
+
reader = create_agent("reader")
|
|
164
|
+
result = reader.execute("Find the authentication module")
|
|
165
|
+
print(result["plan"]) # Planned tool calls
|
|
166
|
+
print(result["recommended_handoff"]) # Next agent suggestion
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Transition Matrix API
|
|
170
|
+
|
|
171
|
+
### Predict Next Tool
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from agent_swarm import TransitionMatrix
|
|
175
|
+
|
|
176
|
+
tm = TransitionMatrix()
|
|
177
|
+
|
|
178
|
+
# Top-3 predictions after "read"
|
|
179
|
+
predictions = tm.next_tool("read", top_k=3)
|
|
180
|
+
# → [ToolCall(name='bash', confidence=0.37),
|
|
181
|
+
# ToolCall(name='edit', confidence=0.22),
|
|
182
|
+
# ToolCall(name='grep', confidence=0.20)]
|
|
183
|
+
|
|
184
|
+
# Get specific transition probability
|
|
185
|
+
prob = tm.get_transition_prob("bash", "bash")
|
|
186
|
+
# → 0.59
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Get Handoff Patterns
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
# Get the tool-call sequence for a reader→editor handoff
|
|
193
|
+
pattern = tm.get_handoff_pattern("reader", "editor")
|
|
194
|
+
# → [ToolCall(name='read', confidence=0.92),
|
|
195
|
+
# ToolCall(name='edit', confidence=0.88)]
|
|
196
|
+
|
|
197
|
+
# Get the probability of this handoff
|
|
198
|
+
prob = tm.get_handoff_probability("reader", "editor")
|
|
199
|
+
# → 0.35
|
|
200
|
+
|
|
201
|
+
# Get all handoff probabilities from a role
|
|
202
|
+
probs = tm.get_all_handoff_probabilities("planner")
|
|
203
|
+
# → {"reader": 0.25, "editor": 0.30, "bash": 0.15, ...}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Build from Traces
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
# Build from a JSONL trace file
|
|
210
|
+
tm = TransitionMatrix.from_traces("agent_traces.jsonl", min_occurrences=5)
|
|
211
|
+
|
|
212
|
+
# Save for later use
|
|
213
|
+
tm.to_json("my_matrix.json")
|
|
214
|
+
|
|
215
|
+
# Load later
|
|
216
|
+
tm = TransitionMatrix.from_json("my_matrix.json")
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Micro-Agents
|
|
220
|
+
|
|
221
|
+
| Agent | Role | Tools | Handoff Targets | Key Transition |
|
|
222
|
+
|-------|------|-------|-----------------|---------------|
|
|
223
|
+
| **ReaderAgent** | Explore & understand code | `read`, `grep`, `glob` | editor, bash, verifier, planner | Read→Edit=0.22 |
|
|
224
|
+
| **EditorAgent** | Write & modify code | `edit`, `write` | reader, bash, verifier, planner | Edit→Bash=0.34 |
|
|
225
|
+
| **BashAgent** | Execute commands | `bash` | reader, editor, verifier, planner | Bash→Bash=0.59 |
|
|
226
|
+
| **VerifierAgent** | Test & validate changes | `bash`, `read`, `grep` | reader, editor, bash, planner | Verify→Edit=0.25 |
|
|
227
|
+
| **PlannerAgent** | Plan & coordinate | `question`, `glob`, `read` | reader, editor, bash, verifier | Plan→Read=0.25 |
|
|
228
|
+
|
|
229
|
+
## Pydantic Models
|
|
230
|
+
|
|
231
|
+
The `models` module provides Pydantic v2 models for serialization and validation:
|
|
232
|
+
|
|
233
|
+
- **AgentConfig** — Configuration for spawning agents (role, tools, prompt, model settings)
|
|
234
|
+
- **SwarmResult** — Result of swarm execution with handoff history and output
|
|
235
|
+
- **HandoffEvent** — Record of an agent handoff with probability and pattern
|
|
236
|
+
- **AgentMessage** — Message in the agent conversation
|
|
237
|
+
|
|
238
|
+
## Testing
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
# Run all tests
|
|
242
|
+
pytest tests/
|
|
243
|
+
|
|
244
|
+
# Run with verbose output
|
|
245
|
+
pytest tests/ -v
|
|
246
|
+
|
|
247
|
+
# Run specific test class
|
|
248
|
+
pytest tests/test_orchestrator.py::TestTransitionMatrix -v
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## License
|
|
252
|
+
|
|
253
|
+
MIT
|
|
254
|
+
|
|
255
|
+
## Ecosystem
|
|
256
|
+
|
|
257
|
+
Part of the [FableForge](../) ecosystem — 21 open-source projects built from 210K real agent traces:
|
|
258
|
+
|
|
259
|
+
| Project | Description |
|
|
260
|
+
| --- | --- |
|
|
261
|
+
| **[Anvil](../anvil)** | Self-verified coding agent |
|
|
262
|
+
| **[VerifyLoop](../verifyloop)** | Plan→Execute→Verify→Recover framework |
|
|
263
|
+
| **[ErrorRecovery](../error-recovery)** | Self-healing middleware (3,725 error patterns) |
|
|
264
|
+
| **[FableForge-14B](../fableforge-14b)** | The fine-tuned 14B model (4-stage training) |
|
|
265
|
+
| **[ShellWhisperer](../shell-whisperer)** | 1.5B edge agent (phone/RPi, 50ms) |
|
|
266
|
+
| **[ReasonCritic](../reason-critic)** | Verification model (130 benchmark tasks) |
|
|
267
|
+
| **[TraceCompiler](../trace-compiler)** | Compile traces → LoRA skills |
|
|
268
|
+
| **[AgentRuntime](../agent-runtime)** | Persistent agent daemon (systemd for AI) |
|
|
269
|
+
| **[AgentSwarm](../agent-swarm)** | Multi-agent from real trace transitions |
|
|
270
|
+
| **[AgentTelemetry](../agent-telemetry)** | Datadog for agents (token tracking, costs) |
|
|
271
|
+
| **[BenchAgent](../bench-agent)** | HumanEval for tool-use (107 tasks) |
|
|
272
|
+
| **[AgentDev](../agent-dev)** | VSCode extension with verification |
|
|
273
|
+
| **[TraceViz](../trace-viz)** | Trace replay visualizer (Next.js) |
|
|
274
|
+
| **[AgentSkills](../agent-skills)** | npm for agent behaviors |
|
|
275
|
+
| **[AgentCurriculum](../agent-curriculum)** | 5-stage progressive training |
|
|
276
|
+
| **[AgentFuzzer](../agent-fuzzer)** | Adversarial testing for agents |
|
|
277
|
+
| **[AgentConstitution](../agent-constitution)** | Safety guardrails from traces |
|
|
278
|
+
| **[CostOptimizer](../cost-optimizer)** | Token cost reduction (50-80%) |
|
|
279
|
+
| **[AgentProfiler](../agent-profiler)** | Behavioral fingerprinting |
|
|
280
|
+
| **[TrajectoryDistiller](../trajectory-distiller)** | Trace→training data pipeline |
|
|
281
|
+
| **[Fable5-Dataset](../fable5-dataset)** | HuggingFace dataset release |
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# AgentSwarm
|
|
2
|
+
|
|
3
|
+
[](LICENSE) [](https://www.python.org/downloads/) [](tests/)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Orchestrate micro-agent swarms using **Markov transition matrices** derived from real Fable5 trace data.
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
AgentSwarm models agent coordination as a Markov chain: each agent's next tool call is predicted by transition probabilities learned from real coding sessions. Instead of hardcoded orchestration logic, the swarm uses probabilistic handoff patterns that mirror how skilled developers switch between reading, editing, running commands, and verifying.
|
|
11
|
+
|
|
12
|
+
### Key Transition Probabilities (Fable5 Data)
|
|
13
|
+
|
|
14
|
+
| Transition | Probability | Interpretation |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| Bash → Bash | 0.59 | Agents loop on shell commands |
|
|
17
|
+
| Bash → Edit | 0.18 | Shell work leads to file edits |
|
|
18
|
+
| Read → Bash | 0.37 | Reading triggers command execution |
|
|
19
|
+
| Read → Edit | 0.22 | Reading precedes editing |
|
|
20
|
+
| Edit → Bash | 0.34 | Edits trigger verification |
|
|
21
|
+
| Edit → Read | 0.28 | Edits lead to re-reading |
|
|
22
|
+
|
|
23
|
+
## Architecture
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
┌─────────────────────────────────────────────┐
|
|
27
|
+
│ SwarmOrchestrator │
|
|
28
|
+
│ ┌──────────┐ TransitionMatrix ┌──────┐ │
|
|
29
|
+
│ │ Planner │ ──────────────────→ │Reader│ │
|
|
30
|
+
│ └────┬─────┘ └──┬───┘ │
|
|
31
|
+
│ │ │ │
|
|
32
|
+
│ ▼ ▼ │
|
|
33
|
+
│ ┌──────────┐ handoff() ┌──────┐ │
|
|
34
|
+
│ │ Editor │ ←──────────────── │Bash │ │
|
|
35
|
+
│ └────┬─────┘ └──┬───┘ │
|
|
36
|
+
│ │ │ │
|
|
37
|
+
│ ▼ │ │
|
|
38
|
+
│ ┌──────────┐ │ │
|
|
39
|
+
│ │Verifier │ ←──────────────────────┘ │
|
|
40
|
+
│ └──────────┘ │
|
|
41
|
+
└─────────────────────────────────────────────┘
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
### Installation
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install agent-swarm
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
For development:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
git clone https://github.com/example/agent-swarm.git
|
|
56
|
+
cd agent-swarm
|
|
57
|
+
pip install -e ".[dev]"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Run a Task
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
swarm run "Fix the authentication bug in auth.py"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Check Status
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
swarm status
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Visualize the Swarm
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
swarm visualize
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Build Custom Transition Matrix
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
swarm build-matrix traces.jsonl -o my_matrix.json
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Programmatic Usage
|
|
85
|
+
|
|
86
|
+
### Basic Usage
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from agent_swarm import SwarmOrchestrator, TransitionMatrix
|
|
90
|
+
|
|
91
|
+
# Use the default matrix (derived from Fable5 data)
|
|
92
|
+
orchestrator = SwarmOrchestrator()
|
|
93
|
+
|
|
94
|
+
# Or load from trace data
|
|
95
|
+
tm = TransitionMatrix.from_traces("my_traces.jsonl")
|
|
96
|
+
orchestrator = SwarmOrchestrator(transition_matrix=tm)
|
|
97
|
+
|
|
98
|
+
# Run a task through the swarm
|
|
99
|
+
result = orchestrator.run("Implement user authentication")
|
|
100
|
+
print(result.summary())
|
|
101
|
+
print(f"Total handoffs: {result.total_handoffs}")
|
|
102
|
+
print(f"Final agent: {result.final_agent}")
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Spawn and Coordinate Agents
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from agent_swarm import SwarmOrchestrator
|
|
109
|
+
|
|
110
|
+
orchestrator = SwarmOrchestrator()
|
|
111
|
+
|
|
112
|
+
# Spawn individual agents
|
|
113
|
+
reader = orchestrator.spawn_agent("reader")
|
|
114
|
+
editor = orchestrator.spawn_agent("editor")
|
|
115
|
+
|
|
116
|
+
# Coordinate a task
|
|
117
|
+
task = orchestrator.coordinate("Fix the login bug")
|
|
118
|
+
|
|
119
|
+
# Predict the next agent
|
|
120
|
+
next_agent = orchestrator.predict_next_agent("reader", current_tool="read")
|
|
121
|
+
# → "editor" or "bash" (based on transition probabilities)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Handoffs with Transition Data
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
# Hand off between agents with context enrichment
|
|
128
|
+
handoff = orchestrator.handoff(
|
|
129
|
+
from_agent="reader",
|
|
130
|
+
to_agent="editor",
|
|
131
|
+
context={"findings": "Auth bug is in token validation", "files": ["auth.py"]},
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# The handoff record includes transition data
|
|
135
|
+
print(handoff.context["handoff_probability"]) # e.g., 0.35
|
|
136
|
+
print(handoff.context["handoff_pattern"]) # Tool call sequence
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Agent Execution
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from agent_swarm.agents import create_agent
|
|
143
|
+
|
|
144
|
+
# Create and execute with an agent
|
|
145
|
+
reader = create_agent("reader")
|
|
146
|
+
result = reader.execute("Find the authentication module")
|
|
147
|
+
print(result["plan"]) # Planned tool calls
|
|
148
|
+
print(result["recommended_handoff"]) # Next agent suggestion
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Transition Matrix API
|
|
152
|
+
|
|
153
|
+
### Predict Next Tool
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from agent_swarm import TransitionMatrix
|
|
157
|
+
|
|
158
|
+
tm = TransitionMatrix()
|
|
159
|
+
|
|
160
|
+
# Top-3 predictions after "read"
|
|
161
|
+
predictions = tm.next_tool("read", top_k=3)
|
|
162
|
+
# → [ToolCall(name='bash', confidence=0.37),
|
|
163
|
+
# ToolCall(name='edit', confidence=0.22),
|
|
164
|
+
# ToolCall(name='grep', confidence=0.20)]
|
|
165
|
+
|
|
166
|
+
# Get specific transition probability
|
|
167
|
+
prob = tm.get_transition_prob("bash", "bash")
|
|
168
|
+
# → 0.59
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Get Handoff Patterns
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
# Get the tool-call sequence for a reader→editor handoff
|
|
175
|
+
pattern = tm.get_handoff_pattern("reader", "editor")
|
|
176
|
+
# → [ToolCall(name='read', confidence=0.92),
|
|
177
|
+
# ToolCall(name='edit', confidence=0.88)]
|
|
178
|
+
|
|
179
|
+
# Get the probability of this handoff
|
|
180
|
+
prob = tm.get_handoff_probability("reader", "editor")
|
|
181
|
+
# → 0.35
|
|
182
|
+
|
|
183
|
+
# Get all handoff probabilities from a role
|
|
184
|
+
probs = tm.get_all_handoff_probabilities("planner")
|
|
185
|
+
# → {"reader": 0.25, "editor": 0.30, "bash": 0.15, ...}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Build from Traces
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
# Build from a JSONL trace file
|
|
192
|
+
tm = TransitionMatrix.from_traces("agent_traces.jsonl", min_occurrences=5)
|
|
193
|
+
|
|
194
|
+
# Save for later use
|
|
195
|
+
tm.to_json("my_matrix.json")
|
|
196
|
+
|
|
197
|
+
# Load later
|
|
198
|
+
tm = TransitionMatrix.from_json("my_matrix.json")
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Micro-Agents
|
|
202
|
+
|
|
203
|
+
| Agent | Role | Tools | Handoff Targets | Key Transition |
|
|
204
|
+
|-------|------|-------|-----------------|---------------|
|
|
205
|
+
| **ReaderAgent** | Explore & understand code | `read`, `grep`, `glob` | editor, bash, verifier, planner | Read→Edit=0.22 |
|
|
206
|
+
| **EditorAgent** | Write & modify code | `edit`, `write` | reader, bash, verifier, planner | Edit→Bash=0.34 |
|
|
207
|
+
| **BashAgent** | Execute commands | `bash` | reader, editor, verifier, planner | Bash→Bash=0.59 |
|
|
208
|
+
| **VerifierAgent** | Test & validate changes | `bash`, `read`, `grep` | reader, editor, bash, planner | Verify→Edit=0.25 |
|
|
209
|
+
| **PlannerAgent** | Plan & coordinate | `question`, `glob`, `read` | reader, editor, bash, verifier | Plan→Read=0.25 |
|
|
210
|
+
|
|
211
|
+
## Pydantic Models
|
|
212
|
+
|
|
213
|
+
The `models` module provides Pydantic v2 models for serialization and validation:
|
|
214
|
+
|
|
215
|
+
- **AgentConfig** — Configuration for spawning agents (role, tools, prompt, model settings)
|
|
216
|
+
- **SwarmResult** — Result of swarm execution with handoff history and output
|
|
217
|
+
- **HandoffEvent** — Record of an agent handoff with probability and pattern
|
|
218
|
+
- **AgentMessage** — Message in the agent conversation
|
|
219
|
+
|
|
220
|
+
## Testing
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
# Run all tests
|
|
224
|
+
pytest tests/
|
|
225
|
+
|
|
226
|
+
# Run with verbose output
|
|
227
|
+
pytest tests/ -v
|
|
228
|
+
|
|
229
|
+
# Run specific test class
|
|
230
|
+
pytest tests/test_orchestrator.py::TestTransitionMatrix -v
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
MIT
|
|
236
|
+
|
|
237
|
+
## Ecosystem
|
|
238
|
+
|
|
239
|
+
Part of the [FableForge](../) ecosystem — 21 open-source projects built from 210K real agent traces:
|
|
240
|
+
|
|
241
|
+
| Project | Description |
|
|
242
|
+
| --- | --- |
|
|
243
|
+
| **[Anvil](../anvil)** | Self-verified coding agent |
|
|
244
|
+
| **[VerifyLoop](../verifyloop)** | Plan→Execute→Verify→Recover framework |
|
|
245
|
+
| **[ErrorRecovery](../error-recovery)** | Self-healing middleware (3,725 error patterns) |
|
|
246
|
+
| **[FableForge-14B](../fableforge-14b)** | The fine-tuned 14B model (4-stage training) |
|
|
247
|
+
| **[ShellWhisperer](../shell-whisperer)** | 1.5B edge agent (phone/RPi, 50ms) |
|
|
248
|
+
| **[ReasonCritic](../reason-critic)** | Verification model (130 benchmark tasks) |
|
|
249
|
+
| **[TraceCompiler](../trace-compiler)** | Compile traces → LoRA skills |
|
|
250
|
+
| **[AgentRuntime](../agent-runtime)** | Persistent agent daemon (systemd for AI) |
|
|
251
|
+
| **[AgentSwarm](../agent-swarm)** | Multi-agent from real trace transitions |
|
|
252
|
+
| **[AgentTelemetry](../agent-telemetry)** | Datadog for agents (token tracking, costs) |
|
|
253
|
+
| **[BenchAgent](../bench-agent)** | HumanEval for tool-use (107 tasks) |
|
|
254
|
+
| **[AgentDev](../agent-dev)** | VSCode extension with verification |
|
|
255
|
+
| **[TraceViz](../trace-viz)** | Trace replay visualizer (Next.js) |
|
|
256
|
+
| **[AgentSkills](../agent-skills)** | npm for agent behaviors |
|
|
257
|
+
| **[AgentCurriculum](../agent-curriculum)** | 5-stage progressive training |
|
|
258
|
+
| **[AgentFuzzer](../agent-fuzzer)** | Adversarial testing for agents |
|
|
259
|
+
| **[AgentConstitution](../agent-constitution)** | Safety guardrails from traces |
|
|
260
|
+
| **[CostOptimizer](../cost-optimizer)** | Token cost reduction (50-80%) |
|
|
261
|
+
| **[AgentProfiler](../agent-profiler)** | Behavioral fingerprinting |
|
|
262
|
+
| **[TrajectoryDistiller](../trajectory-distiller)** | Trace→training data pipeline |
|
|
263
|
+
| **[Fable5-Dataset](../fable5-dataset)** | HuggingFace dataset release |
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fableforge-agent-swarm"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Orchestrate micro-agent swarms using Markov transition matrices as handoff patterns"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"pydantic>=2.0",
|
|
14
|
+
"numpy>=1.24",
|
|
15
|
+
"click>=8.0",
|
|
16
|
+
"rich>=13.0",
|
|
17
|
+
"pyyaml>=6.0",
|
|
18
|
+
"litellm>=1.0",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.optional-dependencies]
|
|
22
|
+
dev = [
|
|
23
|
+
"pytest>=7.0",
|
|
24
|
+
"pytest-asyncio>=0.21",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
swarm = "agent_swarm.cli:cli"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.wheel]
|
|
31
|
+
packages = ["src/agent_swarm"]
|
|
32
|
+
|
|
33
|
+
[tool.pytest.ini_options]
|
|
34
|
+
asyncio_mode = "auto"
|
|
35
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""AgentSwarm — Orchestrate micro-agent swarms using Markov transition matrices."""
|
|
2
|
+
|
|
3
|
+
from agent_swarm.orchestrator import SwarmOrchestrator, SwarmResult, SwarmStatus
|
|
4
|
+
from agent_swarm.transition_matrix import TransitionMatrix, ToolCall, HandoffPattern
|
|
5
|
+
from agent_swarm.agents import (
|
|
6
|
+
ReaderAgent,
|
|
7
|
+
EditorAgent,
|
|
8
|
+
BashAgent,
|
|
9
|
+
VerifierAgent,
|
|
10
|
+
PlannerAgent,
|
|
11
|
+
BaseAgent,
|
|
12
|
+
AgentRole,
|
|
13
|
+
create_agent,
|
|
14
|
+
)
|
|
15
|
+
from agent_swarm.models import (
|
|
16
|
+
AgentConfig,
|
|
17
|
+
SwarmResult as SwarmResultPydantic,
|
|
18
|
+
HandoffEvent,
|
|
19
|
+
AgentMessage as AgentMessagePydantic,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
__version__ = "0.1.0"
|
|
23
|
+
__all__ = [
|
|
24
|
+
"SwarmOrchestrator",
|
|
25
|
+
"SwarmResult",
|
|
26
|
+
"SwarmStatus",
|
|
27
|
+
"TransitionMatrix",
|
|
28
|
+
"ToolCall",
|
|
29
|
+
"HandoffPattern",
|
|
30
|
+
"ReaderAgent",
|
|
31
|
+
"EditorAgent",
|
|
32
|
+
"BashAgent",
|
|
33
|
+
"VerifierAgent",
|
|
34
|
+
"PlannerAgent",
|
|
35
|
+
"BaseAgent",
|
|
36
|
+
"AgentRole",
|
|
37
|
+
"create_agent",
|
|
38
|
+
"AgentConfig",
|
|
39
|
+
"HandoffEvent",
|
|
40
|
+
"AgentMessagePydantic",
|
|
41
|
+
]
|