I Built a 6-Agent AI System to Publish Content Automatically. Here's How the Architecture Works.

Projects· 5 min read

I Built a 6-Agent AI System to Publish Content Automatically. Here’s How the Architecture Works.

There’s a specific moment when you realize the problem isn’t content quality. It’s scale.

It was February 2026. I had conversoriaecnae.es running: a directory of CNAE and IAE codes for freelancers and SMEs in Spain. The SEO was working. Pages were ranking. But I had 2,163 codes to cover with quality educational articles, a weekly newsletter, and distribution across six social platforms.

Doing that manually wasn’t a productivity challenge. It was mathematically impossible.

The solution wasn’t hiring writers. It was building a system.

The Architecture: Orchestrator → Specialized Agents → Distribution

The system has a logic that’s easy to understand, even if the implementation has its complexity:

[@portabletext/react] Unknown block type "code", specify a component for it in the `components.types` prop

Each layer has clear responsibilities. No agent does too much. This separation isn’t just clean architecture: it’s what allows you to optimize each piece independently.

The Agents, One by One

1. Filter Agent: The Gatekeeper

Monitors Gmail connected to Google Alerts. When new alerts arrive, it processes them in batches of 10 with Claude Haiku 4.5 and assigns a score from 0 to 100 based on CNAE/IAE relevance.

The decision to use Haiku here (instead of Sonnet) was deliberate: this task is high volume and low creative complexity. Haiku handles structured classification perfectly. Sonnet would be oversized, and the accumulated cost across five daily executions would be unnecessary.

2. Planner Agent: The Editor

Selects four daily topics following a concrete logic:

  • 2 educational articles on CNAE/IAE codes selected by keyword opportunity
  • 2 news articles based on highest-scoring filtered sources

It uses a rank-based priority queue to ensure systematic coverage. Not random. Systematic. Otherwise, covering 2,163 codes in any logical order would take years.

3. Educational Agent: The Writer

Generates articles between 800 and 1,200 words with fixed structure: introduction, code explanation, practical examples for freelancers, FAQ section, and Unsplash image with automatic attribution.

The interesting part: each article goes through an 8-point quality checklist. If the score is ≥80, it publishes automatically without human intervention. If not, it’s flagged for review.

That’s what makes the system work without constant supervision: I don’t blindly trust the AI, but I don’t review every piece either. The quality threshold does the filtering work.

4. Publisher Agent: The Technician

Converts generated markdown to Sanity CMS Portable Text. This seems like a minor detail, but it’s an important architectural decision: raw HTML ties you to a format; Portable Text lets you reuse content across any future surface.

It also extracts FAQ blocks, manages images as Sanity assets, and adds SEO metadata (title 40-70 characters, meta description 50-60, description 140-160). These limits are enforced at generation time, not as post-processing. Much more reliable.

5. Newsletter Agent: The Communicator

Weekly, it generates a summary with featured articles, the stat of the week, and subject line alternatives for A/B testing. It integrates with the statistics pipeline to include updated CNAE/IAE code rankings when available.

6. Social Agents: The Distributors

There’s one agent per platform: LinkedIn, Twitter/X, Facebook, Threads, Instagram, and Reddit. Each knows its channel’s character limits, appropriate tone, and hashtag strategy. Content reaches Late API for automatic scheduling.

A single generic agent for all platforms would be simpler to build. But the result would be mediocre content everywhere. Specialized agents allow optimizing copy for each context.

The Three Technical Decisions That Matter Most

Prompt Caching

Each agent has an extensive system prompt (over 4,096 tokens) with domain context, editorial rules, and examples. Without caching, that cost would duplicate on every call. With Anthropic API caching enabled, input token savings on repeated calls hover around 80%.

In a system running five daily pipelines, this isn’t premature optimization. It’s what makes the system economically viable long-term.

Structured Outputs (JSON Schema)

All agents return JSON with a defined schema. No exceptions. This eliminates fragile parsing problems and, more importantly, eliminates output ambiguity that forces edge case handling in downstream code.

[@portabletext/react] Unknown block type "code", specify a component for it in the `components.types` prop

When JSON is schema-guaranteed, the code consuming it is dramatically simpler.

Temporal Context Injection

All agents receive dynamic temporal context: current date, season, Spanish fiscal calendar. This prevents generated content from becoming outdated or ignoring relevant context (like January peaks in IAE epigraph change queries).

Commit 496b64e from February 16, 2026 implemented this. Before that change, some articles ignored the time of year. A small detail with real impact on relevance.

The Real Problem: Vercel’s Timeout

The system processes four topics in parallel per cron execution. Processing them sequentially, the pipeline exceeded Vercel’s 300-second limit under high loads.

The solution was parallelization with two concurrent batches of ten items, plus replacing Promise drops with explicit await inside each topic’s processing. The February 15, 2026 commits document exactly that debugging:

[@portabletext/react] Unknown block type "code", specify a component for it in the `components.types` prop

This is building in public in its most honest form: the problem was in production, the commits document it, the solution is visible.

Takeaway

What’s surprised me most about building this system isn’t the technology. It’s that the architecture of specialized agents with clear responsibilities works for the same reason a well-organized human team works: each piece does one thing well, and coordination emerges from interfaces, not chaos.

If you’re thinking about building something similar:

  1. Start with the simplest agent (the filter) before orchestrating the full system.
  2. Add structured outputs from day one, not as a later refactor.
  3. Prompt caching is not optional if you’re running pipelines frequently. Enable it from the start.

The code for this system is private for now, but I document architecture decisions publicly. If you have specific questions about any layer, I’ll answer in the comments.

Brian Mena

Brian Mena

Software engineer building profitable digital products: SaaS, directories and AI agents. All from scratch, all in production.

LinkedIn