Library · Your first workflow, start to finish

Build your first AI workflow live: newsletter automation

Builder80 minUpdated: October 2026
13 of 105 in the library

Module: 3. The WAT framework | Time: about 20 min theory + 60 min practice


The gist

The theory is over; now we build. This lesson walks you step by step through creating a real newsletter automation: from an empty folder to a working system that finds news, writes the email and sends it. We do it live, not on slides.


Key concepts

  • Plan Mode for starting from a fuzzy request
  • Choosing the stack through a conversation with the agent (an agent is an autonomous AI worker)
  • Brand assets as context for the agent (context is the text the AI "sees" at the moment)
  • The five tools of a newsletter automation
  • Setting up .env with API keys (API: application programming interface)
  • A human review point: when the agent must stop
  • The launch and your first real send

Theory

Why newsletter automation is the perfect first project

🎨 Picture this: newsletter automation is like the first dish for a culinary student: not too simple (fried eggs) and not too hard (a French sauce). Enough components to understand the architecture, simple enough not to drown in details. And you see the result right away: an email in your inbox.

Newsletter automation is a great first project because:

  1. Clear business value: every business understands why it's useful
  2. All the WAT components: there's a workflow (a work process), there are tools, the agent coordinates
  3. A human review point: it's obvious where a person needs to check things before sending
  4. A real result: by the end of the lesson you'll see a real email in your inbox
  5. Room to grow: this workflow can be packaged as a ready product or service, but results depend on your niche and your work

The stack we'll choose (and why)

In real work, you explain the task to the agent and it proposes a stack. We'll go through that process. But here's where we'll end up:

