mini-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.
- mini_swarm-0.1.0/LICENSE +49 -0
- mini_swarm-0.1.0/PKG-INFO +64 -0
- mini_swarm-0.1.0/README.md +41 -0
- mini_swarm-0.1.0/pyproject.toml +47 -0
- mini_swarm-0.1.0/setup.cfg +4 -0
- mini_swarm-0.1.0/src/mini_swarm.egg-info/PKG-INFO +64 -0
- mini_swarm-0.1.0/src/mini_swarm.egg-info/SOURCES.txt +26 -0
- mini_swarm-0.1.0/src/mini_swarm.egg-info/dependency_links.txt +1 -0
- mini_swarm-0.1.0/src/mini_swarm.egg-info/entry_points.txt +3 -0
- mini_swarm-0.1.0/src/mini_swarm.egg-info/requires.txt +8 -0
- mini_swarm-0.1.0/src/mini_swarm.egg-info/top_level.txt +1 -0
- mini_swarm-0.1.0/src/miniswarm/__init__.py +5 -0
- mini_swarm-0.1.0/src/miniswarm/__main__.py +7 -0
- mini_swarm-0.1.0/src/miniswarm/agents/__init__.py +1 -0
- mini_swarm-0.1.0/src/miniswarm/agents/compaction.py +117 -0
- mini_swarm-0.1.0/src/miniswarm/agents/swarm.py +41 -0
- mini_swarm-0.1.0/src/miniswarm/queue/__init__.py +1 -0
- mini_swarm-0.1.0/src/miniswarm/queue/units.sh +380 -0
- mini_swarm-0.1.0/src/miniswarm/queue/units_sh.py +307 -0
- mini_swarm-0.1.0/src/miniswarm/run/__init__.py +1 -0
- mini_swarm-0.1.0/src/miniswarm/run/swarm.py +157 -0
- mini_swarm-0.1.0/src/miniswarm/scripted.py +91 -0
- mini_swarm-0.1.0/src/miniswarm/team/__init__.py +1 -0
- mini_swarm-0.1.0/src/miniswarm/team/runner.py +510 -0
- mini_swarm-0.1.0/src/miniswarm/team/triggers.py +140 -0
- mini_swarm-0.1.0/src/miniswarm/team/workspace.py +325 -0
- mini_swarm-0.1.0/src/miniswarm/utils/__init__.py +0 -0
- mini_swarm-0.1.0/src/miniswarm/utils/files.py +27 -0
mini_swarm-0.1.0/LICENSE
ADDED
|
@@ -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,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,41 @@
|
|
|
1
|
+
# mini-swarm
|
|
2
|
+
|
|
3
|
+
A minimal multi-agent baseline: several [mini-swe-agent](https://github.com/SWE-agent/mini-swe-agent)s
|
|
4
|
+
on one checkout, sharing a task queue.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install git+https://github.com/Awayfaring/mini-swarm.git
|
|
8
|
+
swarm -m openai/gpt-5 -t "Fix the failing tests" # one agent: exactly mini
|
|
9
|
+
swarm -m openai/gpt-5 -n 5 --compact -t "Find and fix the bugs" # a swarm of 5
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
- **It's mini.** One agent is stock mini-swe-agent; your mini configs, models and environments work as-is.
|
|
13
|
+
- **One flag to scale.** `-n` agents split the work through a shared queue (`units add / claim / done`).
|
|
14
|
+
- **Limits for the whole run.** `--time` and `-l` cap all agents together; `--compact` keeps each agent's context short.
|
|
15
|
+
- **Safe in docker.** Agents work on a copy of your checkout; you get `submission.diff`.
|
|
16
|
+
|
|
17
|
+
Results: [More agents, more bugs?](https://swesweep.com/multi-agent/) ·
|
|
18
|
+
Docs: [usage](docs/usage.md) · [config](docs/config.md) · [queue](docs/QUEUE.md)
|
|
19
|
+
|
|
20
|
+
## Citation
|
|
21
|
+
|
|
22
|
+
```bibtex
|
|
23
|
+
@misc{lieret2026swesweep,
|
|
24
|
+
title = {{SWE-sweep}: Can Agents Autonomously Find and Fix Bugs?},
|
|
25
|
+
author = {Kilian Lieret and Jeffrey Jian Ma and Rahul Kindi and
|
|
26
|
+
Yuxiang Wei and Jeremy Ma and Sten Sootla and
|
|
27
|
+
Parth Thakkar and Chao Beyond Zhou and Pengcheng Yin and
|
|
28
|
+
Rui Hou and Ofir Press and John Yang},
|
|
29
|
+
year = {2026},
|
|
30
|
+
note = {Preprint},
|
|
31
|
+
url = {https://github.com/facebookresearch/swe-sweep}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@inproceedings{yang2024sweagent,
|
|
35
|
+
title={{SWE}-agent: Agent-Computer Interfaces Enable Automated Software Engineering},
|
|
36
|
+
author={John Yang and Carlos E Jimenez and Alexander Wettig and Kilian Lieret and Shunyu Yao and Karthik R Narasimhan and Ofir Press},
|
|
37
|
+
booktitle={The Thirty-eighth Annual Conference on Neural Information Processing Systems},
|
|
38
|
+
year={2024},
|
|
39
|
+
url={https://arxiv.org/abs/2405.15793}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mini-swarm"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "mini-swe-agent, but with more agents: a minimal agent swarm"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
keywords = ["nlp", "agents", "code"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Operating System :: POSIX :: Linux",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
]
|
|
20
|
+
requires-python = ">=3.11"
|
|
21
|
+
dependencies = [
|
|
22
|
+
"mini-swe-agent>=2.4.6,<2.5", # its agents, models, environments and configs are the ones mini-swarm runs
|
|
23
|
+
"pyyaml",
|
|
24
|
+
"pydantic>=2.0",
|
|
25
|
+
"rich",
|
|
26
|
+
"typer",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dev = ["pytest"]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
swarm = "miniswarm.run.swarm:app"
|
|
34
|
+
mini-swarm = "miniswarm.run.swarm:app"
|
|
35
|
+
|
|
36
|
+
[tool.setuptools.packages.find]
|
|
37
|
+
where = ["src"]
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.package-data]
|
|
40
|
+
miniswarm = ["queue/units.sh"]
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.dynamic]
|
|
43
|
+
version = { attr = "miniswarm.__version__" }
|
|
44
|
+
|
|
45
|
+
[tool.pytest.ini_options]
|
|
46
|
+
testpaths = ["tests"]
|
|
47
|
+
pythonpath = ["src"]
|
|
@@ -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,26 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/mini_swarm.egg-info/PKG-INFO
|
|
5
|
+
src/mini_swarm.egg-info/SOURCES.txt
|
|
6
|
+
src/mini_swarm.egg-info/dependency_links.txt
|
|
7
|
+
src/mini_swarm.egg-info/entry_points.txt
|
|
8
|
+
src/mini_swarm.egg-info/requires.txt
|
|
9
|
+
src/mini_swarm.egg-info/top_level.txt
|
|
10
|
+
src/miniswarm/__init__.py
|
|
11
|
+
src/miniswarm/__main__.py
|
|
12
|
+
src/miniswarm/scripted.py
|
|
13
|
+
src/miniswarm/agents/__init__.py
|
|
14
|
+
src/miniswarm/agents/compaction.py
|
|
15
|
+
src/miniswarm/agents/swarm.py
|
|
16
|
+
src/miniswarm/queue/__init__.py
|
|
17
|
+
src/miniswarm/queue/units.sh
|
|
18
|
+
src/miniswarm/queue/units_sh.py
|
|
19
|
+
src/miniswarm/run/__init__.py
|
|
20
|
+
src/miniswarm/run/swarm.py
|
|
21
|
+
src/miniswarm/team/__init__.py
|
|
22
|
+
src/miniswarm/team/runner.py
|
|
23
|
+
src/miniswarm/team/triggers.py
|
|
24
|
+
src/miniswarm/team/workspace.py
|
|
25
|
+
src/miniswarm/utils/__init__.py
|
|
26
|
+
src/miniswarm/utils/files.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
miniswarm
|
|
@@ -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"
|
|
@@ -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)."""
|