Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

📝 Auto Medium Article Generator

An n8n multi-agent pipeline that turns a single topic into a researched, fact-checked, illustrated, publication-ready Medium article — fully automated.

Drop a topic into a Google Sheet (or click Test), and a fixed chain of five specialized sub-agents researches the topic on the live web, generates a custom architecture diagram, sources a royalty-free hero image, writes the article, fact-checks it against the research, and delivers it by email with the Markdown attached.

Main workflow


✨ What it does

Stage Output
🔎 Research Live web search with inline citations, grounded facts
📊 Diagram A custom architecture diagram generated per topic (Excalidraw → Kroki SVG)
🖼️ Image A royalty-free hero image with proper attribution (Unsplash)
✍️ Write A structured Medium article in Markdown, grounded in the research
Fact-check An automated QA gate that scores the draft before delivery
📬 Deliver Email with the .md attached + a best-effort local file export

🏗️ Architecture

The pipeline runs as a deterministic chain — each stage is a separate n8n sub-workflow invoked in a fixed order by the main orchestrator.

flowchart TD
    subgraph Trigger
        A["📄 New Topic Row<br/>(Google Sheets)"]
        B["▶️ Manual Test Run"]
    end
    A --> C["Extract Topic"]
    B --> C

    C --> R["🔎 Run Research<br/>sub-agent"]
    R --> D["📊 Run Diagram<br/>sub-agent"]
    D --> I["🖼️ Run Image<br/>sub-agent"]
    I --> W["✍️ Run Writer<br/>sub-agent"]
    W --> AS["🧩 Assemble Final<br/>Markdown + HTML<br/>embeds hero + diagram"]
    AS --> Q["✅ Run QA<br/>sub-agent"]
    Q --> QP{"QA Passed?"}

    QP -->|yes| PM["Publish to Medium"]
    PM --> POK{"Published OK?"}
    QP -->|no| PE["Prepare Export"]
    POK -->|no| PE

    PE --> EM["📬 Email Article<br/>(.md attached)"]
    PE --> EX["💾 Export Markdown File<br/>best-effort"]

    classDef agent fill:#eef6ff,stroke:#3b82f6,color:#1e3a8a;
    class R,D,I,W,Q agent;
Loading

The five sub-agents

Sub-workflow Role Key nodes
workflows/research-agent-subworkflow.json Web research & verification LLM Agent + OpenAI web_search tool
workflows/diagram-agent-subworkflow.json LLM designs a flow spec → code builds valid Excalidraw → Kroki renders SVG Diagram Agent → Build Excalidraw Scene → Render (Kroki) → Data URI
workflows/image-agent-subworkflow.json Royalty-free hero image Clean Query → Search Unsplash → (fallback) → Extract URL
workflows/writer-agent-subworkflow.json Writes the article in Markdown Writer Agent (grounded in research)
workflows/qa-agent-subworkflow.json Fact-check gate (pass/fail + score) QA Agent

💡 Why deterministic, not a single AI orchestrator?

An earlier version used one AI Agent node with the five sub-agents attached as tools. The LLM orchestrator routinely skipped steps — it would write the article itself and never call the diagram/image/QA tools, because tool-calling is non-deterministic and conflicts with a required fixed sequence.

The main workflow now invokes each sub-agent explicitly with Execute Sub-workflow nodes, so every step runs every time, in order. Each sub-agent still uses an LLM internally where reasoning is actually needed.


🖼️ Example output

The system generated this end-to-end for the topic "LangChain Architecture":

Article (with hero + citations) Auto-generated diagram
Article Diagram

The image sub-agent handles sparse topics gracefully — cleaning the search query and falling back to a striking abstract-tech image when a niche term returns no results:

Image sub-agent

And every run executes cleanly through all nodes:

Executions


🧰 Tech stack

  • n8n — workflow orchestration (Execute Sub-workflow chaining)
  • OpenAI GPT — chat models for research, writing, QA + web_search tool
  • Kroki / Excalidraw — programmatic diagram rendering (→ SVG)
  • Unsplash API — royalty-free hero images
  • Google Sheets — topic queue / trigger
  • SMTP — email delivery
  • JavaScript — Code nodes for assembly, parsing, and Excalidraw scene building

🚀 Setup

All credentials live in n8n's encrypted credential store — never in the JSON files.

  1. Import all six workflows into n8n (Workflows → Import from File).
  2. Activate the five sub-workflows (research / diagram / image / writer / qa). Execute Sub-workflow calls require the called workflow to be active. Leave the main workflow inactive until you want the automatic Sheets trigger.
  3. OpenAI credential (openAiApi) — used by the research, diagram, writer, and qa sub-agents.
  4. Unsplash credentialHeader Auth (httpHeaderAuth): Name Authorization, Value Client-ID <your-unsplash-access-key>. Select it on the Search Unsplash node.
  5. Google Sheets — add a Google Sheets OAuth credential and set the document ID on the New Topic Row trigger. Columns: Topic (required), Audience, Notes (optional).
  6. SMTP — bind your mail credential to the Email Article node.
  7. Test with the Manual Test Run node (no sheet needed), or click Test workflow.

Repository files

File Role
workflows/medium-article-generator-workflow.json Main chain — import and open this one
workflows/research-agent-subworkflow.json Web research & verification
workflows/diagram-agent-subworkflow.json Excalidraw → Kroki SVG diagram
workflows/image-agent-subworkflow.json Unsplash hero image
workflows/writer-agent-subworkflow.json Markdown article writer
workflows/qa-agent-subworkflow.json QA / fact-check gate

⚠️ Caveats

  • Medium's public API is retired (no new tokens since 2023), so the publish node fails by design and routes to the email + file fallback. Delivery is resilient: email (with the .md attached) is the primary output and runs in parallel with a best-effort local file write.
  • Kroki uses the public kroki.io instance (data leaves your network, rate-limited) — self-host for production. Diagrams embed as a base64 data URI, great for the .md/HTML/email but stripped by Medium's importer (host the SVG at a URL for true Medium embedding).
  • OpenAI web_search availability depends on account/model access — swap the research HTTP tool for SerpApi/Tavily if unavailable.
  • Hero images use Unsplash (an earlier OpenAI Images path was dropped due to a key without Images entitlement); the extractor can be repointed to POST /v1/images/generations if you have image access.

Built with n8n. Free to adapt.

About

n8n multi-agent pipeline that turns a topic into a researched, fact-checked, illustrated Medium article

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors