From 17e4de48874450200bdb45c9efa1e7562bb3c0b8 Mon Sep 17 00:00:00 2001 From: Steve-Dusty Date: Wed, 19 Nov 2025 20:32:38 -0800 Subject: [PATCH] fixed auto swarm builder issues --- swarms/structs/auto_swarm_builder.py | 4 ++++ tests/structs/test_auto_swarms_builder.py | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/swarms/structs/auto_swarm_builder.py b/swarms/structs/auto_swarm_builder.py index 514cb79c..08c75164 100644 --- a/swarms/structs/auto_swarm_builder.py +++ b/swarms/structs/auto_swarm_builder.py @@ -407,6 +407,8 @@ class AutoSwarmBuilder: agents_dictionary = model.run(task) + agents_dictionary = json.loads(agents_dictionary) + return agents_dictionary except Exception as e: @@ -437,6 +439,8 @@ class AutoSwarmBuilder: f"Create the swarm spec for the following task: {task}" ) + swarm_spec = json.loads(swarm_spec) + print(swarm_spec) print(type(swarm_spec)) diff --git a/tests/structs/test_auto_swarms_builder.py b/tests/structs/test_auto_swarms_builder.py index a1e9085a..547c032d 100644 --- a/tests/structs/test_auto_swarms_builder.py +++ b/tests/structs/test_auto_swarms_builder.py @@ -46,16 +46,22 @@ def test_agent_building(): print("Testing Agent Building") try: swarm = AutoSwarmBuilder() - agent = swarm.build_agent( + + # Create agent spec + agent_spec = AgentSpec( agent_name="TestAgent", - agent_description="A test agent", - agent_system_prompt="You are a test agent", + description="A test agent", + system_prompt="You are a test agent", max_loops=1, ) + # Create agent from spec + agents = swarm.create_agents_from_specs({"agents": [agent_spec]}) + agent = agents[0] + print("✓ Built agent with configuration:") print(f" - Name: {agent.agent_name}") - print(f" - Description: {agent.description}") + print(f" - Description: {agent.agent_description}") print(f" - Max loops: {agent.max_loops}") print("✓ Agent building test passed") return agent @@ -74,13 +80,14 @@ def test_agent_creation(): description="A swarm for research tasks", ) task = "Research the latest developments in quantum computing" - agents = swarm._create_agents(task) + agents_dict = swarm.create_agents(task) + agents = swarm.create_agents_from_specs(agents_dict) print("✓ Created agents for research task:") for i, agent in enumerate(agents, 1): print(f" Agent {i}:") print(f" - Name: {agent.agent_name}") - print(f" - Description: {agent.description}") + print(f" - Description: {agent.agent_description}") print(f"✓ Created {len(agents)} agents successfully") return agents except Exception as e: @@ -103,7 +110,7 @@ def test_swarm_routing(): task = "Analyze the impact of AI on healthcare" print("Starting task routing...") - result = swarm.swarm_router(agents, task) + result = swarm.initialize_swarm_router(agents, task) print("✓ Task routed successfully") print(