How to Build Your Own Newsletter AI Agent

Sushant Thakur Last Updated : 19 Jun, 2025
6 min read

With the evolution of AI and its integration with social media, there is no doubt that it helps in creating valuable content. Since it has led to reducing human interaction, the aftermath of this integration has resulted in reduced attention span. So the question is, how can you get undivided attention from your reader while creating content that drives engagement?

The answer is the Newsletter.

In this article, I will show you how to create your own newsletter AI agent.

Why Newsletter?

A newsletter is a regularly distributed publication. It is usually sent via e-mail to share updates, insights or customized content with a specific audience. The main purpose of the newsletter is to:

  1. Share Information: Businesses or organizations use a newsletter to give updates about your company and the recent developments (like product launches, blog updates, events).
  2. Promote: Companies send newsletters to their targeted audiences promoting products, services, or courses in a subtle, relationship-building way.
  3. Engage: Communities with promotional content first engage with their audiences by sharing the relevant content through newsletters, so that once they share the promotional content, they are very likely to ignore it

The Shift: From Manual to Autonomous Content Creation

Since its inception, newsletters have followed the same formula, and that is someone would spend hours collecting links and summarizing content. The copies created were minimally personalized beyond the recipient’s name and were not susceptible to scale for niche audiences.

But things are rapidly changing.

From the time we have entered into the Agentic workflows, we have moved one step closer to not just generating personalized content but also automating it. By combining LLMs and Agentic workflows, one not just strategises the content but also makes decisions and executes tasks without regular inputs.

Also Read: Top 4 Agentic AI Design Patterns

Project Plan for Building a Newsletter AI Agent

Let’s try to visualize how an AI-powered newsletter agent works:

Project Plan | Newsletter AI Agent
  1. Prompt: In the first step, you will show your intention by creating a weekly AI roundup.
  2. Goal Setting: In the next step, we are going to set up the expectations by defining what kind of newsletter we want
  3. Execution plan: Here comes the role of the agent, where it searches sources, summarizes insights and formats them.
  4. Output: Lastly, it curates the final newsletter, ready to send.

I am building a simple newsletter agent here. If you are looking for a more complex one, then checkout – 🔗 Building a Customized Newsletter AI Agent

Let’s Build: Your First Newsletter AI Agent

Now that you understand the importance of agentic workflows for strategizing and automating your newsletter, let’s move on to exploring the “How”.

In this article, we are going to build a simple AI-powered workflow that automates newsletter creation from a CSV dataset of news articles.

Let’s get started.

Step 1: Ingest a CSV File Containing Multiple News Entries

To start, we need to read the CSV file containing the news articles. The CSV file should have a structure where each row contains details of a news article, such as the title, content, and other metadata. We can use the pandas library to ingest and manipulate this data.

Code for Ingesting CSV:

import pandas as pd

# Load the CSV file containing news articles
def load_news_csv(file_path: str):
   df = pd.read_csv(file_path)
   return df

# Example usage
news_data = load_news_csv("news_articles.csv")
print(news_data.head())  # Display first few rows of the dataset

In this step, we are reading the CSV file and storing it in a DataFrame. The dataset can now be processed to extract the relevant articles for the newsletter.

Step 2: Filter and Score Each Article Based on AI-related Keywords or Topics

Now that we have the articles, we need to analyze them for AI-related keywords or topics. These keywords could include terms like “machine learning”, “artificial intelligence”, “neural networks”, etc. The AIContentFilter class in the code is used for this purpose. It analyses the content of each article to determine whether it is related to AI/ML/Data Science.

class AIContentFilter:
   """AI Content Filter with multiple compatibility modes"""
  
   def __init__(self, openai_api_key: str):
       self.openai_api_key = openai_api_key
       # Setup for LangChain or keyword-based filtering
       self.mode = "keyword"
       self.ai_keywords = [
           'ai', 'artificial intelligence', 'machine learning', 'deep learning',
           'neural network', 'chatgpt', 'claude', 'gemini', 'openai', 'anthropic'
       ]
  
   def keyword_analysis(self, content: str) -> bool:
       """Keyword-based analysis for AI-related topics"""
       content_lower = content.lower()
       return any(keyword in content_lower for keyword in self.ai_keywords)
  
   def filter_articles(self, df: pd.DataFrame) -> pd.DataFrame:
       """Filter articles based on AI-related keywords"""
       return df[df['content'].apply(self.keyword_analysis)]

