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:
- CrewAI for multi-agent orchestration.
- Cohere's CommandR-7B as the LLM.
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:
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?
THAT'S A WRAP
No-Fluff Industry ML resources to
Succeed in DS/ML roles
At the end of the day, all businesses care about impact. That’s it!
- Can you reduce costs?
- Drive revenue?
- Can you scale ML models?
- Predict trends before they happen?
We have discussed several other topics (with implementations) in the past that align with such topics.
Here are some of them:
- Learn sophisticated graph architectures and how to train them on graph data in this crash course.
- So many real-world NLP systems rely on pairwise context scoring. Learn scalable approaches here.
- Run large models on small devices using Quantization techniques.
- Learn how to generate prediction intervals or sets with strong statistical guarantees for increasing trust using Conformal Predictions.
- Learn how to identify causal relationships and answer business questions using causal inference in this crash course.
- Learn how to scale and implement ML model training in this practical guide.
- Learn 5 techniques with implementation to reliably test ML models in production.
- Learn how to build and implement privacy-first ML systems using Federated Learning.
- Learn 6 techniques with implementation to compress ML models.
All these resources will help you cultivate key skills that businesses and companies care about the most.
SPONSOR US
Advertise to 450k+ data professionals
Our newsletter puts your products and services directly in front of an audience that matters — thousands of leaders, senior data scientists, machine learning engineers, data analysts, etc., around the world.