kyegomez / swarms

The Enterprise-Grade Production-Ready Multi-Agent Orchestration Framework Join our Community: https://discord.com/servers/agora-999382051935506503
https://docs.swarms.world
Other
942 stars 129 forks source link

ValueError: Agents must be provided. [BUG] #497

Open Veanir opened 1 month ago

Veanir commented 1 month ago

Describe the bug BaseSwarm class throws value error when instantiating SwarmNetwork when using provided Swarm Network example.

To Reproduce Steps to reproduce the behavior:

  1. Go to Swarms documentation
  2. Install swarms like intended
  3. Run provided "Swarm Network" code eg.
    
    import os

from dotenv import load_dotenv

Import the OpenAIChat model and the Agent struct

from swarms import Agent, OpenAIChat, SwarmNetwork

Load the environment variables

load_dotenv()

Get the API key from the environment

api_key = os.environ.get("OPENAI_API_KEY")

Initialize the language model

llm = OpenAIChat( temperature=0.5, openai_api_key=api_key, )

Initialize the workflow

agent = Agent(llm=llm, max_loops=1, agent_name="Social Media Manager") agent2 = Agent(llm=llm, max_loops=1, agent_name=" Product Manager") agent3 = Agent(llm=llm, max_loops=1, agent_name="SEO Manager")

Load the swarmnet with the agents

swarmnet = SwarmNetwork( agents=[agent, agent2, agent3], )

List the agents in the swarm network

out = swarmnet.list_agents() print(out)

Run the workflow on a task

out = swarmnet.run_single_agent( agent2.id, "Generate a 10,000 word blog on health and wellness." ) print(out)

Run all the agents in the swarm network on a task

out = swarmnet.run_many_agents("Generate a 10,000 word blog on health and wellness.") print(out)


4. Watch error in the console.

**Screenshots**
![image](https://github.com/kyegomez/swarms/assets/58010186/d4d25dd3-eb5e-461c-a8e7-9773a83d9abd)

**Additional context**
Python 3.12.2
swarms installed via pip

<!-- POLAR PLEDGE BADGE START -->
## Upvote & Fund

- We're using [Polar.sh](https://polar.sh/kyegomez) so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.

<a href="https://polar.sh/kyegomez/swarms/issues/497">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/kyegomez/swarms/issues/497/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/kyegomez/swarms/issues/497/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->
github-actions[bot] commented 1 month ago

Hello there, thank you for opening an Issue ! 🙏🏻 The team was notified and they will get back to you asap.

kyegomez commented 1 month ago

@Veanir hey excuse, me think i just fixed it, try upgrading and then let me know: pip3 install -U swarms

evelynmitchell commented 1 month ago

I set up a colab notebook replicator with the latest swarms. It ran, but ran out of memory after only producing

32m2024-06-17T23:14:10.620655+0000 Reliability checks activated.

If interrupted before running out of memory I get;

KeyboardInterrupt                         Traceback (most recent call last)
[<ipython-input-2-1f396324b767>](https://localhost:8080/#) in <cell line: 27>()
     25 
     26 # Load the swarmnet with the agents
---> 27 swarmnet = SwarmNetwork(
     28     agents=[agent, agent2, agent3],
     29 )

[/usr/local/lib/python3.10/dist-packages/swarms/structs/swarm_net.py](https://localhost:8080/#) in __init__(self, name, description, agents, idle_threshold, busy_threshold, api_enabled, logging_enabled, api_on, host, port, swarm_callable, *args, **kwargs)
    145         if agents is not None:
    146             for agent in agents:
--> 147                 self.agents.append(agent)
    148 
    149         # Create the FastAPI instance

KeyboardInterrupt:

I'll dig in a bit more.

Veanir commented 1 month ago

Yea, seems like infinite loop to me

# For each agent in the pool, run it on it's own thread
        if agents is not None:
            for agent in agents:
                self.agents.append(agent)
evelynmitchell commented 1 month ago

Ok, I think I figured this out. This code is recursively adding agents to agents, and so will never stop, and will oom. swarms/structs/swarm_net.py 144 You likely don't need this code at all. The agents have already been added with self.agents.

       # For each agent in the pool, run it on it's own thread
        if agents is not None:
            for agent in agents:
                self.agents.append(agent)
kyegomez commented 4 weeks ago

@Veanir @evelynmitchell i've tried fixing it, thanks good catch. try upgrading now!