Multi-agent systems enable specialized agents to collaborate on complex tasks, improving modularity, scalability, and robustness. Instead of relying on a single agent for all operations, tasks are distributed among agents with distinct capabilities.
In smolagents, different agents can be combined to generate Python code, call external tools, perform web searches, and more. By orchestrating these agents, we can create powerful workflows, such as:
The diagram below illustrates a simple multi-agent architecture where a Manager Agent coordinates a Code Interpreter Tool and a Web Search Agent, which in turn utilizes tools like Web Search and Visit Webpage to gather relevant information.
+----------------+
| Manager agent |
+----------------+
|
_______________|______________
| |
Code Interpreter +------------------+
tool | Web Search agent |
+------------------+
| |
Web Search tool |
Visit webpage toolA multi-agent system consists of multiple specialized agents working together under the coordination of an Orchestrator Agent. This approach enables complex workflows by distributing tasks among agents with distinct roles.
For example, a Multi-Agent RAG system can integrate:
All of these agents operate under an orchestrator that manages task delegation and interaction.
To create a multi-agent system in smolagents, we start by defining individual CodeAgent instances, each responsible for a specific task. These agents are then managed by an Orchestrator Agent, which acts as the central coordinator.
The orchestrator is initialized with a managed_agents attribute, listing the agents it controls. This modular approach allows for flexible and scalable multi-agent architectures.
# https://huggingface.co/learn/cookbook/multiagent_rag_system
manager_agent = CodeAgent(
tools=[],
model=model,
managed_agents=[managed_web_agent, managed_retriever_agent, managed_image_generation_agent],
additional_authorized_imports=["time", "datetime", "PIL"],
)
# Many possible prompts!
manager_agent.run("How many years ago was Stripe founded?")
result = manager_agent.run("Improve this prompt, then generate an image of it.", prompt="A rabbit wearing a space suit")
manager_agent.run("How can I push a model to the Hub?")
manager_agent.run("How do you combine multiple adapters in peft?")The library handles system management internally, so no additional code is needed.