Type something to search...
Building a Multi-agent Internet Research Assistant

Building a Multi-agent Internet Research Assistant

…with OpenAI Swarm & Llama 3.2 (100% local).

Let’s build a multi-agent internet research assistant using OpenAI Swarm & Llama 3.2 (100% local):

Hands-on tutorial to build a multi-agent internet research assistant app that:

  • Accepts a user query.
  • Searches the web about it.
  • And turns it into a well-crafted article.

We used three agents in this app:

  • Agent 1 → Accepts the user query and searches the web.
  • Agent 2 → Accepts the web results from Agent 1 and refines them.
  • Agent 3 → A technical writing agent that accepts the refined results, drafts an article, and sends it back to the user.

Recently, OpenAI released Swarm.

It’s an open-source framework designed to manage and coordinate multiple AI agents in a highly customizable way.

AI Agents are autonomous systems that can reason, think, plan, figure out the relevant sources and extract information from them when needed, take actions, and even correct themselves if something goes wrong.

Today, let’s cover a practical and hands-on demo of this. We’ll build an internet research assistant app that:

  • Accepts a user query.
  • Searches the web about it.
  • And turns it into a well-crafted article.

We shall use:

  • OpenAI Swarm for multi-agent orchestration.
  • Streamlit for the UI.

Here’s the step-by-step workflow of our multi-agent app.

As depicted above, we have three agents:

  • Agent 1 → Accepts the user query and searches the web.
  • Agent 2 → Accepts the web results from Agent 1 and refines them.
  • Agent 3 → A technical writing agent that accepts the refined results, drafts an article, and sends it back to the user.

Let’s build this application!

Imports

First, we begin with some standard imports:

  • We use Swarm from OpenAI to build our multi-agent app.
  • We use duckduckgo_search to search the web.

Next, we define the MODEL name, and initialize swarm client and search client:

Agent 1

This agent must accept the user’s query, search the web, and return the raw web results.

To build this, we first implement a function that accepts the query and returns the raw results.

  • Line 7: Search the web.
  • Line 9–16: Collect all the web results (title + URL + Body) in a single string and return it.

Next, we define our web search agent that will utilize the above function, and we also specify the instructions for this agent below:

Line 1: We specify the role.

Line 6–11: We define an object of Agent class (from OpenAI Swarm), specify the above function, the instructions, and the LLM.

Agent 2

The results returned by Agent 1 will be pretty messy and may have a ton of irrelevant information. We need another agent to filter the appropriate information.

Like Agent 1, we define another object of the Agent class and pass the instructions:

Agent 3

Finally, we build another agent that accepts the above-filtered results and drafts an article:

Stitch them together

While we have defined the three agents above, the multi-agent app does not know the order in which these agents must run and whose output must be passed to the next agent.

Thus, we need to stitch them together in a workflow function.

Let’s do it step by step for simplicity.

  • First, we pass the user query to the web search agent, which generates raw responses:

Next, we pass the raw responses to the web filter agent:

Done!

This is the entire code for the run_workflow method:

Executing the run_workflow method generates the desired output, as depicted below (and in the video at the top of this newsletter:

Of course, we did not cover the Streamlit part in this tutorial.

We launched this repo today, wherein we’ll publish the code for such hands-on AI engineering newsletter issues.

This repository will be dedicated to:

  • In-depth tutorials on LLMs and RAGs.
  • Real-world AI agent applications.
  • Examples to implement, adapt, and scale in your projects.

Do you like the topic? Join our newsletter Subscribe

If you like the article and would like to support me, make sure to:

👏 Clap for the story (100 Claps) and follow me 👉🏻 Mohammed Lubbad

📑 View more content on my Medium Profile

🔔 Follow Me: LinkedIn | Medium | GitHub | Twitter | Telegram

🚀 Help me reach a wider audience by sharing my content with your friends and colleagues.

Related Posts

10 Creative Ways to Use ChatGPT Search The Web Feature

10 Creative Ways to Use ChatGPT Search The Web Feature

For example, prompts and outputs Did you know you can use the “search the web” feature of ChatGPT for many tasks other than your basic web search? For those who don't know, ChatGPT’s new

Read More
📚 10 Must-Learn Skills to Stay Ahead in AI and Tech 🚀

📚 10 Must-Learn Skills to Stay Ahead in AI and Tech 🚀

In an industry as dynamic as AI and tech, staying ahead means constantly upgrading your skills. Whether you’re aiming to dive deep into AI model performance, master data analysis, or transform trad

Read More
10 Powerful Perplexity AI Prompts to Automate Your Marketing Tasks

10 Powerful Perplexity AI Prompts to Automate Your Marketing Tasks

In today’s fast-paced digital world, marketers are always looking for smarter ways to streamline their efforts. Imagine having a personal assistant who can create audience profiles, suggest mar

Read More
10+ Top ChatGPT Prompts for UI/UX Designers

10+ Top ChatGPT Prompts for UI/UX Designers

AI technologies, such as machine learning, natural language processing, and data analytics, are redefining traditional design methodologies. From automating repetitive tasks to enabling personal

Read More
100 AI Tools to Finish Months of Work in Minutes

100 AI Tools to Finish Months of Work in Minutes

The rapid advancements in artificial intelligence (AI) have transformed how businesses operate, allowing people to complete tasks that once took weeks or months in mere minutes. From content creat

Read More
17 Mindblowing GitHub Repositories You Never Knew Existed

17 Mindblowing GitHub Repositories You Never Knew Existed

Github Hidden Gems!! Repositories To Bookmark Right Away Learning to code is relatively easy, but mastering the art of writing better code is much tougher. GitHub serves as a treasur

Read More