How I Built a Fully Automated pSEO Engine with LangGraph and Gemini
Last month I got tired of manually writing comparison articles for my two niche sites. So I built a fully automated pipeline that generates, validates, and deploys content 4 times a day without my involvement. Here's th
Last month I got tired of manually writing comparison articles for my two niche sites. So I built a fully automated pipeline that generates, validates, and deploys content 4 times a day without my involvement.
Here's the technical breakdown.
The Problem
I run two pSEO sites:
- feescompared.com — comparing crypto exchanges by fees, limits, and security
- getaivs.com — comparing AI tools by pricing, features, and API limits
Manually writing 60+ comparison articles per month was not sustainable. I needed automation that could:
- Generate factual, specific content (not generic fluff)
- Maintain consistent quality across thousands of articles
- Deploy automatically without breaking the build
- Avoid duplicate content (a common pSEO trap)
The Stack
- LangGraph for the agent orchestration
- Gemini 3.8 Flash for content generation
- Astro 5 for the static site generator
- Vercel for hosting + auto-deploy
- SQLite for state tracking
- GitHub Actions for the cron scheduler
The Architecture
The agent is a LangGraph state machine with 6 nodes:
Each node is bound to a specific niche config via functools.partial, so the same code handles both crypto and AI tools.
Key design decisions:
-
Config-driven — all prompts, paths, and model settings live in a single
config.json -
Isolated datasets — each niche has its own
pairs.json, SQLite DB, and Astro site - Retry logic — Gemini calls have exponential backoff (2s → 4s → 8s)
- Validation before export — checks frontmatter, sections, word count
The Validation Step (The Secret Sauce)
The hardest part of pSEO isn't generation — it's maintaining quality. My validate_node checks:
- All required H2 sections are present
- Word count is within min/max range
- Frontmatter has
title,description,tags - (For crypto) every fee number is tagged
(verify)— I removed this later, but it was crucial for accuracy
If validation fails, the agent regenerates with feedback up to 3 times before giving up.
The Deploy Step
After export, a deploy_node runs vercel --prod via subprocess and parses the URL from stdout. If deploy fails, the article is still committed to git (thanks to if: always() in GitHub Actions), so nothing is lost.
The Cron
GitHub Actions runs the agent 4 times a day:
yaml
on:
schedule:
- cron: "0 6 * * *" # 06:00 UTC daily
Each run generates 2 crypto + 2 AI articles, deploys both sites, and commits the updated SQLite state back to git.
## The Results
After 2 weeks:
- 81 articles published (39 crypto + 42 AI)
- 11 pages indexed by Google
- 373 impressions in Search Console
- Cost: ~$15/month in Gemini API calls
## What I Learned
**1. Sanitization matters more than generation.** Gemini outputs are not MDX-safe by default — it hallucinates `<br>` tags, `$` currency signs (which break LaTeX), and phantom product names. I built a `_sanitize_mdx` function that protects fenced code blocks and math blocks while escaping everything else.
**2. Validation is not optional.** About 30% of first-pass generations fail validation. Without the retry loop, I'd have 30% broken articles.
**3. Whitelist entities.** Gemini invented "DALL-E 4" and "SD 4" (which don't exist). Now I inject a whitelist of 48 real entities into every prompt — Gemini refuses to compare anything outside the list.
**4. Ship early, iterate on data.** I launched with generic titles ("Fees, Limits & Security Compared") and got 0 clicks despite 373 impressions. Now I'm rewriting all titles to be click-worthy ("Which is Cheaper in 2026?") and watching the CTR.
## What's Next
- Adding Schema.org FAQ markup to each article
- Interactive fee calculators (dollar savings per volume)
- Category hub pages (LLMs, Code Editors, Image Generators)
You can see the generated AI tools comparison site at [getaivs.com](https://www.getaivs.com) — 42 articles, all AI-generated, all validated.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.