Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/main/smolagents_doc/en/multiagents.ipynb
Views: 2934
Orchestrate a multi-agent system 🤖🤝🤖
In this notebook we will make a multi-agent web browser: an agentic system with several agents collaborating to solve problems using the web!
It will be a simple hierarchy:
Let's set up this system.
Run the line below to install the required dependencies:
Let's login in order to call the HF Inference API:
⚡️ Our agent will be powered by Qwen/Qwen2.5-Coder-32B-Instruct using HfApiModel
class that uses HF's Inference API: the Inference API allows to quickly and easily run any OS model.
Note: The Inference API hosts models based on various criteria, and deployed models may be updated or replaced without prior notice. Learn more about it here.
🔍 Create a web search tool
For web browsing, we can already use our pre-existing DuckDuckGoSearchTool
tool to provide a Google search equivalent.
But then we will also need to be able to peak into the page found by the DuckDuckGoSearchTool
. To do so, we could import the library's built-in VisitWebpageTool
, but we will build it again to see how it's done.
So let's create our VisitWebpageTool
tool from scratch using markdownify
.
Ok, now let's initialize and test our tool!
Build our multi-agent system 🤖🤝🤖
Now that we have all the tools search
and visit_webpage
, we can use them to create the web agent.
Which configuration to choose for this agent?
Web browsing is a single-timeline task that does not require parallel tool calls, so JSON tool calling works well for that. We thus choose a
ToolCallingAgent
.Also, since sometimes web search requires exploring many pages before finding the correct answer, we prefer to increase the number of
max_steps
to 10.
Note that we gave this agent attributes name
and description
, mandatory attributes to make this agent callable by its manager agent.
Then we create a manager agent, and upon initialization we pass our managed agent to it in its managed_agents
argument.
Since this agent is the one tasked with the planning and thinking, advanced reasoning will be beneficial, so a CodeAgent
will be the best choice.
Also, we want to ask a question that involves the current year and does additional data calculations: so let us add additional_authorized_imports=["time", "numpy", "pandas"]
, just in case the agent needs these packages.
That's all! Now let's run our system! We select a question that requires both some calculation and research:
We get this report as the answer:
Seems like we'll need some sizeable powerplants if the scaling hypothesis continues to hold true.
Our agents managed to efficiently collaborate towards solving the task! ✅
💡 You can easily extend this orchestration to more agents: one does the code execution, one the web search, one handles file loadings...