Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Veanir opened this issue Jun 15, 2024 · 6 comments
Open

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

Veanir opened this issue Jun 15, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@Veanir
Copy link

Veanir commented Jun 15, 2024

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)
  1. Watch error in the console.

Screenshots
image

Additional context
Python 3.12.2
swarms installed via pip

Upvote & Fund

  • We're using Polar.sh 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.
Fund with Polar
@Veanir Veanir added the bug Something isn't working label Jun 15, 2024
Copy link

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

@kyegomez
Copy link
Owner

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

@evelynmitchell
Copy link
Contributor

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�[0m �[1mReliability checks activated.�[0m

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
Copy link
Author

Veanir commented Jun 17, 2024

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
Copy link
Contributor

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants