swarms 7.5.8__py3-none-any.whl → 7.5.9__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/structs/agent_builder.py +32 -18
- {swarms-7.5.8.dist-info → swarms-7.5.9.dist-info}/METADATA +1 -1
- {swarms-7.5.8.dist-info → swarms-7.5.9.dist-info}/RECORD +6 -6
- {swarms-7.5.8.dist-info → swarms-7.5.9.dist-info}/LICENSE +0 -0
- {swarms-7.5.8.dist-info → swarms-7.5.9.dist-info}/WHEEL +0 -0
- {swarms-7.5.8.dist-info → swarms-7.5.9.dist-info}/entry_points.txt +0 -0
swarms/structs/agent_builder.py
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
import os
|
2
|
-
from typing import List, Optional, Tuple
|
2
|
+
from typing import Any, List, Optional, Tuple
|
3
3
|
|
4
4
|
from loguru import logger
|
5
5
|
from pydantic import BaseModel, Field
|
6
6
|
|
7
7
|
from swarms.structs.agent import Agent
|
8
|
-
from swarms.utils.any_to_str import any_to_str
|
9
8
|
from swarms.utils.function_caller_model import OpenAIFunctionCaller
|
10
|
-
from swarms.utils.litellm_tokenizer import count_tokens
|
11
9
|
|
12
10
|
BOSS_SYSTEM_PROMPT = """
|
13
11
|
# Swarm Intelligence Orchestrator
|
@@ -148,13 +146,17 @@ class AgentsBuilder:
|
|
148
146
|
description: str = "This is a swarm that creates swarms",
|
149
147
|
verbose: bool = True,
|
150
148
|
max_loops: int = 1,
|
149
|
+
model_name: str = "gpt-4o",
|
150
|
+
return_dictionary: bool = True,
|
151
151
|
):
|
152
152
|
self.name = name
|
153
153
|
self.description = description
|
154
154
|
self.verbose = verbose
|
155
155
|
self.max_loops = max_loops
|
156
156
|
self.agents_pool = []
|
157
|
-
|
157
|
+
self.model_name = model_name
|
158
|
+
self.return_dictionary = return_dictionary
|
159
|
+
|
158
160
|
logger.info(
|
159
161
|
f"Initialized AutoSwarmBuilder: {name} {description}"
|
160
162
|
)
|
@@ -174,11 +176,11 @@ class AgentsBuilder:
|
|
174
176
|
The output from the swarm's execution
|
175
177
|
"""
|
176
178
|
logger.info(f"Running swarm on task: {task}")
|
177
|
-
agents
|
179
|
+
agents = self._create_agents(
|
178
180
|
task, image_url, *args, **kwargs
|
179
181
|
)
|
180
182
|
|
181
|
-
return agents
|
183
|
+
return agents
|
182
184
|
|
183
185
|
def _create_agents(self, task: str, *args, **kwargs):
|
184
186
|
"""Create the necessary agents for a task.
|
@@ -197,23 +199,28 @@ class AgentsBuilder:
|
|
197
199
|
api_key=os.getenv("OPENAI_API_KEY"),
|
198
200
|
temperature=0.1,
|
199
201
|
base_model=Agents,
|
200
|
-
model_name=
|
202
|
+
model_name=self.model_name,
|
203
|
+
max_tokens = 8192,
|
201
204
|
)
|
202
205
|
|
203
206
|
agents_dictionary = model.run(task)
|
204
|
-
|
207
|
+
print(agents_dictionary)
|
208
|
+
|
209
|
+
print(type(agents_dictionary))
|
205
210
|
logger.info("Agents successfully created")
|
206
211
|
logger.info(f"Agents: {len(agents_dictionary.agents)}")
|
207
212
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
213
|
+
if self.return_dictionary:
|
214
|
+
logger.info("Returning dictionary")
|
215
|
+
|
216
|
+
# Convert swarm config to dictionary
|
217
|
+
agents_dictionary = agents_dictionary.model_dump()
|
218
|
+
return agents_dictionary
|
219
|
+
else:
|
220
|
+
logger.info("Returning agents")
|
221
|
+
return self.create_agents(agents_dictionary)
|
222
|
+
|
223
|
+
def create_agents(self, agents_dictionary: Any):
|
217
224
|
# Create agents from config
|
218
225
|
agents = []
|
219
226
|
for agent_config in agents_dictionary.agents:
|
@@ -235,7 +242,7 @@ class AgentsBuilder:
|
|
235
242
|
)
|
236
243
|
agents.append(agent)
|
237
244
|
|
238
|
-
return agents
|
245
|
+
return agents
|
239
246
|
|
240
247
|
def build_agent(
|
241
248
|
self,
|
@@ -278,3 +285,10 @@ class AgentsBuilder:
|
|
278
285
|
)
|
279
286
|
|
280
287
|
return agent
|
288
|
+
|
289
|
+
|
290
|
+
# if __name__ == "__main__":
|
291
|
+
# builder = AgentsBuilder(model_name="gpt-4o")
|
292
|
+
# agents = builder.run("Create a swarm that can write a book about the history of the world")
|
293
|
+
# print(agents)
|
294
|
+
# print(type(agents))
|
@@ -76,7 +76,7 @@ swarms/schemas/agent_step_schemas.py,sha256=a14gb58vR0xOwB_fwSJQbN6yb9HddEaT30E6
|
|
76
76
|
swarms/schemas/base_schemas.py,sha256=UvBLVWg2qRen4tK5GJz50v42SiX95EQ5qK7hfyAHTEU,3267
|
77
77
|
swarms/structs/__init__.py,sha256=iPQmbvhyBMobHP1SXIxncVdpsMDnPWwcAEZz_TEORt0,4354
|
78
78
|
swarms/structs/agent.py,sha256=tcGFYvQGdv-2VD9kaQvIKcdBxhv4H9WhWmEMzNcFeYc,96232
|
79
|
-
swarms/structs/agent_builder.py,sha256=
|
79
|
+
swarms/structs/agent_builder.py,sha256=YYsGjyNAObopDFfgE9jvP_G1puGQD-lQ32JqgDnhdEM,12097
|
80
80
|
swarms/structs/agent_registry.py,sha256=il507cO1NF-d4ChyANVLuWrN8bXsEAi8_7bLJ_sTU6A,12112
|
81
81
|
swarms/structs/agent_roles.py,sha256=8XEw6RjOOZelaZaWt4gXaYQm5WMLEhSO7W6Z8sQjmFg,582
|
82
82
|
swarms/structs/agent_router.py,sha256=YZw5AaK2yTvxkOA7ouED_4MoYgn0XZggvo1wrglp-4E,13017
|
@@ -177,8 +177,8 @@ swarms/utils/swarm_reliability_checks.py,sha256=MsgUULt3HYg72D0HifZNmtCyJYpLA2UD
|
|
177
177
|
swarms/utils/try_except_wrapper.py,sha256=appEGu9Afy3TmdkNNXUgQ9yU9lj2j0uNkIoW0JhVzzY,3917
|
178
178
|
swarms/utils/visualizer.py,sha256=0ylohEk62MAS6iPRaDOV03m9qo2k5J56tWlKJk_46p4,16927
|
179
179
|
swarms/utils/wrapper_clusterop.py,sha256=PMSCVM7ZT1vgj1D_MYAe835RR3SMLYxA-si2JS02yNQ,4220
|
180
|
-
swarms-7.5.
|
181
|
-
swarms-7.5.
|
182
|
-
swarms-7.5.
|
183
|
-
swarms-7.5.
|
184
|
-
swarms-7.5.
|
180
|
+
swarms-7.5.9.dist-info/LICENSE,sha256=jwRtEmTWjLrEsvFB6QFdYs2cEeZPRMdj-UMOFkPF8_0,11363
|
181
|
+
swarms-7.5.9.dist-info/METADATA,sha256=92H77NpiHOd-fJRABYyx9RZEVuxVKn2brNGkds33c3A,103019
|
182
|
+
swarms-7.5.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
183
|
+
swarms-7.5.9.dist-info/entry_points.txt,sha256=2K0rTtfO1X1WaO-waJlXIKw5Voa_EpAL_yU0HXE2Jgc,47
|
184
|
+
swarms-7.5.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|