Skip to content

Conversation

@IlumCI
Copy link
Contributor

@IlumCI IlumCI commented Oct 3, 2025

Description

Fixed multiple issues in AutoSwarmBuilder that were preventing the execute-swarm-router execution type from working correctly.

Issue

#1115

Dependencies

No new dependencies required.

Tag maintainer

@kyegomez

Twitter handle

https://x.com/IlumTheProtogen

Code Changes

Problem: Missing execute-swarm-router execution type in run method

# OLD CODE (broken):
def run(self, task: str, *args, **kwargs):
    try:
        if self.execution_type == "return-agents":
            return self.create_agents(task)
        elif self.execution_type == "return-swarm-router-config":
            return self.create_router_config(task)
        elif self.execution_type == "return-agents-objects":
            agents = self.create_agents(task)
            return self.create_agents_from_specs(agents)
        else:
            raise ValueError(f"Invalid execution type: {self.execution_type}")

The execute-swarm-router execution type was missing, preventing _execute_task from being called.

Solution: Added execute-swarm-router execution type

# NEW CODE (working):
def run(self, task: str, *args, **kwargs):
    try:
        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":
            agents = self.create_agents(task)
            return self.create_agents_from_specs(agents)
        else:
            raise ValueError(f"Invalid execution type: {self.execution_type}")

Problem: Missing JSON parsing in create_agents method

# OLD CODE (broken):
def create_agents(self, task: str):
    try:
        logger.info("Creating agents from specifications")
        model = self.build_llm_agent(config=Agents)
        agents_dictionary = model.run(task)
        return agents_dictionary

The LLM returns a JSON string, but the code expected a dictionary.

Solution: Added JSON parsing

# NEW CODE (working):
def create_agents(self, task: str):
    try:
        logger.info("Creating agents from specifications")
        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

Problem: AgentSpec to Agent conversion issue

# OLD CODE (broken):
for agent_config in agents_list:
    if isinstance(agent_config, dict):
        agent_config = AgentSpec(**agent_config)
    agent = Agent(**agent_config)  # TypeError: Agent() argument after ** must be a mapping, not AgentSpec

Solution: Convert AgentSpec to dictionary

# NEW CODE (working):
for agent_config in agents_list:
    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_dict)
    agents.append(agent)

The fix ensures AutoSwarmBuilder can successfully create agents and execute swarm workflows with the execute-swarm-router execution type.


📚 Documentation preview 📚: https://swarms--1117.org.readthedocs.build/en/1117/

@kyegomez kyegomez closed this Nov 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants