The Problem: Content Without Direction
A few months ago I started working on conversoriaecnae.es, a site about CNAE and IAE codes (Spanish tax regulations). Traffic was decent, but I faced a classic problem:
What content should I create?
I could write random articles about CNAE, but that's shooting blind. I needed a system that:
1. Discovered what people were searching for 2. Analyzed if it was relevant 3. Generated optimized content automatically 4. Published only quality work
Thus the Autonomous Content Agent was born.
The Architecture: Monitoring → Analysis → Generation → Publishing
The system works in four phases:
Phase 1: Discovery (Gmail Monitoring)
I set up Google Alerts to monitor Spanish regulations about CNAE, IAE, taxes, and labor law. All alerts land in an email, and my agent captures them automatically using the Gmail API.
```typescript // The agent checks Gmail periodically const alerts = await gmail.users.messages.list({ userId: 'me', q: 'from:google-alerts@google.com' }); ```
Simple but effective. I don't manually check anything.
Phase 2: Filtering (Relevance Scoring)
This is where Claude comes in. I don't publish everything Google Alerts finds. Each alert gets automatically scored:
- **CNAE/IAE Relevance**: Does it directly discuss tax codes?
- **Timeliness**: Is it a new regulation or important change?
- **SEO Potential**: Are there keywords people search for?
- **Clarity**: Can I explain it without confusing people?
Recent commits show I've been refining this constantly:
``` fix: Improve statistics agent prompts for higher quality scores (1/12/2026) ```
That wasn't random. After publishing mediocre content, I realized my prompts were too generous. I lowered the quality threshold and the system started rejecting more alerts.
Key metric: Of the alerts I receive, I typically publish only a fraction. The rest don't pass the filter. This is good—it means I'm being selective.
Phase 3: Generation (Article Creation)
Once an alert passes the filter, Claude generates a complete article in Spanish (es-ES) with:
- SEO-optimized title
- Meta description
- Header structure
- Paragraphs with CNAE/IAE context
- Internal links to related content
The stack is 98% TypeScript, using:
- **@anthropic-ai/sdk**: For Claude API calls
- **@sanity/client**: To store drafts
- **@supabase/supabase-js**: To store alert data
- **cheerio**: To parse HTML from alerts
```typescript // Simplified generation const article = await claude.messages.create({ model: "claude-3-5-sonnet-20241022", max_tokens: 2000, messages: [{ role: "user", content: `Generate an article about: ${alertContent}. Focus: CNAE/IAE, Spanish regulation, SEO.` }] }); ```
Phase 4: Publishing (Sanity CMS)
I don't publish directly. Everything goes to Sanity as a draft. I review, edit if needed, and publish manually. This gives me final quality control.
How I Measure Performance
Here's the interesting part: How do I know if the agent is working?
Just counting published articles isn't enough. I need real metrics:
1. Rejection Rate
I track how many alerts come in vs. how many get published. If rejection rate is too high, the system is too strict. If too low, I'm publishing garbage.
I'm currently calibrating this. Recent commits show prompt iterations—that means I'm adjusting the balance.
2. Time on Page
I use Analytics to see how long users spend on agent-generated articles vs. articles I wrote manually.
If people leave quickly, the content isn't useful. If they stay, I'm on the right track.
3. Clicks to Internal Resources
Each article has links to other site pages (CNAE converters, IAE calculators, etc.). If nobody clicks, the content isn't relevant.
4. Publishing Errors
I track bugs: duplicate content, broken links, formatting errors. Each error tells me where to improve the prompt or logic.
The Reality: Not Everything Works on First Try
This project is actively in development. Look at the status:
```
- Phase 1: Foundation ✅ COMPLETE
- Phase 2: Gmail Integration ✅ COMPLETE & TESTED
- Phase 3: AI Agents 🔨 IN PROGRESS
```
It's not finished. And that's exactly the point.
In the first weeks, the agent published articles that were technically correct but boring. Users didn't scroll. I iterated on the prompts.
Then it published too much content. I adjusted relevance thresholds.
Then articles had formatting errors. I improved sanitization logic.
Every change is documented in commits. I don't hide failures—I publish them.
Practical Lessons for Building Content Agents
1. Start Without AI
Before automating, do it manually. Understand the process. Only then automate.
2. Measure the Right Things
Don't count generated articles. Measure engagement. An article nobody reads is worthless.
3. Iterate on Prompts
Prompts are code. Version them. Test small changes. Measure impact.
4. Keep Quality Control
I don't publish automatically. I review everything. This prevents publishing garbage and helps me learn what works.
5. Document the System
I have a CLAUDE.md file with my agent configuration. This lets me iterate without losing context.
The Stack I Use
For those wanting to replicate this:
- **Next.js**: Main framework
- **Supabase**: Database for alerts and statistics
- **Sanity**: CMS for content
- **Claude (Anthropic)**: Generation and analysis
- **Gmail API**: Alert monitoring
- **Vercel**: Deployment
All in TypeScript. No surprises.
Next Steps
I'm in Phase 3: AI Agents. The next step is:
1. Improve relevance scoring with more historical data 2. Automate publishing (with final review) 3. Create a dashboard to see metrics in real time 4. Experiment with different content styles
The Takeaway
You don't need a big team to automate content. You need:
1. A real problem: What content to create 2. A process: How to discover it, analyze it, generate it 3. Clear metrics: How to know if it works 4. Constant iteration: Improve based on data
This agent isn't perfect. But it's alive, learning, and improving every day.
Are you building something similar? Share your experience. Those of us iterating in public learn together.
