# Newsletter Agent (`pratikdani/newsletter-agent`) Actor

An AI-powered Apify actor that generates well-structured newsletters using a crew of specialized AI agents. The system uses CrewAI to coordinate multiple agents that research, write, and edit newsletter content based on user input.

- **URL**: https://apify.com/pratikdani/newsletter-agent.md
- **Developed by:** [Pratik Dani](https://apify.com/pratikdani) (community)
- **Categories:** AI, News, Automation
- **Stats:** 8 total users, 1 monthly users, 100.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

$750.00 / 1,000 generate newsletters

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Newsletter AI Agent

An AI-powered Apify actor that generates well-structured newsletters using a crew of specialized AI agents. The system uses CrewAI to coordinate multiple agents that research, write, and edit newsletter content based on user input.

### Documentation

[![Documentation](https://img.shields.io/badge/docs-online-blue.svg)](https://newsletter-ai-agent.pratikdani.com/)

### Features

- **Multi-agent System**: Uses CrewAI to coordinate specialized agents for research, writing, and editing
- **Apify Integration**: Leverages Apify actors for efficient web scraping and data collection
- **Comprehensive Research**: Gathers information from multiple sources:
  - Google Search results
  - Latest news articles
  - Reddit discussions
  - Twitter/X posts
  - YouTube videos
- **Intelligent Processing**: Transforms raw data into well-structured newsletters
- **Markdown Output**: Delivers clean, formatted content ready for distribution
- **Configurable Sections**: Customize newsletter structure and content focus

### Architecture

```mermaid
graph TD
    subgraph "User Interface"
        A[Apify Actor Input] --> B[main.py]
    end

    subgraph "Core System"
        B --> C[NewsletterCrew]
        C --> D[Agent Orchestration]
    end

    subgraph "Agents"
        D --> E[Researcher Agent]
        D --> F[Writer Agent]
        D --> G[Editor Agent]
    end

    subgraph "Tools"
        E --> H[Google Search Tool]
        E --> I[Reddit Tool]
        E --> J[Twitter Tool]
        E --> K[YouTube Tool]
        E --> L[Google News Tool]
    end

    subgraph "Apify Integration"
        H --> M[Apify Actors]
        I --> M
        J --> M
        K --> M
        L --> M
        M --> N[Web Data]
    end

    subgraph "Output"
        G --> O[Newsletter Content]
        O --> P[Apify Actor Output]
    end

    classDef default fill:#F3F4F6,stroke:#D1D5DB,color:#1F2937
    classDef core fill:#E5E7EB,stroke:#9CA3AF,color:#111827
    classDef highlight fill:#DBEAFE,stroke:#93C5FD,color:#1E40AF
    classDef agents fill:#FCE7F3,stroke:#F9A8D4,color:#9D174D
    classDef tools fill:#D1FAE5,stroke:#6EE7B7,color:#065F46
    classDef apify fill:#E0F2FE,stroke:#7DD3FC,color:#0C4A6E

    class B,C,D core;
    class E,F,G agents;
    class H,I,J,K,L tools;
    class M,N apify;
```

### Prerequisites

- Python 3.10+
- Apify API key
- Google API key for Gemini Pro
- Apify CLI (for local development)

### Environment Setup

1. Clone the repository:

```bash
git clone https://github.com/pratik-dani/newsletter-ai-agent.git
cd newsletter-agent
```

2. Install Apify CLI:

```bash
npm install -g apify-cli
```

3. Create and activate virtual environment:

```bash
python -m venv venv
source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
```

4. Install dependencies:

```bash
pip install -r requirements.txt
```

5. Configure environment variables in `.env`:

```bash
APIFY_API_KEY=your_apify_api_key_here
GOOGLE_API_KEY=your_google_api_key_here
```

### Usage

#### Local Development

1. Run the actor locally:

```bash
apify run
```

2. Test with custom input by modifying `storage/key_value_stores/default/INPUT.json`:

```json
{
    "topic": "Your newsletter topic here"
}
```

#### Apify Platform Deployment

1. Login to Apify:

```bash
apify login
```

2. Deploy the actor:

```bash
apify push
```

### Input Schema

```json
{
    "topic": {
        "title": "Newsletter Topic",
        "type": "string",
        "description": "Topic or requirements for the newsletter",
        "editor": "textfield"
    }
}
```

Example input:

```json
{
    "topic": "Latest developments in quantum computing, focusing on breakthroughs, industry news, and practical applications"
}
```

### Output Format

The actor outputs a dataset containing:

```json
{
    "topic": "string",
    "content": "markdown formatted newsletter content",
    "status": "success|error",
    "timestamp": "ISO 8601 datetime"
}
```

### Project Structure

```
newsletter-agent/
├── .actor/                # Actor configuration
├── docs/                  # Documentation
├── src/
│   ├── agents/           # AI agent implementations
│   │   ├── researcher.py # Research agent
│   │   ├── writer.py     # Content writer
│   │   └── editor.py     # Editor
│   ├── config/           # Configuration
│   ├── tools/            # Apify integration tools
│   ├── newsletter_crew.py # Agent orchestration
│   └── main.py          # Entry point
├── tests/                # Test suite
├── requirements.txt      # Python dependencies
└── README.md
```

### Contributing

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

### License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

# Actor input Schema

## `topic` (type: `string`):

The topic or subject for the newsletter. Can include specific requirements or focus areas.

## Actor input object example

```json
{
  "topic": "I want to know everything about AI agents – current news, AI agentic platforms and frameworks, and companies in this field."
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("pratikdani/newsletter-agent").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("pratikdani/newsletter-agent").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call pratikdani/newsletter-agent --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,pratikdani/newsletter-agent"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/KYO13169Q7GRNxETA/builds/PuLu3Da7NKcjb7t8V/openapi.json
