swarms 7.7.2__py3-none-any.whl → 7.7.4__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.
- swarms/prompts/ag_prompt.py +51 -19
- swarms/prompts/agent_system_prompts.py +13 -4
- swarms/prompts/multi_agent_collab_prompt.py +18 -0
- swarms/prompts/prompt.py +6 -10
- swarms/schemas/__init__.py +0 -3
- swarms/structs/__init__.py +2 -4
- swarms/structs/agent.py +201 -160
- swarms/structs/aop.py +8 -1
- swarms/structs/auto_swarm_builder.py +271 -210
- swarms/structs/conversation.py +22 -65
- swarms/structs/hiearchical_swarm.py +94 -123
- swarms/structs/hybrid_hiearchical_peer_swarm.py +1 -1
- swarms/structs/ma_utils.py +96 -0
- swarms/structs/mixture_of_agents.py +20 -103
- swarms/structs/multi_agent_router.py +32 -95
- swarms/structs/multi_model_gpu_manager.py +1447 -0
- swarms/structs/output_types.py +3 -16
- swarms/structs/stopping_conditions.py +30 -0
- swarms/structs/swarm_arange.py +18 -15
- swarms/structs/swarm_router.py +56 -4
- swarms/structs/swarming_architectures.py +576 -185
- swarms/telemetry/main.py +1 -7
- swarms/tools/mcp_client.py +209 -53
- swarms/tools/mcp_integration.py +1 -53
- swarms/utils/generate_keys.py +64 -0
- swarms/utils/history_output_formatter.py +2 -0
- {swarms-7.7.2.dist-info → swarms-7.7.4.dist-info}/METADATA +98 -263
- {swarms-7.7.2.dist-info → swarms-7.7.4.dist-info}/RECORD +31 -34
- swarms/schemas/agent_input_schema.py +0 -149
- swarms/structs/agents_available.py +0 -87
- swarms/structs/graph_swarm.py +0 -612
- swarms/structs/queue_swarm.py +0 -193
- swarms/structs/swarm_builder.py +0 -395
- swarms/structs/swarm_output_type.py +0 -23
- {swarms-7.7.2.dist-info → swarms-7.7.4.dist-info}/LICENSE +0 -0
- {swarms-7.7.2.dist-info → swarms-7.7.4.dist-info}/WHEEL +0 -0
- {swarms-7.7.2.dist-info → swarms-7.7.4.dist-info}/entry_points.txt +0 -0
swarms/structs/output_types.py
CHANGED
@@ -1,19 +1,6 @@
|
|
1
|
-
from
|
2
|
-
|
3
|
-
|
4
|
-
OutputType = Literal[
|
5
|
-
"all",
|
6
|
-
"final",
|
7
|
-
"list",
|
8
|
-
"dict",
|
9
|
-
".json",
|
10
|
-
".md",
|
11
|
-
".txt",
|
12
|
-
".yaml",
|
13
|
-
".toml",
|
14
|
-
"string",
|
15
|
-
"str",
|
16
|
-
]
|
1
|
+
from swarms.utils.history_output_formatter import (
|
2
|
+
HistoryOutputType as OutputType,
|
3
|
+
)
|
17
4
|
|
18
5
|
# Use the OutputType for type annotations
|
19
6
|
output_type: OutputType
|
@@ -36,3 +36,33 @@ def check_exit(s):
|
|
36
36
|
|
37
37
|
def check_end(s):
|
38
38
|
return "end" in s
|
39
|
+
|
40
|
+
|
41
|
+
def check_stopping_conditions(input: str) -> str:
|
42
|
+
"""
|
43
|
+
Checks a string against all stopping conditions and returns an appropriate message.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
s (str): The input string to check
|
47
|
+
|
48
|
+
Returns:
|
49
|
+
str: A message indicating which stopping condition was met, or None if no condition was met
|
50
|
+
"""
|
51
|
+
conditions = [
|
52
|
+
(check_done, "Task is done"),
|
53
|
+
(check_finished, "Task is finished"),
|
54
|
+
(check_complete, "Task is complete"),
|
55
|
+
(check_success, "Task succeeded"),
|
56
|
+
(check_failure, "Task failed"),
|
57
|
+
(check_error, "Task encountered an error"),
|
58
|
+
(check_stopped, "Task was stopped"),
|
59
|
+
(check_cancelled, "Task was cancelled"),
|
60
|
+
(check_exit, "Task exited"),
|
61
|
+
(check_end, "Task ended"),
|
62
|
+
]
|
63
|
+
|
64
|
+
for check_func, message in conditions:
|
65
|
+
if check_func(input):
|
66
|
+
return message
|
67
|
+
|
68
|
+
return None
|
swarms/structs/swarm_arange.py
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
import threading
|
2
|
-
import time
|
3
2
|
import uuid
|
4
3
|
from typing import Any, Callable, Dict, List, Optional
|
5
4
|
|
6
5
|
from swarms.utils.any_to_str import any_to_str
|
7
6
|
from swarms.utils.loguru_logger import initialize_logger
|
7
|
+
from swarms.structs.conversation import Conversation
|
8
|
+
from swarms.utils.history_output_formatter import (
|
9
|
+
output_type,
|
10
|
+
)
|
8
11
|
|
9
12
|
logger = initialize_logger(log_folder="swarm_arange")
|
10
13
|
|
@@ -13,20 +16,6 @@ def swarm_id():
|
|
13
16
|
return uuid.uuid4().hex
|
14
17
|
|
15
18
|
|
16
|
-
class SwarmArrangeInput:
|
17
|
-
id: str = uuid.uuid4().hex
|
18
|
-
time_stamp: str = time.strftime("%Y-%m-%d %H:%M:%S")
|
19
|
-
name: str
|
20
|
-
description: str
|
21
|
-
swarms: List[Callable] = []
|
22
|
-
output_type: str
|
23
|
-
flow: str = ""
|
24
|
-
|
25
|
-
|
26
|
-
class SwarmArrangeOutput:
|
27
|
-
input_config: SwarmArrangeInput = None
|
28
|
-
|
29
|
-
|
30
19
|
class SwarmRearrange:
|
31
20
|
"""
|
32
21
|
A class representing a swarm of swarms for rearranging tasks.
|
@@ -69,6 +58,7 @@ class SwarmRearrange:
|
|
69
58
|
Callable[[str], str]
|
70
59
|
] = None,
|
71
60
|
return_json: bool = False,
|
61
|
+
output_type: output_type = "dict-all-except-first",
|
72
62
|
*args,
|
73
63
|
**kwargs,
|
74
64
|
):
|
@@ -96,7 +86,9 @@ class SwarmRearrange:
|
|
96
86
|
self.verbose = verbose
|
97
87
|
self.human_in_the_loop = human_in_the_loop
|
98
88
|
self.custom_human_in_the_loop = custom_human_in_the_loop
|
89
|
+
self.output_type = output_type
|
99
90
|
self.return_json = return_json
|
91
|
+
|
100
92
|
self.swarm_history = {swarm.name: [] for swarm in swarms}
|
101
93
|
self.lock = threading.Lock()
|
102
94
|
self.id = uuid.uuid4().hex if id is None else id
|
@@ -104,6 +96,9 @@ class SwarmRearrange:
|
|
104
96
|
# Run the reliability checks
|
105
97
|
self.reliability_checks()
|
106
98
|
|
99
|
+
# Conversation
|
100
|
+
self.conversation = Conversation()
|
101
|
+
|
107
102
|
def reliability_checks(self):
|
108
103
|
logger.info("Running reliability checks.")
|
109
104
|
if not self.swarms:
|
@@ -283,6 +278,10 @@ class SwarmRearrange:
|
|
283
278
|
current_task, img, *args, **kwargs
|
284
279
|
)
|
285
280
|
result = any_to_str(result)
|
281
|
+
self.conversation.add(
|
282
|
+
role=swarm.name, content=result
|
283
|
+
)
|
284
|
+
|
286
285
|
logger.info(
|
287
286
|
f"Swarm {swarm_name} returned result of type: {type(result)}"
|
288
287
|
)
|
@@ -325,6 +324,10 @@ class SwarmRearrange:
|
|
325
324
|
current_task, img, *args, **kwargs
|
326
325
|
)
|
327
326
|
result = any_to_str(result)
|
327
|
+
|
328
|
+
self.conversation.add(
|
329
|
+
role=swarm.name, content=result
|
330
|
+
)
|
328
331
|
logger.info(
|
329
332
|
f"Swarm {swarm_name} returned result of type: {type(result)}"
|
330
333
|
)
|
swarms/structs/swarm_router.py
CHANGED
@@ -5,7 +5,9 @@ from typing import Any, Callable, Dict, List, Literal, Optional, Union
|
|
5
5
|
|
6
6
|
from pydantic import BaseModel, Field
|
7
7
|
|
8
|
-
from swarms.prompts.
|
8
|
+
from swarms.prompts.multi_agent_collab_prompt import (
|
9
|
+
MULTI_AGENT_COLLAB_PROMPT_TWO,
|
10
|
+
)
|
9
11
|
from swarms.structs.agent import Agent
|
10
12
|
from swarms.structs.concurrent_workflow import ConcurrentWorkflow
|
11
13
|
from swarms.structs.csv_to_agent import AgentLoader
|
@@ -66,6 +68,38 @@ class SwarmLog(BaseModel):
|
|
66
68
|
documents: List[Document] = []
|
67
69
|
|
68
70
|
|
71
|
+
class SwarmRouterConfig(BaseModel):
|
72
|
+
"""Configuration model for SwarmRouter."""
|
73
|
+
|
74
|
+
name: str = Field(
|
75
|
+
description="Name identifier for the SwarmRouter instance",
|
76
|
+
)
|
77
|
+
description: str = Field(
|
78
|
+
description="Description of the SwarmRouter's purpose",
|
79
|
+
)
|
80
|
+
# max_loops: int = Field(
|
81
|
+
# description="Maximum number of execution loops"
|
82
|
+
# )
|
83
|
+
swarm_type: SwarmType = Field(
|
84
|
+
description="Type of swarm to use",
|
85
|
+
)
|
86
|
+
rearrange_flow: Optional[str] = Field(
|
87
|
+
description="Flow configuration string"
|
88
|
+
)
|
89
|
+
rules: Optional[str] = Field(
|
90
|
+
description="Rules to inject into every agent"
|
91
|
+
)
|
92
|
+
multi_agent_collab_prompt: bool = Field(
|
93
|
+
description="Whether to enable multi-agent collaboration prompts",
|
94
|
+
)
|
95
|
+
task: str = Field(
|
96
|
+
description="The task to be executed by the swarm",
|
97
|
+
)
|
98
|
+
|
99
|
+
class Config:
|
100
|
+
arbitrary_types_allowed = True
|
101
|
+
|
102
|
+
|
69
103
|
class SwarmRouter:
|
70
104
|
"""
|
71
105
|
A class that dynamically routes tasks to different swarm types based on user selection or automatic matching.
|
@@ -157,6 +191,7 @@ class SwarmRouter:
|
|
157
191
|
load_agents_from_csv: bool = False,
|
158
192
|
csv_file_path: str = None,
|
159
193
|
return_entire_history: bool = True,
|
194
|
+
multi_agent_collab_prompt: bool = True,
|
160
195
|
*args,
|
161
196
|
**kwargs,
|
162
197
|
):
|
@@ -179,14 +214,18 @@ class SwarmRouter:
|
|
179
214
|
self.load_agents_from_csv = load_agents_from_csv
|
180
215
|
self.csv_file_path = csv_file_path
|
181
216
|
self.return_entire_history = return_entire_history
|
217
|
+
self.multi_agent_collab_prompt = multi_agent_collab_prompt
|
182
218
|
|
219
|
+
# Reliability check
|
220
|
+
self.reliability_check()
|
221
|
+
|
222
|
+
# Load agents from CSV
|
183
223
|
if self.load_agents_from_csv:
|
184
224
|
self.agents = AgentLoader(
|
185
225
|
csv_path=self.csv_file_path
|
186
226
|
).load_agents()
|
187
227
|
|
188
|
-
|
189
|
-
|
228
|
+
# Log initialization
|
190
229
|
self._log(
|
191
230
|
"info",
|
192
231
|
f"SwarmRouter initialized with swarm type: {swarm_type}",
|
@@ -345,7 +384,6 @@ class SwarmRouter:
|
|
345
384
|
name=self.name,
|
346
385
|
description=self.description,
|
347
386
|
agents=self.agents,
|
348
|
-
aggregator_system_prompt=aggregator_system_prompt.get_prompt(),
|
349
387
|
aggregator_agent=self.agents[-1],
|
350
388
|
layers=self.max_loops,
|
351
389
|
output_type=self.output_type,
|
@@ -421,6 +459,17 @@ class SwarmRouter:
|
|
421
459
|
f"Invalid swarm type: {self.swarm_type} try again with a valid swarm type such as 'SequentialWorkflow' or 'ConcurrentWorkflow' or 'auto' or 'AgentRearrange' or 'MixtureOfAgents' or 'SpreadSheetSwarm'"
|
422
460
|
)
|
423
461
|
|
462
|
+
def update_system_prompt_for_agent_in_swarm(self):
|
463
|
+
# Use list comprehension for faster iteration
|
464
|
+
[
|
465
|
+
setattr(
|
466
|
+
agent,
|
467
|
+
"system_prompt",
|
468
|
+
agent.system_prompt + MULTI_AGENT_COLLAB_PROMPT_TWO,
|
469
|
+
)
|
470
|
+
for agent in self.agents
|
471
|
+
]
|
472
|
+
|
424
473
|
def _log(
|
425
474
|
self,
|
426
475
|
level: str,
|
@@ -464,6 +513,9 @@ class SwarmRouter:
|
|
464
513
|
"""
|
465
514
|
self.swarm = self._create_swarm(task, *args, **kwargs)
|
466
515
|
|
516
|
+
if self.multi_agent_collab_prompt is True:
|
517
|
+
self.update_system_prompt_for_agent_in_swarm()
|
518
|
+
|
467
519
|
try:
|
468
520
|
logger.info(
|
469
521
|
f"Running task on {self.swarm_type} swarm with task: {task}"
|