Path: blob/main/smolagents_doc/en/tensorflow/multiagents.ipynb
8409 views
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 to HF in order to call Inference Providers:
⚡️ Our agent will be powered by Qwen/Qwen3-Next-80B-A3B-Thinking using InferenceClientModel class that uses HF's Inference API: the Inference API allows to quickly and easily run any OS model.
[!TIP] Inference Providers give access to hundreds of models, powered by serverless inference partners. A list of supported providers can be found here.
🔍 Create a web search tool
For web browsing, we can already use our native WebSearchTool tool to provide a Google search equivalent.
But then we will also need to be able to peak into the page found by the WebSearchTool. 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_stepsto 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 work well.
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...