# Filter the articles in the dataset
ai_filter = AIContentFilter(openai_api_key="your-openai-api-key")
filtered_articles = ai_filter.filter_articles(news_data)
print(filtered_articles.head())  # Show filtered AI-related articles

Step 3: Apply a Threshold to Identify Only the Most Relevant Articles

Once the articles are filtered, we might want to apply a threshold to only include those that are highly relevant. For instance, we could set a confidence score based on how many AI-related keywords are found within an article. The higher the score, the more relevant the article.

Code for Applying a Threshold:

def apply_relevance_threshold(df: pd.DataFrame, threshold: int = 3) -> pd.DataFrame:
   """Apply threshold to select only the most relevant articles"""
   df['relevance_score'] = df['content'].apply(lambda x: sum(keyword in x.lower() for keyword in ai_filter.ai_keywords))
   return df[df['relevance_score'] >= threshold]

# Apply threshold to filtered articles
relevant_articles = apply_relevance_threshold(filtered_articles, threshold=3)
print(relevant_articles.head())  # Display most relevant articles

Step 4: Generate Summaries of These Filtered Articles Using an LLM

Now that we have the most relevant articles, the next step is to generate summaries of these articles. We will use an LLM (Language Learning Model) for this purpose. In the code provided, the ChatOpenAI class from the LangChain package is used to interact with OpenAI’s models to summarize the articles.

Code for Generating Article Summaries:

from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate

def generate_summary(content: str, openai_api_key: str) -> str:
   llm = ChatOpenAI(model="gpt-4o-mini", temperature=0.1, api_key=openai_api_key)
  
   prompt = f"Summarize the following article:\n\n{content}"
   response = llm(prompt)
   return response['choices'][0]['text'].strip()

# Generate summaries for the filtered articles
relevant_articles['summary'] = relevant_articles['content'].apply(lambda x: generate_summary(x, openai_api_key="your-openai-api-key"))
print(relevant_articles[['title', 'summary']].head())  # Display article summaries

Step 5: Format the Selected Content into a Ready-to-Send Newsletter Layout

Finally, we need to format the selected content into a layout suitable for sending as a newsletter. This could be done in Markdown or HTML format, depending on your preference. Below is an example of how we can format the selected articles and their summaries into a Markdown format.

Code for Formatting the Content:

def format_newsletter(articles_df: pd.DataFrame) -> str:
   """Format the selected articles into a newsletter (Markdown)"""
   newsletter_content = "# AI News Newsletter\n\n"
  
   for _, row in articles_df.iterrows():
       newsletter_content += f"## {row['title']}\n\n"
       newsletter_content += f"**Summary**: {row['summary']}\n\n"
       newsletter_content += "----\n"
  
   return newsletter_content

# Format the relevant articles into a newsletter
newsletter = format_newsletter(relevant_articles)
print(newsletter)  # Display the formatted newsletter

With these steps, we have automated the creation of content for AI-powered newsletters.

Output:

Here is the newsletter created after filtering all the news:

Newsletter Output

Go Beyond the Blog: Learn to Build and Deploy Your Newsletter Agent

So far, what we have covered in this blog helps us in understanding the foundational concepts. But let’s take a step further, from filtering content to formatting the output. If you’re interested in exploring the complete process in more detail, there’s a short free course that teaches you to build a personalized newsletter agent using Vibe Coding.

We have created a free 1-hour course using real tools like:

  1. AI21 Maestro to structure and run your Agentic workflows
  2. LangChain to handle filtering and text summarization
  3. Streamlit to deploy a clean interface.

You can access it here if you’d like to explore this course further:
🔗 Building a Customized Newsletter AI Agent

Conclusion

In a world flooded with content, the newsletter remains a prominent source for the curation of meaningful content. What we have covered in this blog is just like scratching the tip of the iceberg; How LLMs and the Agentic work frame can be leveraged to transform a manual task into scalable, intelligent systems. As these tools become more accessible, the ability to make it more scalable and personalized is no longer limited to large teams or developers. It’s something you can experiment with and customize as per your requirement.

Hi, I'm Sushant Thakur, an Instructional Designer. I'm actively involved in writing blogs and articles that explore the latest trends in Generative AI technologies and their real-world applications. Follow me for insights on how Gen AI is shaping industries and enhancing learning experiences.

Login to continue reading and enjoy expert-curated content.

Responses From Readers

Clear