Component Tool Why
News search Perplexity API Search with real links and up-to-date data
Writing the text Anthropic Claude API High-quality writing in English
Infographic Nano Banana (Google's image model, Gemini API) Image generation from a prompt
Sending Gmail API Simple integration, free within Google's daily limits (check the Gmail docs for current limits)
Archive Google Sheets Send log, easy to analyze

Why Perplexity and not just Google?

Perplexity returns structured data with real links and fresh sources. Regular search through scraping is unreliable: Google blocks it, and its API is expensive. The Perplexity API gives you clean JSON (a data format) with sources.

Why Gmail and not SendGrid?

For a first project Gmail is simpler: you don't need to verify a domain, and you can start in 10 minutes. Dedicated email services (SendGrid, for example) are better for industrial-scale sends to thousands of people.


Step 1: Plan Mode, starting from a fuzzy request

Open Claude Code in a new empty folder called newsletter-automation.

Write this first request:

Type this into the chat
I want to build an automatic weekly news email about [your topic] for clients.
Before you start, ask me clarifying questions, put together a plan,
then show me the WAT structure you're going to create.

The agent will ask questions like:

  • "Where should the news come from: specific sites or a general search?"
  • "How is the recipient list stored?"
  • "Do you need an infographic in the email?"
  • "What language should the email be in?"
  • "Do you need to approve each send?"

Answer honestly. In the end the agent will put together a plan. You sign off on it, and the building begins.


Step 2: Loading brand assets

🎨 Picture this: brand assets for an agent are like a uniform and a briefing for a new server. Without the uniform, they're just a person in the dining room. With the uniform and the briefing ("we're an Italian restaurant, no sushi, we speak politely, we suggest wine"), they're part of your brand.

Before the agent starts generating content, give it brand context.

Create a folder /brand_assets/ and put in it:

  • logo.png: your logo (or download any placeholder)
  • brand_guidelines.md: a description of the brand

Sample brand_guidelines.md:

Type this into the chat
# Brand Guidelines

## Tone of Voice
- Professional but approachable
- No grandstanding
- Specifics matter more than pretty words
- Short sentences

## Colors
- Primary: #1A56DB (blue)
- Secondary: #F3F4F6 (light gray)
- Accent: #10B981 (green for positive news)

## Typography
- Headings: bold, large
- Body: 16px, line height 1.6

## What NOT to write
- No "revolutionary" or "unique"
- Don't start with "In an era of..."
- Don't use the word "innovative"

After loading the assets, tell the agent:

Type this into the chat
I've added a logo and brand guidelines to /brand_assets/.
Use these materials when generating content and laying out the email.
Reference the files as @brand_assets/logo.png and @brand_assets/brand_guidelines.md.

Step 3: The agent creates five tools

The agent will write all the tools itself based on the plan. Here's what you'll get:

Tool 1: tools/research_news.py

Calls the Perplexity API with a given query and returns a list of 5–7 news items in the format [{title, description, url, date, source}].

Tool 2: tools/generate_infographic.py

Takes the news list, builds a prompt (a request to the AI) for an image generation API, and returns a URL or a base64 image. Nano Banana (via the Gemini API) takes a text request and returns an image.

Tool 3: tools/assemble_html.py

Takes the news + the infographic + the brand guidelines, calls the Claude API, and generates a finished HTML email template. It inserts the logo and applies the colors from the brand guidelines.

Tool 4: tools/send_via_gmail.py

Takes the HTML, the recipient list and the subject line. Uses the Gmail API through OAuth 2.0. Sends the email to each recipient.

Tool 5: tools/archive_to_sheets.py

Writes a row to Google Sheets: send date, number of recipients, subject line, status. Builds a log for analysis.


Step 4: Configuration files

The agent will create two config files:

config/newsletter_style.json

json
{
  "font_family": "system-ui, -apple-system, sans-serif",
  "font_size_body": "16px",
  "line_height": "1.6",
  "colors": {
    "primary": "#1A56DB",
    "background": "#F3F4F6",
    "accent": "#10B981",
    "text": "#111827"
  },
  "max_width": "600px",
  "news_count": 5
}

config/recipients.json

json
{
  "test": ["[email protected]"],
  "production": [
    "[email protected]",
    "[email protected]"
  ]
}

Start with test: send to yourself. Once everything is set up, add real recipients to production.


Step 5: Setting up .env with API keys

The agent will create a .env.example template:

bash
# Anthropic API (platform.claude.com → API Keys)
ANTHROPIC_API_KEY=your_key_here

# Perplexity API (perplexity.ai → API)
PERPLEXITY_API_KEY=your_key_here

# Gmail API (Google Cloud Console → Credentials)
GMAIL_CLIENT_ID=your_client_id
GMAIL_CLIENT_SECRET=your_client_secret
GMAIL_REFRESH_TOKEN=your_refresh_token

# Google Sheets (same Google Cloud project)
GOOGLE_SHEETS_ID=your_spreadsheet_id

# Gemini API for image generation with Nano Banana (optional)
GEMINI_API_KEY=your_key_here

How to get the keys:

  1. Anthropic API: go to the Console (platform.claude.com) → API Keys → Create Key
  2. Perplexity API: go to perplexity.ai → Settings → API → Generate
  3. Gmail API: the hardest one. Google Cloud Console → New Project → Enable Gmail API → Credentials → OAuth 2.0 Client ID → download the JSON → use google-auth-oauthlib to get a refresh token
  4. Google Sheets API: the same Google Cloud project → Enable Sheets API → you can use the same OAuth

Copy .env.example to .env and fill in the real keys. Make sure .env is listed in .gitignore.


Step 6: The human review point, where the agent stops

🎨 Picture this: a human review point is like a quality control checkpoint in a factory. The assembly line moves fast, but before anything ships to the customer, it has to pass inspection. Let one defect through and you lose a client. Two minutes of checking saves a week of damage to your reputation.

This is a critical part of the workflow. Before sending emails, the agent must stop and show you a preview.

In the workflow it looks like an explicit instruction:

Type this into the chat
### Step 3: ⚠️ MANDATORY HUMAN REVIEW

STOP. Do not continue automatically.

Show me:
1. An HTML preview of the email
2. The recipient list (which mode: test or production)
3. The subject line
4. The number of news items and their headlines

Wait for explicit confirmation: "Send it" or "OK send" or "go"
If you get "stop" or "wait", don't send; wait for instructions.

Why this matters: the agent might have generated a news item with a factual error. Or picked an unsuitable topic. Or someone extra ended up on the recipient list. You check once, and then the system runs on its own with periodic spot checks.


A real prompt example for newsletter automation

Here's a complete prompt you can use as a template for your own niche:

Type this into the chat
Build a weekly newsletter automation for a real estate agency.

What the system should do:
1. Every Monday at 10:00 AM, find 5-7 fresh news items for the query
   "Austin real estate market 2026" through the Perplexity API
2. Based on the news found, generate an HTML email in the style of
   the brand guidelines in /brand_assets/
3. Add a "Listing of the week" section with a placeholder to fill in by hand
4. STOP and show me a preview before sending
5. After my "ok", send through the Gmail API to the list in config/recipients.json
6. Write a send log to Google Sheets

Important:
- Email tone: professional, no grandstanding, concrete numbers
- Language: English
- Maximum 800 words for the whole newsletter
- Always include links to the news sources

Step 7: Launch, "Write me a newsletter about agentic AI"

🎨 Picture this: the first run of a workflow is like the first start of a new car off the assembly line. If the engine turns over, that's already a win. Then comes the break-in, then the fine-tuning. Don't expect the first run to be perfect; expect it to work.

After all the setup, write to the agent:

Type this into the chat
Run the newsletter workflow.
This week's topic: agentic AI for small business.
Use the test recipient list.

The agent will:

  1. Call research_news with your topic
  2. Show the news it found (you can remove some)
  3. Call generate_infographic
  4. Call assemble_html
  5. Stop and show the preview
  6. After your "Send it", call send_via_gmail
  7. Call archive_to_sheets

In about 3–5 minutes there will be a real email in your inbox.


Practice

Exercise: Build a newsletter automation from scratch to the first send.

Step 1, Preparation (15 min):

  1. Create a folder called newsletter-automation
  2. Open it in VS Code with Claude Code
  3. Create brand_assets/brand_guidelines.md for your topic
  4. Create a .gitignore containing .env and logs/

Step 2, Plan Mode (10 min):

  1. Write the Plan Mode request (the text from Step 1 of the theory)
  2. Answer the agent's questions
  3. Sign off on the plan

Step 3, Building (25 min):

  1. Give the agent the go-ahead: "Start building according to the plan"
  2. Watch it create the structure, the workflow, the tools
  3. Answer clarifying questions now and then if the agent stops

Step 4, API keys (15 min):

  1. Fill in .env (at minimum: ANTHROPIC_API_KEY and one email service)
  2. If you don't have Perplexity, use the Anthropic API with WebSearch or just test data

Step 5, First run (10 min):

  1. Run the test workflow to your own email
  2. Check the email in your inbox
  3. Take a screenshot: this is your first agentic product

Tools and resources


Common mistakes

Mistake 1: Launching without .gitignore

You created a project, set up .env with keys, ran git add ., and the keys leaked into the repo. Always create .gitignore BEFORE the first commit.

Mistake 2: Skipping the human review point

You wrote "send automatically" in the workflow, and the agent sent an unchecked email with a factual error to every client. For the first 10–20 runs, always check by hand before sending.

Mistake 3: An initial prompt that's too general

"Make me a newsletter," with no details about topic, audience, language or style. The more specific the initial prompt, the fewer rounds of revision later. Use Plan Mode so the agent asks the right questions.


Cross-references


Key takeaways

Plan Mode lets you start from a fuzzy idea: the agent asks the right questions itself and puts together a plan.

Brand assets + brand guidelines give the agent context for creating content in the right style.

A human review point is a mandatory stop before any irreversible action (sending, publishing, payment).

At the end you don't just have files: you have a working system that can be packaged into a service or product.


Next lesson

→ Debugging and self-repair: what to do when the first run breaks

The mark stays in this browser only and is never sent anywhere. My progress