mini-swarm 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: mini-swarm
3
+ Version: 0.1.0
4
+ Summary: mini-swe-agent, but with more agents: a minimal agent swarm
5
+ License-Expression: MIT
6
+ Keywords: nlp,agents,code
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Operating System :: POSIX :: Linux
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Requires-Python: >=3.11
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: mini-swe-agent<2.5,>=2.4.6
16
+ Requires-Dist: pyyaml
17
+ Requires-Dist: pydantic>=2.0
18
+ Requires-Dist: rich
19
+ Requires-Dist: typer
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest; extra == "dev"
22
+ Dynamic: license-file
23
+
24
+ # mini-swarm
25
+
26
+ A minimal multi-agent baseline: several [mini-swe-agent](https://github.com/SWE-agent/mini-swe-agent)s
27
+ on one checkout, sharing a task queue.
28
+
29
+ ```bash
30
+ pip install git+https://github.com/Awayfaring/mini-swarm.git
31
+ swarm -m openai/gpt-5 -t "Fix the failing tests" # one agent: exactly mini
32
+ swarm -m openai/gpt-5 -n 5 --compact -t "Find and fix the bugs" # a swarm of 5
33
+ ```
34
+
35
+ - **It's mini.** One agent is stock mini-swe-agent; your mini configs, models and environments work as-is.
36
+ - **One flag to scale.** `-n` agents split the work through a shared queue (`units add / claim / done`).
37
+ - **Limits for the whole run.** `--time` and `-l` cap all agents together; `--compact` keeps each agent's context short.
38
+ - **Safe in docker.** Agents work on a copy of your checkout; you get `submission.diff`.
39
+
40
+ Results: [More agents, more bugs?](https://swesweep.com/multi-agent/) ·
41
+ Docs: [usage](docs/usage.md) · [config](docs/config.md) · [queue](docs/QUEUE.md)
42
+
43
+ ## Citation
44
+
45
+ ```bibtex
46
+ @misc{lieret2026swesweep,
47
+ title = {{SWE-sweep}: Can Agents Autonomously Find and Fix Bugs?},
48
+ author = {Kilian Lieret and Jeffrey Jian Ma and Rahul Kindi and
49
+ Yuxiang Wei and Jeremy Ma and Sten Sootla and
50
+ Parth Thakkar and Chao Beyond Zhou and Pengcheng Yin and
51
+ Rui Hou and Ofir Press and John Yang},
52
+ year = {2026},
53
+ note = {Preprint},
54
+ url = {https://github.com/facebookresearch/swe-sweep}
55
+ }
56
+
57
+ @inproceedings{yang2024sweagent,
58
+ title={{SWE}-agent: Agent-Computer Interfaces Enable Automated Software Engineering},
59
+ author={John Yang and Carlos E Jimenez and Alexander Wettig and Kilian Lieret and Shunyu Yao and Karthik R Narasimhan and Ofir Press},
60
+ booktitle={The Thirty-eighth Annual Conference on Neural Information Processing Systems},
61
+ year={2024},
62
+ url={https://arxiv.org/abs/2405.15793}
63
+ }
64
+ ```
@@ -0,0 +1,23 @@
1
+ mini_swarm-0.1.0.dist-info/licenses/LICENSE,sha256=8HEGomU8z6MbLOqUKp9p3q67iEwEshRYu_K2kwMx36w,2598
2
+ miniswarm/__init__.py,sha256=4DixcbcXdbHF5MiIjVrMkfwDBFZDDU6TZVhoRvHey94,326
3
+ miniswarm/__main__.py,sha256=12g-TUK7-aZ5MaMVCXp7HR0nCkHJLcEtfIRK5VFH3Pc,160
4
+ miniswarm/scripted.py,sha256=oE8uxoQUm6QZQBYuQQs2sUvvnJLeNsPXff2XW1l_92Q,4091
5
+ miniswarm/agents/__init__.py,sha256=PW4uEElgE8EY4pfYVb3FIdgeMYTzInGv2Rd3xkzQ5Jo,115
6
+ miniswarm/agents/compaction.py,sha256=prbKxkB8_rt1SFLU6pfckbSwBw4KOaVEl7RSemaPU8o,6413
7
+ miniswarm/agents/swarm.py,sha256=yhWNxoANRi3Rf3GZsjjhAlVJy0JAqD7kwAzUUgtA5CQ,1986
8
+ miniswarm/queue/__init__.py,sha256=4mDFQ_kge5Qwzvf73pvp__GZcVqnEoNrwgpt7NlFNlk,112
9
+ miniswarm/queue/units.sh,sha256=Lt-IxUG-_Keq6XpvoEEVW_5qf6apra93ITdekuvJ1Jg,16760
10
+ miniswarm/queue/units_sh.py,sha256=b05nRUdBv431Q43zRUpaSdmrv5XtOxvA0SlZTXFptJY,12981
11
+ miniswarm/run/__init__.py,sha256=QztJ-ItuMAY0_DSKj0wRsEkLiUxaBQaq0wJOkrpAbWg,52
12
+ miniswarm/run/swarm.py,sha256=BYpMdlvvQGrQcBAleuknPmjHA7plb--T1Eb0S1r9D1E,8476
13
+ miniswarm/team/__init__.py,sha256=ZsWzeiNXghCjO9JdpN0h7WBSdVF8Ay1EmJHxcIqVGRQ,81
14
+ miniswarm/team/runner.py,sha256=uMaZzzjF4mhaL8YPkRLxlhVCQgXzEG3XU8kZ5ZE_BE8,28218
15
+ miniswarm/team/triggers.py,sha256=_ABo1T9LsY22TzIO3WTvbbGywaozJ8HDTIuLxlvoiWU,6751
16
+ miniswarm/team/workspace.py,sha256=w9iSWeAsg6Yl3DiBxOLqYN_fG9hUgusfKhq5fxWB7_Q,18046
17
+ miniswarm/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
+ miniswarm/utils/files.py,sha256=cR6E5h4yJ3TE0-FWasFm4Ioai_RGmqObXSSTeDf-4hM,1028
19
+ mini_swarm-0.1.0.dist-info/METADATA,sha256=lEfH2t_YMg3Ry-4ZhqmhqlQKhsP1d0L54LHq_UDv7Pk,2574
20
+ mini_swarm-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
21
+ mini_swarm-0.1.0.dist-info/entry_points.txt,sha256=P2nK4ipiIvkGB9YLE09YnccbIySt6FoTOvwOEfbp5G4,87
22
+ mini_swarm-0.1.0.dist-info/top_level.txt,sha256=wRr-l7o4IBHovKQ043aZ4E6qHpdd9X3JW3f5TuNUScU,10
23
+ mini_swarm-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ mini-swarm = miniswarm.run.swarm:app
3
+ swarm = miniswarm.run.swarm:app
@@ -0,0 +1,49 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jeremy Ma
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.
22
+
23
+ ---------------------------------------------------------------------------------------------------------
24
+
25
+ Parts of src/miniswarm (agents/default.py, models/litellm_response_model.py, models/utils/, environments/,
26
+ config/__init__.py, config/swarm.yaml, utils/serialize.py, utils/log.py, exceptions.py, run/swarm.py,
27
+ run/hello_world.py) are adapted from mini-swe-agent (https://github.com/SWE-agent/mini-swe-agent), under this license:
28
+
29
+ MIT License
30
+
31
+ Copyright (c) 2025 Kilian A. Lieret and Carlos E. Jimenez
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining a copy
34
+ of this software and associated documentation files (the "Software"), to deal
35
+ in the Software without restriction, including without limitation the rights
36
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
37
+ copies of the Software, and to permit persons to whom the Software is
38
+ furnished to do so, subject to the following conditions:
39
+
40
+ The above copyright notice and this permission notice shall be included in all
41
+ copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
48
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ miniswarm
miniswarm/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ """mini-swarm: mini-swe-agent with a swarm. It installs and uses mini-swe-agent itself (its agent, model and environment
2
+ classes, its configs, its global config and MSWEA_* variables) and adds the swarm on top: several agents on one task,
3
+ a shared work queue, forced compaction and run-level limits."""
4
+
5
+ __version__ = "0.1.0"
miniswarm/__main__.py ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env python3
2
+ """This is what happens when you do `python -m miniswarm`."""
3
+
4
+ from miniswarm.run.swarm import app
5
+
6
+ if __name__ == "__main__":
7
+ app()
@@ -0,0 +1 @@
1
+ """The swarm's additions to mini-swe-agent's agents: triggers (swarm.py) and forced compaction (compaction.py)."""
@@ -0,0 +1,117 @@
1
+ """Forced compaction, a trigger of the swarm's agents (agents/swarm.py; `swarm.compact_at_tokens`): above the
2
+ threshold, one extra model call without tools asks for notes, and the agent's messages become [system message, first
3
+ user message, the notes]. Every notes call is saved in the trajectory under `compaction_calls` (docs/usage.md)."""
4
+
5
+ import json
6
+ import math
7
+ from typing import Callable
8
+
9
+ from minisweagent.exceptions import FormatError, InterruptAgentFlow
10
+
11
+ from miniswarm.agents.swarm import limits_reached
12
+
13
+ COMPACT_REQUEST = ("The context is getting long. Your history will be replaced by the first message and the notes you "
14
+ "write now, and your earlier reasoning is dropped; the files on disk (and the work queue, if there is "
15
+ "one) stay as they are. Write the notes you need to continue: what you changed (files and what), what "
16
+ "you were checking, open leads, how to build and run tests. No tool calls.")
17
+ COMPACT_NOTES = "Your notes before the context was rewritten:\n{notes}"
18
+ COMPACT_BACKOFF_TOKENS = 20_000
19
+
20
+
21
+ def estimate_tokens(messages: list[dict]) -> int:
22
+ """The size of the next request: the last response's reported input + output tokens plus the characters added
23
+ since, / 3; with no such response (none yet, or one that reports no input tokens): all the characters, / 3."""
24
+ for i in range(len(messages) - 1, -1, -1):
25
+ m = messages[i]
26
+ response = m if m.get("object") == "response" else (m.get("extra") or {}).get("response")
27
+ if isinstance(response, dict): # a model reply (Responses API, or chat completions in extra.response)
28
+ usage = response.get("usage") or {}
29
+ inp = usage.get("input_tokens") or usage.get("prompt_tokens")
30
+ if isinstance(inp, int) and inp > 0:
31
+ out = usage.get("output_tokens") or usage.get("completion_tokens") or 0
32
+ return inp + out + math.ceil(sum(map(_chars, messages[i + 1:])) / 3)
33
+ break
34
+ return math.ceil(sum(map(_chars, messages)) / 3)
35
+
36
+
37
+ def _chars(m: dict) -> int:
38
+ return len(json.dumps({k: v for k, v in m.items() if k != "extra"}, default=str))
39
+
40
+
41
+ class Compaction:
42
+ def __init__(self, at_tokens: int, event: Callable[..., None]):
43
+ """`event(kind, **fields)` logs compact / compact_failed (the runner writes them to events.jsonl)."""
44
+ self.at_tokens = self.above = at_tokens
45
+ self.event = event
46
+ self.count = 0
47
+ self.calls: list[dict] = [] # every notes call: request, reply, cost, dropped (the messages it replaced)
48
+
49
+ def __call__(self, agent) -> None:
50
+ before = estimate_tokens(agent.messages)
51
+ if before <= self.above or limits_reached(agent):
52
+ return
53
+ self.above = before + COMPACT_BACKOFF_TOKENS
54
+ notes = self._notes(agent)
55
+ if notes is None:
56
+ return
57
+ self.count += 1
58
+ self.calls[-1]["dropped"] = agent.messages[2:]
59
+ agent.messages = agent.messages[:2] + [agent.model.format_message(
60
+ role="user", content=COMPACT_NOTES.format(notes=notes), extra={"compaction": self.count})]
61
+ after = estimate_tokens(agent.messages)
62
+ # a first message already over the threshold must not compact on every call
63
+ self.above = after + COMPACT_BACKOFF_TOKENS if after > self.at_tokens else self.at_tokens
64
+ self.event("compact", tokens_before=before, tokens_after=after, notes_chars=len(notes))
65
+
66
+ def _notes(self, agent) -> str | None:
67
+ """The notes call: the reply's text, or None if the call failed or the reply has a tool call, no text or was
68
+ cut off."""
69
+ model = agent.model
70
+ request = model.format_message(role="user", content=COMPACT_REQUEST)
71
+ try:
72
+ reply = model.query(agent.messages + [request], **({} if _text_based(model) else {"tool_choice": "none"}))
73
+ except FormatError as e: # no tool call, as asked: mini's models keep the response and its cost in it
74
+ reply = e.messages[0]
75
+ except InterruptAgentFlow:
76
+ raise
77
+ except Exception as e:
78
+ if isinstance(e, RuntimeError) and str(e).startswith("Global cost/call limit exceeded"):
79
+ raise # mini's global limit (raised after the call was billed): it ends the agent, as in mini
80
+ self.event("compact_failed", error=repr(e)[:500])
81
+ return None
82
+ extra = reply.get("extra") or {}
83
+ agent.cost += extra.get("cost", 0.0)
84
+ response = extra.get("response", reply) # the model's response (the reply itself for the Responses API)
85
+ self.calls.append({"request": request, "reply": response, "cost": extra.get("cost", 0.0), "dropped": []})
86
+ text, cut = _text(response)
87
+ if not text.strip() or extra.get("actions"):
88
+ self.event("compact_failed", error="tool call in the reply" if extra.get("actions") else "empty reply")
89
+ return None
90
+ if cut: # e.g. max_output_tokens: partial notes would replace the history
91
+ self.event("compact_failed", error="reply cut off")
92
+ return None
93
+ return text.strip()
94
+
95
+ def serialize(self) -> dict:
96
+ return {"info": {"miniswarm": {"compact_at_tokens": self.at_tokens, "compactions": self.count}},
97
+ "compaction_calls": self.calls}
98
+
99
+
100
+ def _text_based(model) -> bool:
101
+ """A text-based model (actions parsed from the text: no tools), or one that picks among models (RouletteModel,
102
+ InterleavingModel) of which one is."""
103
+ return hasattr(model.config, "action_regex") or any(map(_text_based, getattr(model, "models", [])))
104
+
105
+
106
+ def _text(response) -> tuple[str, bool]:
107
+ """A model response's text and whether it was cut off: chat completions (`choices`), the Responses API (`output`),
108
+ or a plain message (`content`)."""
109
+ if not isinstance(response, dict):
110
+ return "", False
111
+ if response.get("choices"):
112
+ choice = response["choices"][0]
113
+ return (choice.get("message") or {}).get("content") or "", choice.get("finish_reason") == "length"
114
+ if "output" in response:
115
+ return "".join(part.get("text", "") for item in response.get("output") or [] if item.get("type") == "message"
116
+ for part in item.get("content") or []), response.get("status") == "incomplete"
117
+ return (c if isinstance(c := response.get("content"), str) else ""), False
@@ -0,0 +1,41 @@
1
+ """mini-swe-agent's agent plus triggers: swarm_agent_class() puts TriggersMixin on top of the config's agent class.
2
+ A trigger is a callable `trigger(agent)` run before every model call; it may change the agent or end it by raising
3
+ one of mini's InterruptAgentFlow exceptions, and a trigger's `serialize()` is added to the saved trajectory."""
4
+
5
+ import time
6
+ from pathlib import Path
7
+
8
+ from minisweagent.agents import get_agent_class
9
+
10
+
11
+ class TriggersMixin:
12
+ def __init__(self, *args, triggers=(), **kwargs):
13
+ super().__init__(*args, **kwargs)
14
+ self.triggers = list(triggers)
15
+
16
+ def query(self) -> dict:
17
+ for trigger in self.triggers:
18
+ trigger(self)
19
+ return super().query()
20
+
21
+ def save(self, path: Path | None, *extra_dicts) -> dict:
22
+ """The agent class's save, plus what the triggers keep (e.g. the messages compaction dropped)."""
23
+ kept = [t.serialize() for t in self.triggers if hasattr(t, "serialize")]
24
+ return super().save(path, *kept, *extra_dicts)
25
+
26
+
27
+ def limits_reached(agent) -> bool:
28
+ """The agent's own step, cost or time limit is reached: DefaultAgent.query raises LimitsExceeded / TimeExceeded
29
+ next (a trigger that would spend a call or end the agent otherwise leaves it to mini)."""
30
+ c = agent.config
31
+ return (0 < c.step_limit <= agent.n_calls or 0 < c.cost_limit <= agent.cost
32
+ or 0 < c.wall_time_limit_seconds <= int(time.time() - agent._start_time))
33
+
34
+ def swarm_agent_class(spec: str = "") -> type:
35
+ """The agent class `spec` names (mini's names and import paths; "" = mini's DefaultAgent) with TriggersMixin on top,
36
+ under the same name and module, so the trajectory's agent_type is the configured class, as stock mini writes it."""
37
+ base = get_agent_class(spec or "default")
38
+ if issubclass(base, TriggersMixin):
39
+ return base
40
+ names = {"__module__": base.__module__, "__qualname__": base.__qualname__}
41
+ return type(base.__name__, (TriggersMixin, base), names)
@@ -0,0 +1 @@
1
+ """The work queue the agents of a team share: the `units` CLI (units.sh) and its harness side (units_sh.py)."""