Skip to content

Commit 8f14487

Browse files
committed
Merge remote-tracking branch 'origin/master' into perf/autonomous-loop-readonly-batch
# Conflicts: # swarms/agents/autonomous_loop.py
2 parents aae7e62 + 7a6eeeb commit 8f14487

42 files changed

Lines changed: 2957 additions & 2198 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/multi_agent/concurrent_examples/concurrent_mix.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@
1818
corporate law and ensure that all hiring practices are in compliance with
1919
state and federal regulations.
2020
""",
21-
model_name="claude-sonnet-4-20250514",
21+
model_name="claude-sonnet-5",
2222
max_loops=1,
2323
autosave=False,
2424
dashboard=False,
2525
verbose=True,
26-
output_type="str",
27-
artifacts_on=True,
28-
artifacts_output_path="delaware_ccorp_hiring_description.md",
29-
artifacts_file_extension=".md",
26+
temperature=None,
3027
)
3128

3229
indian_foreign_agent = Agent(
@@ -45,15 +42,12 @@
4542
implications of hiring foreign nationals and the requirements for obtaining
4643
necessary visas and work permits.
4744
""",
48-
model_name="claude-sonnet-4-20250514",
45+
model_name="claude-sonnet-5",
4946
max_loops=1,
5047
autosave=False,
5148
dashboard=False,
5249
verbose=True,
53-
output_type="str",
54-
artifacts_on=True,
55-
artifacts_output_path="indian_foreign_hiring_description.md",
56-
artifacts_file_extension=".md",
50+
temperature=None,
5751
)
5852

5953
# List of agents and corresponding tasks
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from swarms import Agent, HierarchicalSwarm
2+
3+
4+
def main() -> None:
5+
"""Run a director with two specialized workers.
6+
7+
Returns:
8+
None.
9+
"""
10+
researcher = Agent(
11+
agent_name="Researcher",
12+
agent_description="Finds relevant facts and key considerations.",
13+
system_prompt="Research the assigned topic and return concise facts.",
14+
model_name="gpt-5.4",
15+
max_loops=1,
16+
)
17+
writer = Agent(
18+
agent_name="Writer",
19+
agent_description="Turns research into a clear final explanation.",
20+
system_prompt="Write a concise explanation for a general audience.",
21+
model_name="gpt-5.4",
22+
max_loops=1,
23+
)
24+
25+
swarm = HierarchicalSwarm(
26+
name="ResearchWritingSwarm",
27+
description="Researches a topic and explains the findings.",
28+
agents=[researcher, writer],
29+
max_loops=1,
30+
)
31+
32+
result = swarm.run(
33+
"Explain three practical benefits of multi-agent systems."
34+
)
35+
print(result)
36+
37+
38+
if __name__ == "__main__":
39+
main()

pyproject.toml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
55

66
[tool.poetry]
77
name = "swarms"
8-
version = "14.0.2"
8+
version = "15.0.0"
99
description = "Swarms - TGSC"
1010
license = "Apache-2.0"
1111
authors = ["Kye Gomez <kye@swarms.world>"]
@@ -99,8 +99,6 @@ pytest = "*"
9999

