swarms 7.6.2__py3-none-any.whl → 7.6.5__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/__init__.py +1 -0
- swarms/agents/__init__.py +0 -3
- swarms/agents/flexion_agent.py +2 -1
- swarms/client/__init__.py +15 -0
- swarms/prompts/multi_agent_collab_prompt.py +313 -0
- swarms/structs/__init__.py +5 -17
- swarms/structs/agent.py +219 -255
- swarms/structs/base_swarm.py +0 -7
- swarms/structs/concurrent_workflow.py +1 -1
- swarms/structs/conversation.py +16 -2
- swarms/structs/de_hallucination_swarm.py +8 -4
- swarms/structs/groupchat.py +80 -84
- swarms/structs/hybrid_hiearchical_peer_swarm.py +23 -40
- swarms/structs/multi_agent_exec.py +63 -139
- swarms/structs/rearrange.py +65 -204
- swarms/structs/sequential_workflow.py +34 -47
- swarms/structs/swarm_router.py +2 -1
- swarms/telemetry/bootup.py +19 -38
- swarms/telemetry/main.py +56 -20
- swarms/tools/mcp_integration.py +321 -483
- swarms/utils/auto_download_check_packages.py +2 -2
- swarms/utils/disable_logging.py +0 -17
- swarms/utils/history_output_formatter.py +8 -3
- swarms/utils/litellm_wrapper.py +117 -1
- swarms/utils/vllm_wrapper.py +146 -0
- {swarms-7.6.2.dist-info → swarms-7.6.5.dist-info}/METADATA +1 -5
- {swarms-7.6.2.dist-info → swarms-7.6.5.dist-info}/RECORD +31 -31
- swarms/structs/auto_swarm.py +0 -229
- swarms/utils/agent_ops_check.py +0 -26
- swarms/utils/pandas_utils.py +0 -92
- /swarms/{structs/swarms_api.py → client/main.py} +0 -0
- {swarms-7.6.2.dist-info → swarms-7.6.5.dist-info}/LICENSE +0 -0
- {swarms-7.6.2.dist-info → swarms-7.6.5.dist-info}/WHEEL +0 -0
- {swarms-7.6.2.dist-info → swarms-7.6.5.dist-info}/entry_points.txt +0 -0
swarms/structs/auto_swarm.py
DELETED
@@ -1,229 +0,0 @@
|
|
1
|
-
from typing import Any, Callable, Dict, Optional, Sequence
|
2
|
-
|
3
|
-
from swarms.structs.base_swarm import BaseSwarm
|
4
|
-
from swarms.utils.loguru_logger import logger
|
5
|
-
|
6
|
-
|
7
|
-
class AutoSwarmRouter(BaseSwarm):
|
8
|
-
"""AutoSwarmRouter class represents a router for the AutoSwarm class.
|
9
|
-
|
10
|
-
This class is responsible for routing tasks to the appropriate swarm based on the provided name.
|
11
|
-
It allows customization of the preprocessing, routing, and postprocessing of tasks.
|
12
|
-
|
13
|
-
Attributes:
|
14
|
-
name (str): The name of the router.
|
15
|
-
description (str): The description of the router.
|
16
|
-
verbose (bool): Whether to enable verbose mode.
|
17
|
-
custom_params (dict): Custom parameters for the router.
|
18
|
-
swarms (list): A list of BaseSwarm objects.
|
19
|
-
custom_preprocess (callable): Custom preprocessing function for tasks.
|
20
|
-
custom_postprocess (callable): Custom postprocessing function for task results.
|
21
|
-
custom_router (callable): Custom routing function for tasks.
|
22
|
-
|
23
|
-
Methods:
|
24
|
-
run(task: str = None, *args, **kwargs) -> Any:
|
25
|
-
Run the swarm simulation and route the task to the appropriate swarm.
|
26
|
-
|
27
|
-
Flow:
|
28
|
-
name -> router -> swarm entry point
|
29
|
-
"""
|
30
|
-
|
31
|
-
def __init__(
|
32
|
-
self,
|
33
|
-
name: Optional[str] = None,
|
34
|
-
description: Optional[str] = None,
|
35
|
-
verbose: bool = False,
|
36
|
-
custom_params: Optional[Dict[str, Any]] = None,
|
37
|
-
swarms: Sequence[BaseSwarm] = None,
|
38
|
-
custom_preprocess: Optional[Callable] = None,
|
39
|
-
custom_postprocess: Optional[Callable] = None,
|
40
|
-
custom_router: Optional[Callable] = None,
|
41
|
-
*args,
|
42
|
-
**kwargs,
|
43
|
-
):
|
44
|
-
super().__init__(
|
45
|
-
name=name, description=description, *args, **kwargs
|
46
|
-
)
|
47
|
-
self.name = name
|
48
|
-
self.description = description
|
49
|
-
self.verbose = verbose
|
50
|
-
self.custom_params = custom_params
|
51
|
-
self.swarms = swarms
|
52
|
-
self.custom_preprocess = custom_preprocess
|
53
|
-
self.custom_postprocess = custom_postprocess
|
54
|
-
self.custom_router = custom_router
|
55
|
-
|
56
|
-
# Create a dictionary of swarms
|
57
|
-
self.swarm_dict = {swarm.name: swarm for swarm in self.swarms}
|
58
|
-
|
59
|
-
logger.info(
|
60
|
-
f"AutoSwarmRouter has been initialized with {self.len_of_swarms()} swarms."
|
61
|
-
)
|
62
|
-
|
63
|
-
def run(self, task: str = None, *args, **kwargs):
|
64
|
-
try:
|
65
|
-
"""Run the swarm simulation and route the task to the appropriate swarm."""
|
66
|
-
|
67
|
-
if self.custom_preprocess:
|
68
|
-
# If custom preprocess function is provided then run it
|
69
|
-
logger.info("Running custom preprocess function.")
|
70
|
-
task, args, kwargs = self.custom_preprocess(
|
71
|
-
task, args, kwargs
|
72
|
-
)
|
73
|
-
|
74
|
-
if self.custom_router:
|
75
|
-
# If custom router function is provided then use it to route the task
|
76
|
-
logger.info("Running custom router function.")
|
77
|
-
out = self.custom_router(self, task, *args, **kwargs)
|
78
|
-
|
79
|
-
if self.custom_postprocess:
|
80
|
-
# If custom postprocess function is provided then run it
|
81
|
-
out = self.custom_postprocess(out)
|
82
|
-
|
83
|
-
return out
|
84
|
-
|
85
|
-
if self.name in self.swarm_dict:
|
86
|
-
# If a match is found then send the task to the swarm
|
87
|
-
out = self.swarm_dict[self.name].run(
|
88
|
-
task, *args, **kwargs
|
89
|
-
)
|
90
|
-
|
91
|
-
if self.custom_postprocess:
|
92
|
-
# If custom postprocess function is provided then run it
|
93
|
-
out = self.custom_postprocess(out)
|
94
|
-
|
95
|
-
return out
|
96
|
-
|
97
|
-
# If no match is found then return None
|
98
|
-
raise ValueError(
|
99
|
-
f"Swarm with name {self.name} not found."
|
100
|
-
)
|
101
|
-
except Exception as e:
|
102
|
-
logger.error(f"Error: {e}")
|
103
|
-
raise e
|
104
|
-
|
105
|
-
def len_of_swarms(self):
|
106
|
-
return print(len(self.swarms))
|
107
|
-
|
108
|
-
def list_available_swarms(self):
|
109
|
-
for swarm in self.swarms:
|
110
|
-
try:
|
111
|
-
logger.info(
|
112
|
-
f"Swarm Name: {swarm.name} || Swarm Description: {swarm.description} "
|
113
|
-
)
|
114
|
-
except Exception as error:
|
115
|
-
logger.error(
|
116
|
-
f"Error Detected You may not have swarms available: {error}"
|
117
|
-
)
|
118
|
-
raise error
|
119
|
-
|
120
|
-
|
121
|
-
class AutoSwarm(BaseSwarm):
|
122
|
-
"""AutoSwarm class represents a swarm of agents that can be created automatically.
|
123
|
-
|
124
|
-
Flow:
|
125
|
-
name -> router -> swarm entry point
|
126
|
-
|
127
|
-
Args:
|
128
|
-
name (Optional[str]): The name of the swarm. Defaults to None.
|
129
|
-
description (Optional[str]): The description of the swarm. Defaults to None.
|
130
|
-
verbose (bool): Whether to enable verbose mode. Defaults to False.
|
131
|
-
custom_params (Optional[Dict[str, Any]]): Custom parameters for the swarm. Defaults to None.
|
132
|
-
router (Optional[AutoSwarmRouter]): The router for the swarm. Defaults to None.
|
133
|
-
"""
|
134
|
-
|
135
|
-
def __init__(
|
136
|
-
self,
|
137
|
-
name: Optional[str] = None,
|
138
|
-
description: Optional[str] = None,
|
139
|
-
verbose: bool = False,
|
140
|
-
custom_params: Optional[Dict[str, Any]] = None,
|
141
|
-
custom_preprocess: Optional[Callable] = None,
|
142
|
-
custom_postprocess: Optional[Callable] = None,
|
143
|
-
custom_router: Optional[Callable] = None,
|
144
|
-
max_loops: int = 1,
|
145
|
-
*args,
|
146
|
-
**kwargs,
|
147
|
-
):
|
148
|
-
super().__init__()
|
149
|
-
self.name = name
|
150
|
-
self.description = description
|
151
|
-
self.verbose = verbose
|
152
|
-
self.custom_params = custom_params
|
153
|
-
self.custom_preprocess = custom_preprocess
|
154
|
-
self.custom_postprocess = custom_postprocess
|
155
|
-
self.custom_router = custom_router
|
156
|
-
self.max_loops = max_loops
|
157
|
-
self.router = AutoSwarmRouter(
|
158
|
-
name=name,
|
159
|
-
description=description,
|
160
|
-
verbose=verbose,
|
161
|
-
custom_params=custom_params,
|
162
|
-
custom_preprocess=custom_preprocess,
|
163
|
-
custom_postprocess=custom_postprocess,
|
164
|
-
custom_router=custom_router,
|
165
|
-
*args,
|
166
|
-
**kwargs,
|
167
|
-
)
|
168
|
-
|
169
|
-
if name is None:
|
170
|
-
raise ValueError(
|
171
|
-
"A name must be provided for the AutoSwarm, what swarm do you want to use?"
|
172
|
-
)
|
173
|
-
|
174
|
-
if verbose is True:
|
175
|
-
self.init_logging()
|
176
|
-
|
177
|
-
def init_logging(self):
|
178
|
-
logger.info("AutoSwarm has been activated. Ready for usage.")
|
179
|
-
|
180
|
-
# def name_swarm_check(self, name: str = None):
|
181
|
-
|
182
|
-
def run(self, task: str = None, *args, **kwargs):
|
183
|
-
"""Run the swarm simulation."""
|
184
|
-
try:
|
185
|
-
loop = 0
|
186
|
-
|
187
|
-
while loop < self.max_loops:
|
188
|
-
if self.custom_preprocess:
|
189
|
-
# If custom preprocess function is provided then run it
|
190
|
-
logger.info("Running custom preprocess function.")
|
191
|
-
task, args, kwargs = self.custom_preprocess(
|
192
|
-
task, args, kwargs
|
193
|
-
)
|
194
|
-
|
195
|
-
if self.custom_router:
|
196
|
-
# If custom router function is provided then use it to route the task
|
197
|
-
logger.info("Running custom router function.")
|
198
|
-
out = self.custom_router(
|
199
|
-
self, task, *args, **kwargs
|
200
|
-
)
|
201
|
-
|
202
|
-
else:
|
203
|
-
out = self.router.run(task, *args, **kwargs)
|
204
|
-
|
205
|
-
if self.custom_postprocess:
|
206
|
-
# If custom postprocess function is provided then run it
|
207
|
-
out = self.custom_postprocess(out)
|
208
|
-
|
209
|
-
# LOOP
|
210
|
-
loop += 1
|
211
|
-
|
212
|
-
return out
|
213
|
-
except Exception as e:
|
214
|
-
logger.error(
|
215
|
-
f"Error: {e} try optimizing the inputs and try again."
|
216
|
-
)
|
217
|
-
raise e
|
218
|
-
|
219
|
-
def list_all_swarms(self):
|
220
|
-
for swarm in self.swarms:
|
221
|
-
try:
|
222
|
-
logger.info(
|
223
|
-
f"Swarm Name: {swarm.name} || Swarm Description: {swarm.description} "
|
224
|
-
)
|
225
|
-
except Exception as error:
|
226
|
-
logger.error(
|
227
|
-
f"Error Detected You may not have swarms available: {error}"
|
228
|
-
)
|
229
|
-
raise error
|
swarms/utils/agent_ops_check.py
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
from swarms.utils.loguru_logger import logger
|
2
|
-
import os
|
3
|
-
|
4
|
-
|
5
|
-
def try_import_agentops(*args, **kwargs):
|
6
|
-
try:
|
7
|
-
logger.info("Trying to import agentops")
|
8
|
-
import agentops
|
9
|
-
|
10
|
-
agentops.init(os.getenv("AGENTOPS_API_KEY"), *args, **kwargs)
|
11
|
-
|
12
|
-
return "agentops imported successfully."
|
13
|
-
except ImportError:
|
14
|
-
logger.error("Could not import agentops")
|
15
|
-
|
16
|
-
|
17
|
-
def end_session_agentops():
|
18
|
-
try:
|
19
|
-
logger.info("Trying to end session")
|
20
|
-
import agentops
|
21
|
-
|
22
|
-
agentops.end_session("Success")
|
23
|
-
return "Session ended successfully."
|
24
|
-
except ImportError:
|
25
|
-
logger.error("Could not import agentops")
|
26
|
-
return "Could not end session."
|
swarms/utils/pandas_utils.py
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
import subprocess
|
2
|
-
from typing import Any, Dict, List
|
3
|
-
|
4
|
-
from swarms.utils.loguru_logger import initialize_logger
|
5
|
-
|
6
|
-
from pydantic import BaseModel
|
7
|
-
|
8
|
-
from swarms.structs.agent import Agent
|
9
|
-
|
10
|
-
logger = initialize_logger(log_folder="pandas_utils")
|
11
|
-
|
12
|
-
|
13
|
-
def display_agents_info(agents: List[Agent]) -> None:
|
14
|
-
"""
|
15
|
-
Displays information about all agents in a list using a DataFrame.
|
16
|
-
|
17
|
-
:param agents: List of Agent instances.
|
18
|
-
"""
|
19
|
-
# Extracting relevant information from each agent
|
20
|
-
|
21
|
-
try:
|
22
|
-
import pandas as pd
|
23
|
-
except ImportError:
|
24
|
-
logger.error("Failed to import pandas")
|
25
|
-
subprocess.run(["pip", "install", "pandas"])
|
26
|
-
import pandas as pd
|
27
|
-
|
28
|
-
agent_data = []
|
29
|
-
for agent in agents:
|
30
|
-
try:
|
31
|
-
agent_info = {
|
32
|
-
"ID": agent.id,
|
33
|
-
"Name": agent.agent_name,
|
34
|
-
"Description": agent.description,
|
35
|
-
"max_loops": agent.max_loops,
|
36
|
-
# "Docs": agent.docs,
|
37
|
-
"System Prompt": agent.system_prompt,
|
38
|
-
"LLM Model": agent.llm.model_name, # type: ignore
|
39
|
-
}
|
40
|
-
agent_data.append(agent_info)
|
41
|
-
except AttributeError as e:
|
42
|
-
logger.error(
|
43
|
-
f"Failed to extract information from agent {agent}: {e}"
|
44
|
-
)
|
45
|
-
continue
|
46
|
-
|
47
|
-
# Creating a DataFrame to display the data
|
48
|
-
try:
|
49
|
-
df = pd.DataFrame(agent_data)
|
50
|
-
except Exception as e:
|
51
|
-
logger.error(f"Failed to create DataFrame: {e}")
|
52
|
-
return
|
53
|
-
|
54
|
-
# Displaying the DataFrame
|
55
|
-
try:
|
56
|
-
print(df)
|
57
|
-
except Exception as e:
|
58
|
-
logger.error(f"Failed to print DataFrame: {e}")
|
59
|
-
|
60
|
-
|
61
|
-
def dict_to_dataframe(data: Dict[str, Any]):
|
62
|
-
"""
|
63
|
-
Converts a dictionary into a pandas DataFrame.
|
64
|
-
|
65
|
-
:param data: Dictionary to convert.
|
66
|
-
:return: A pandas DataFrame representation of the dictionary.
|
67
|
-
"""
|
68
|
-
try:
|
69
|
-
import pandas as pd
|
70
|
-
except ImportError:
|
71
|
-
logger.error("Failed to import pandas")
|
72
|
-
subprocess.run(["pip", "install", "pandas"])
|
73
|
-
import pandas as pd
|
74
|
-
|
75
|
-
# Convert dictionary to DataFrame
|
76
|
-
df = pd.json_normalize(data)
|
77
|
-
return df
|
78
|
-
|
79
|
-
|
80
|
-
def pydantic_model_to_dataframe(model: BaseModel) -> any:
|
81
|
-
"""
|
82
|
-
Converts a Pydantic Base Model into a pandas DataFrame.
|
83
|
-
|
84
|
-
:param model: Pydantic Base Model to convert.
|
85
|
-
:return: A pandas DataFrame representation of the Pydantic model.
|
86
|
-
"""
|
87
|
-
# Convert Pydantic model to dictionary
|
88
|
-
model_dict = model.dict()
|
89
|
-
|
90
|
-
# Convert dictionary to DataFrame
|
91
|
-
df = dict_to_dataframe(model_dict)
|
92
|
-
return df
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|