Skip to content

Commit e307b20

Browse files
committed
[feat][auto-equip-respond][auto inject respond tool into groupchat
agents][bugf][router-groupchat-params][forward output type and verbose to groupchat][feat][groupchat-examples][add dynamic and router groupchat examples][docs][example-readmes][list new examples in readmes][improvement][version-bump][bump package version to 12.0.3]
1 parent 604613f commit e307b20

8 files changed

Lines changed: 86 additions & 5 deletions

File tree

dynamic_groupchat_example.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import json
22

3-
from swarms import RESPOND_TOOL, Agent, GroupChat
3+
from swarms import Agent, GroupChat
44

55
a1 = Agent(
66
agent_name="Researcher",
77
system_prompt="You are a research-minded agent who values evidence.",
88
model_name="gpt-5.5",
99
max_loops=1,
1010
persistent_memory=False,
11-
tools_list_dictionary=[RESPOND_TOOL],
11+
print_on=True,
1212
output_type="final",
1313
)
1414

@@ -17,7 +17,7 @@
1717
system_prompt="You push back on weak claims and ask sharp questions.",
1818
model_name="claude-haiku-4-5",
1919
max_loops=1,
20-
tools_list_dictionary=[RESPOND_TOOL],
20+
print_on=True,
2121
persistent_memory=False,
2222
output_type="final",
2323
)
@@ -27,8 +27,8 @@
2727
system_prompt="You turn ideas into concrete next steps.",
2828
model_name="gpt-5.5",
2929
max_loops=1,
30-
tools_list_dictionary=[RESPOND_TOOL],
3130
persistent_memory=False,
31+
print_on=True,
3232
output_type="final",
3333
)
3434

@@ -38,7 +38,9 @@
3838
threshold=0.6,
3939
output_type="dict",
4040
)
41+
4142
result = chat.run(
4243
"Should we use vector databases or knowledge graphs for agent memory?"
4344
)
45+
4446
print(json.dumps(result, indent=4))

examples/multi_agent/groupchat/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This directory contains examples demonstrating the dynamic `GroupChat` — an as
44

55
## Examples
66

7+
- [dynamic_groupchat_example.py](dynamic_groupchat_example.py) - Minimal dynamic groupchat walkthrough
78
- [enhanced_collaboration_example.py](enhanced_collaboration_example.py) - Analyst / researcher / strategist scenarios
89
- [medical_panel_example.py](medical_panel_example.py) - Panel of medical specialists discussing a complex multi-system case
910
- [quantum_physics_swarm.py](quantum_physics_swarm.py) - Condensed-matter physics research team
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import json
2+
3+
from swarms import RESPOND_TOOL, Agent, GroupChat
4+
5+
a1 = Agent(
6+
agent_name="Researcher",
7+
system_prompt="You are a research-minded agent who values evidence.",
8+
model_name="gpt-5.5",
9+
max_loops=1,
10+
persistent_memory=False,
11+
# tools_list_dictionary=[RESPOND_TOOL],
12+
output_type="final",
13+
)
14+
15+
a2 = Agent(
16+
agent_name="Skeptic",
17+
system_prompt="You push back on weak claims and ask sharp questions.",
18+
model_name="claude-haiku-4-5",
19+
max_loops=1,
20+
# tools_list_dictionary=[RESPOND_TOOL],
21+
persistent_memory=False,
22+
output_type="final",
23+
)
24+
25+
a3 = Agent(
26+
agent_name="Builder",
27+
system_prompt="You turn ideas into concrete next steps.",
28+
model_name="gpt-5.5",
29+
max_loops=1,
30+
tools_list_dictionary=[RESPOND_TOOL],
31+
persistent_memory=False,
32+
output_type="final",
33+
)
34+
35+
chat = GroupChat(
36+
agents=[a1, a2, a3],
37+
max_loops=4,
38+
threshold=0.6,
39+
output_type="dict",
40+
)
41+
42+
result = chat.run(
43+
"Should we use vector databases or knowledge graphs for agent memory?"
44+
)
45+
46+
print(json.dumps(result, indent=4))

examples/multi_agent/swarm_router/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This directory contains examples demonstrating swarm routing patterns for direct
44

55
## Examples
66

7+
- [groupchat_swarm_router_example.py](groupchat_swarm_router_example.py) - Self-selecting groupchat via SwarmRouter
78
- [heavy_swarm_router_example.py](heavy_swarm_router_example.py) - Router for heavy swarms
89
- [market_analysis_swarm_router_concurrent.py](market_analysis_swarm_router_concurrent.py) - Concurrent market analysis router
910
- [sr_moa_example.py](sr_moa_example.py) - Swarm router with MOA

groupchat_swarm_router_example.py renamed to examples/multi_agent/swarm_router/groupchat_swarm_router_example.py

File renamed without changes.

pyproject.toml

Lines changed: 1 addition & 1 deletion
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 = "12.0.2"
8+
version = "12.0.3"
99
description = "Swarms - TGSC"
1010
license = "Apache-2.0"
1111
authors = ["Kye Gomez <kye@swarms.world>"]

swarms/structs/groupchat.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def __init__(
195195
output_type: str = "str-all-except-first",
196196
verbose: bool = False,
197197
print_on: bool = True,
198+
auto_equip: bool = True,
198199
):
199200
"""Initialize the dynamic groupchat runtime.
200201
@@ -222,12 +223,40 @@ def __init__(
222223
self.output_type = output_type
223224
self.verbose = verbose
224225
self.print_on = print_on
226+
self.auto_equip = auto_equip
225227

226228
self.conversation = Conversation(time_enabled=True)
227229

228230
if len(self.agents) < 2:
229231
raise ValueError("GroupChat requires at least 2 agents.")
230232

233+
if self.auto_equip:
234+
self._ensure_respond_tool()
235+
236+
def _ensure_respond_tool(self) -> None:
237+
"""Inject ``RESPOND_TOOL`` into agents that do not already carry it.
238+
239+
Without the ``respond`` tool an agent's speaking decision can never be
240+
parsed, so it would sit silent for the whole chat. The agent's LLM
241+
client bakes ``tools_list_dictionary`` in at construction time, so
242+
after appending the schema the client is rebuilt via
243+
``llm_handling()``.
244+
"""
245+
for agent in self.agents:
246+
tools = agent.tools_list_dictionary or []
247+
if any(
248+
tool.get("function", {}).get("name") == "respond"
249+
for tool in tools
250+
if isinstance(tool, dict)
251+
):
252+
continue
253+
agent.tools_list_dictionary = [*tools, RESPOND_TOOL]
254+
agent.llm = agent.llm_handling()
255+
self._log(
256+
"info",
257+
f"Injected respond tool into {agent.agent_name}",
258+
)
259+
231260
def _other_agents(self, exclude: str) -> str:
232261
"""Return a comma-separated list of peers visible to one agent."""
233262
return ", ".join(

swarms/structs/swarm_router.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,8 @@ def _create_group_chat(self, *args, **kwargs):
708708
description=self.description,
709709
agents=self.agents,
710710
max_loops=self.max_loops,
711+
output_type=self.output_type,
712+
verbose=self.verbose,
711713
*args,
712714
**kwargs,
713715
)

0 commit comments

Comments
 (0)