Skip to main content
LLMs

[Hands-on] Building A Multi-agent News Generator

...using Cohere’s Command R7B and CrewAI.

Avi Chawla
Avi Chawla
👉

TODAY'S ISSUE

TODAY’S DAILY DOSE OF DATA SCIENCE

[Hands-on] Building a multi-agent news generator using Cohere’s CommandR-7B and CrewAI

We talked about Cohere’s latest ​Command R-7B​ model last week.

It’s a multilingual 7B-parameter open-weight model specialized in enterprise-focused LLM use cases…

…and outperforms other similarly sized open-weight models in core business use cases such as RAG, tool use, and AI agents.

Today, let’s build a multi-agent news generator using this model:

The app will take a user query, search the web for it, and turn it into a well-crafted news article with citations!

Here’s our tech stack for this demo:

We’ll have two agents in this multi-agent app:

1) Research analyst agent:

  • Accepts a user query.
  • Uses the Serper web search tool to fetch results from the internet.
  • Consolidates the results.

2) Content writer agent:

  • Uses the curated results to prepare a polished, publication-ready article.

If you prefer to watch, we have added a video demo below:

0:00
/1:29

You can find the entire code in this GitHub repository: AI Engineering Hub.

Let’s build this application!

PREREQUISITES

Setup

Create a .env file for their corresponding API keys:

Next, setup the LLM and web search tool as follows:

In the above code, we define the LLM and the search tool.

Notice the use of temperature in this code. We discussed what it is in yesterday’s issue.

AGENT 1

Research analyst agent

This agent will take a user query and then use the Serper web search tool to fetch results from the internet and consolidate them:

This is implemented below:

Here, we define our first agent and its goal. Along with that, we also give it access to the tools and the LLM.

Next, we must also create a task for it.

Below, we assign the research analyst agent a research task with a description and expected output:

AGENT 2

Content writer agent

The role of the content writer is to use the curated results and turn them into a polished, publication-ready news article.

The agent, like Agent 1, is defined below:

Let’s also give it its job, where we describe its writing task with all the details and expected output:

Almost done!

BRING IT ALL TOGETHER

Launch crew

Below, we build our crew of agents and run the multi-agent app:

This produces the following output:

Perfect, it works as expected!

You can find all the code and instructions to run in this GitHub repo: AI Engineering Hub.

We launched this repo recently, 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.

Find it here: AI Engineering Hub (and do star it).

👉 Over to you: What other topics would you like to learn about?

Published on Dec 17, 2024