From 3742da086db0d95f4c2f82e9c143b3a5eee1a623 Mon Sep 17 00:00:00 2001 From: CI-DEV <154627941+IlumCI@users.noreply.github.com> Date: Fri, 3 Oct 2025 20:26:57 +0300 Subject: [PATCH 1/3] Update ma_utils.py --- swarms/structs/ma_utils.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/swarms/structs/ma_utils.py b/swarms/structs/ma_utils.py index 51980e35..09639d36 100644 --- a/swarms/structs/ma_utils.py +++ b/swarms/structs/ma_utils.py @@ -131,11 +131,9 @@ def set_random_models_for_agents( return random.choice(model_names) if isinstance(agents, list): - return [ + for agent in agents: setattr(agent, "model_name", random.choice(model_names)) - or agent - for agent in agents - ] + return agents else: setattr(agents, "model_name", random.choice(model_names)) return agents From 4baf6173105e461b4189cf888e22f02d8362ee99 Mon Sep 17 00:00:00 2001 From: CI-DEV <154627941+IlumCI@users.noreply.github.com> Date: Fri, 3 Oct 2025 20:31:09 +0300 Subject: [PATCH 2/3] Update auto_swarm_builder.py --- swarms/structs/auto_swarm_builder.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/swarms/structs/auto_swarm_builder.py b/swarms/structs/auto_swarm_builder.py index 54a36e9d..826faa79 100644 --- a/swarms/structs/auto_swarm_builder.py +++ b/swarms/structs/auto_swarm_builder.py @@ -407,6 +407,10 @@ class AutoSwarmBuilder: model = self.build_llm_agent(config=Agents) agents_dictionary = model.run(task) + + # Parse JSON string if needed + if isinstance(agents_dictionary, str): + agents_dictionary = json.loads(agents_dictionary) return agents_dictionary @@ -437,6 +441,10 @@ class AutoSwarmBuilder: swarm_spec = model.run( f"Create the swarm spec for the following task: {task}" ) + + # Parse JSON string if needed + if isinstance(swarm_spec, str): + swarm_spec = json.loads(swarm_spec) print(swarm_spec) @@ -503,8 +511,16 @@ class AutoSwarmBuilder: # Convert dict to AgentSpec if needed if isinstance(agent_config, dict): agent_config = AgentSpec(**agent_config) + + # Convert AgentSpec to dict for Agent constructor + if hasattr(agent_config, 'dict'): + agent_dict = agent_config.dict() + elif hasattr(agent_config, 'model_dump'): + agent_dict = agent_config.model_dump() + else: + agent_dict = agent_config - agent = Agent(**agent_config) + agent = Agent(**agent_dict) agents.append(agent) return agents @@ -535,6 +551,8 @@ class AutoSwarmBuilder: if self.execution_type == "return-agents": return self.create_agents(task) + elif self.execution_type == "execute-swarm-router": + return self._execute_task(task) elif self.execution_type == "return-swarm-router-config": return self.create_router_config(task) elif self.execution_type == "return-agents-objects": From 22afe4b24b0b916e75b8e6c573810c2478f2bd67 Mon Sep 17 00:00:00 2001 From: CI-DEV <154627941+IlumCI@users.noreply.github.com> Date: Fri, 3 Oct 2025 20:31:53 +0300 Subject: [PATCH 3/3] Update ma_utils.py --- swarms/structs/ma_utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/swarms/structs/ma_utils.py b/swarms/structs/ma_utils.py index 09639d36..51980e35 100644 --- a/swarms/structs/ma_utils.py +++ b/swarms/structs/ma_utils.py @@ -131,9 +131,11 @@ def set_random_models_for_agents( return random.choice(model_names) if isinstance(agents, list): - for agent in agents: + return [ setattr(agent, "model_name", random.choice(model_names)) - return agents + or agent + for agent in agents + ] else: setattr(agents, "model_name", random.choice(model_names)) return agents