What Are Multi-Agent Systems? Learning With Smolagents
NBD Lite -#43 How Multi-Agent Systems Work in Real-World Tasks?
In our previous articles, we’ve covered the basics of what Agents are and how to use tools with Smolagents.
However, real-world tasks are often more complex than what a single agent can handle on its own.
This is where the concept of Multi-Agent Systems (MAS) comes in—an approach that solves problems by coordinating multiple agents to work together when one agent isn’t enough.
So, how does MAS work? And why is it important to understand? Let’s explore it together!
Multi-Agent Systems (MAS) with Smolagents
Multi-Agent Systems (MAS) are one of the most exciting developments in AI, enabling autonomous agents to work together to achieve collective goals.
By designing systems where multiple agents can interact, collaborate, and communicate, MAS allows for solving more complex tasks that a single agent simply cannot handle.
In a MAS environment, agents work toward shared objectives by exchanging information and making decisions collectively, all while focusing on their specialized tasks. This collaboration enhances problem-solving capabilities and creates a more dynamic and adaptive system.
There are a few important key features of MAS, including:
Autonomy:
Each agent operates independently without needing continuous human intervention.Decentralization:
There is no single point of control. Agents make local decisions but can work together to achieve a global objective.Collaboration:
Agents communicate with each other to share information and coordinate actions.Adaptability:
Agents can adjust their strategies based on environmental changes or the actions of other agents.
Multi-agent systems typically follow a structured workflow where tasks are broken down into subtasks, and agents with specific capabilities are assigned to handle them.
Let’s try the example with Smolagents.
In the Smolagents framework, we will use the ManagedAgent
class to encapsulate the agent where it will be embedded into the manager agent’s system prompt so they can call this agent.
For example, here is how you use the manager agents to control the individual agent.
from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool, ManagedAgent
model = HfApiModel()
web_agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
managed_web_agent = ManagedAgent(
agent=web_agent,
name="web_search",
description="Runs web searches for you. Give it your query as an argument."
)
manager_agent = CodeAgent(
tools=[], model=model, managed_agents=[managed_web_agent]
)
manager_agent.run("Who is the elected president of United States in 2024?")
There is only one individual agent so the manager only needs to assign the task to the only available agents.
How about if we extend the agent into two where one agent can search the web and the other can generate images?
First, let’s load the tool that the agent can use to generate the image.
from smolagents import load_tool
image_generation_tool = load_tool("m-ric/text-to-image", trust_remote_code=True)
Then, we develop two different agents for each task and embed them with the manager agent.
from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool, ManagedAgent
web_agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
image_gen_agent = CodeAgent(tools=[image_generation_tool], model=model)
managed_web_agent = ManagedAgent(
agent=web_agent,
name="web_search",
description="Runs web searches for you. Give it your query as an argument."
)
managed_image_gen_agent = ManagedAgent(
agent=image_gen_agent,
name="image_gen",
description="Runs image generation for you. Give it your query as an argument."
)
manager_agent = CodeAgent(
tools=[], model=model, managed_agents=[managed_web_agent, managed_image_gen_agent],
)
Lastly, we will ask the agent to search the web for elected president and generate that president image.
manager_agent.run("Who is the elected president of United States in 2024 and can you generate that president image?")
The agents work pretty well in executing our tasks. This is an example of how MAS works.
I can say that the future of AI is likely to involve more advanced multi-agent systems that can:
Collaborate with humans in hybrid workflows.
Perform continuous learning through feedback loops.
Handle more complex, multi-step tasks in dynamic environments.
I will try to write more about the above concepts in later articles, so stay tuned!
That’s all that MAS is about with Smolagents. I hope it helps your work!
Is there anything else you’d like to discuss? Let’s dive into it together!
👇👇👇