100100
[tool.pytest.ini_options]
101101
testpaths = ["tests"]
102-
# Without this, pytest-asyncio's strict default silently skips every bare
103-
# `async def test_`, reporting it as a failure that never ran.
104102
asyncio_mode = "auto"
105103
markers = [
106104
"remote: tests that hit a real remote MCP server over the network",
@@ -109,12 +107,6 @@ markers = [
109107
[tool.ruff]
110108
line-length = 70
111109

112-
# Library code under swarms/ is held to the full rule set. Example scripts,
113-
# test helpers and one-off scripts are not: an availability probe imports a
114-
# package to see whether it is installed (F401), a demo loads dotenv before
115-
# importing (E402), and a teaching example catches everything so it can print
116-
# a friendly message (E722). Enforcing those there produces churn without
117-
# making the library safer.
118110
[tool.ruff.lint.per-file-ignores]
119111
"examples/**" = ["E402", "E721", "E722", "F401", "F402"]
120112
"tests/**" = ["E402", "E721", "E722", "F401", "F402"]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ networkx
1111
httpx
1212
requests
1313
litellm==1.76.1
14-
mcp>=1.28.1,<2.0.0
14+
mcp>=1.28.1,<3.0.0
1515
schedule
1616
opentelemetry-sdk
1717
opentelemetry-exporter-otlp-proto-http

swarms/__init__.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,36 @@
1414
from swarms.telemetry import * # noqa: E402, F403
1515
from swarms.tools import * # noqa: E402, F403
1616
from swarms.utils import * # noqa: E402, F403
17+
18+
19+
def __getattr__(name: str) -> str:
20+
"""Resolve ``swarms.__version__`` on first access.
21+
22+
The version comes from the installed distribution's metadata rather
23+
than a literal here, so it cannot drift from ``pyproject.toml``.
24+
Resolving it lazily keeps the dist-info scan off the import path for
25+
the majority of programs, which never read it.
26+
"""
27+
if name == "__version__":
28+
from importlib.metadata import (
29+
PackageNotFoundError,
30+
version,
31+
)
32+
33+
try:
34+
resolved = version("swarms")
35+
except PackageNotFoundError:
36+
# A source checkout with no installed distribution.
37+
resolved = "unknown"
38+
39+
globals()["__version__"] = resolved
40+
return resolved
41+
42+
raise AttributeError(
43+
f"module {__name__!r} has no attribute {name!r}"
44+
)
45+
46+
47+
def __dir__() -> list:
48+
"""Advertise ``__version__`` before anything has accessed it."""
49+
return sorted(set(globals()) | {"__version__"})

swarms/agents/autonomous_loop.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,42 @@ def _run_readonly_planning_tools(
195195

196196
batch.clear()
197197

198+
def _maybe_compress_context(self) -> bool:
199+
"""Compress the conversation when it nears the context limit.
200+
201+
``ContextCompressor`` measures and compacts
202+
``agent.short_memory``, but the request body actually sent to
203+
the model is ``self._transcript`` — so after a compaction the
204+
transcript is rebuilt around the summary. Compressing only the
205+
mirror would leave the payload growing unbounded, which is the
206+
failure the compressor exists to prevent.
207+
208+
Returns:
209+
bool: True when a compression ran and the transcript was
210+
re-seeded. The caller must then restore whatever immediate
211+
instruction the model needs (e.g. the prompt for the
212+
subtask in flight).
213+
"""
214+
compressor = getattr(self.agent, "_context_compressor", None)
215+
if compressor is None:
216+
return False
217+
summary = compressor.maybe_compress(self.agent)
218+
if summary is None:
219+
return False
220+
221+
# compact() already re-seeded short_memory with the summary,
222+
# so the transcript copy must not be mirrored back a second
223+
# time.
224+
self._transcript = Transcript()
225+
self._say_user(
226+
"[Compressed Memory Summary]\n"
227+
"Earlier turns were compressed to stay within the "
228+
"context window. Progress so far:\n\n"
229+
f"{summary}",
230+
mirror=False,
231+
)
232+
return True
233+
198234
def _run_autonomous_loop(
199235
self,
200236
task: Optional[Union[str, Any]] = None,
@@ -724,6 +760,16 @@ def _run_autonomous_loop(
724760
):
725761
subtask_iterations += 1
726762

763+
# Between iterations every recorded tool call has
764+
# been answered, so this is the one point the
765+
# transcript can be replaced without orphaning a
766+
# tool_call id.
767+
if self._maybe_compress_context():
768+
# The rebuilt transcript holds only the
769+
# summary; restore the instruction for the
770+
# subtask in flight.
771+
self._say_user(execution_prompt)
772+
727773
try:
728774
response = self.agent.call_llm(
729775
task=None,

swarms/prompts/agent_judge_prompt.py

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,3 @@
1-
HIERARCHICAL_SWARM_JUDGE_PROMPT = """
2-
# Hierarchical Swarm Judge — Evaluation Protocol
3-
4-
You are an elite evaluation agent embedded inside a hierarchical multi-agent swarm. Your sole responsibility is to rigorously assess the quality of every worker agent's output after each execution cycle and produce a structured, evidence-grounded scoring report.
5-
6-
You are NOT a worker agent. You do not perform the task. You evaluate those who did.
7-
8-
---
9-
10-
## Your Inputs
11-
12-
You will receive:
13-
1. **The original task** — what the swarm was asked to accomplish.
14-
2. **The director's plan** — the strategy and order assignments issued by the director.
15-
3. **Each agent's output** — the actual response produced by each worker agent.
16-
4. **Full conversation history** — the complete context of everything that occurred before you were called.
17-
18-
---
19-
20-
## Evaluation Dimensions
21-
22-
Score each agent on the following five dimensions. Each dimension is scored 0–10. The overall agent score is the weighted average defined below.
23-
24-
### 1. Task Adherence (weight: 25%)
25-
Did the agent actually do what it was assigned? Did it stay on topic and fulfill the specific order given by the director — not a paraphrase of it, not a tangential interpretation, but the precise assignment?
26-
27-
- **10**: Perfectly on-task. Every part of the assignment is addressed directly.
28-
- **7–9**: Mostly on-task with minor drift or omissions.
29-
- **4–6**: Partially addressed the assignment; significant gaps or off-topic content.
30-
- **1–3**: Largely ignored the assigned task; substituted its own agenda.
31-
- **0**: No relevance to the assigned task whatsoever.
32-
33-
### 2. Accuracy & Factual Integrity (weight: 25%)
34-
Are the claims, data points, and conclusions factually sound? Are assertions supported by reasoning or evidence, or are they speculative and unsupported?
35-
36-
- **10**: All claims are accurate, well-supported, and internally consistent.
37-
- **7–9**: Mostly accurate; minor unsupported claims or imprecise statements.
38-
- **4–6**: Several questionable claims or logical inconsistencies.
39-
- **1–3**: Significant factual errors or unsupported speculation throughout.
40-
- **0**: Output is factually unreliable or contradicts known information.
41-
42-
### 3. Depth & Completeness (weight: 20%)
43-
Did the agent produce a thorough, substantive response — or a shallow, surface-level one? Were edge cases, nuances, and implications considered?
44-
45-
- **10**: Comprehensive. Covers all relevant angles with appropriate depth.
46-
- **7–9**: Solid depth; a few areas could be expanded.
47-
- **4–6**: Superficial in key areas; missing important dimensions.
48-
- **1–3**: Very thin output; little substance beyond restatement of the task.
49-
- **0**: Empty, trivially short, or entirely non-substantive.
50-
51-
### 4. Clarity & Communication (weight: 15%)
52-
Is the output well-structured, readable, and unambiguous? Could a downstream agent or human act on this output without confusion?
53-
54-
- **10**: Exceptionally clear, logically organized, precise language throughout.
55-
- **7–9**: Clear and readable; minor structural or phrasing issues.
56-
- **4–6**: Understandable but poorly organized or unnecessarily verbose/terse.
57-
- **1–3**: Confusing, disorganized, or full of ambiguous statements.
58-
- **0**: Incomprehensible or self-contradictory.
59-
60-
### 5. Contribution to Swarm Goal (weight: 15%)
61-
Considering the swarm's overall objective, did this agent's output move the mission forward? Did it produce something that other agents or the director can build upon?
62-
63-
- **10**: Directly advances the collective goal; highly actionable by downstream agents.
64-
- **7–9**: Useful contribution; minor gaps in handoff value.
65-
- **4–6**: Marginally useful; another agent would need to redo significant work.
66-
- **1–3**: Redundant, contradicts other agents, or creates confusion downstream.
67-
- **0**: Actively harmful to the swarm's progress.
68-
69-
---
70-
71-
## Composite Score Formula
72-
73-
```
74-
composite_score = (
75-
task_adherence * 0.25 +
76-
accuracy * 0.25 +
77-
depth_completeness * 0.20 +
78-
clarity * 0.15 +
79-
swarm_contribution * 0.15
80-
)
81-
```
82-
83-
Round to the nearest integer (0–10) for the final `score` field.
84-
85-
---
86-
87-
## Reasoning Standards
88-
89-
Your `reasoning` field for each agent must:
90-
- Cite **specific content** from the agent's output (quote or paraphrase concrete examples).
91-
- Identify **what was done well** before identifying weaknesses.
92-
- Avoid vague language like "good job" or "needs improvement" — every claim must be specific.
93-
- Be no shorter than 3 sentences and no longer than 8 sentences.
94-
95-
Your `suggestions` field must:
96-
- Give **concrete, actionable** improvement directions — not generic advice.
97-
- Specify *what* the agent should add, remove, or restructure in future iterations.
98-
- Be grounded in the gap between what was produced and what was needed.
99-
100-
---
101-
102-
## Overall Report Standards
103-
104-
Your `summary` must:
105-
- Synthesize how the agents performed **as a collective**, not just individually.
106-
- Identify the strongest and weakest agent by name.
107-
- Note any critical gaps in the swarm's combined output that the director should address in the next loop.
108-
- Be 3–6 sentences.
109-
110-
Your `overall_quality` score must reflect the swarm's collective output quality — not the average of individual scores. Weight it toward the degree to which the swarm, as a whole, accomplished the original task.
111-
112-
---
113-
114-
## Behavioral Rules
115-
116-
- **Never hallucinate agent outputs.** Only evaluate what was actually provided.
117-
- **Never praise without evidence.** Every positive statement must cite something specific.
118-
- **Never penalize for scope.** Agents are only responsible for their assigned order — not the entire task.
119-
- **Maintain calibration.** A score of 10 should be genuinely exceptional. A score of 5 is mediocre but functional. Reserve 0–2 for outputs that are harmful or completely off-task.
120-
- **Be adversarially honest.** The purpose of your evaluation is to improve the swarm in subsequent loops — not to make agents feel good.
121-
122-
---
123-
124-
## Output Format
125-
126-
You must return a valid `JudgeReport` using the provided tool schema. Do not include any text outside the structured tool call.
127-
"""
128-
129-
1301
AGENT_JUDGE_PROMPT = """
1312
# Adaptive Output Evaluator - Role and Protocol
1323

0 commit comments

Comments
 (0)