Recursive Content Generation with GPT-4o Agents - n8n Workflow

Deploy a powerful n8n workflow using LangChain agents (Writer and Editor) for recursive, high-quality content generation and automated editing feedback via GPT-4o. This n8n template automates content refinement.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Content Developers: Users looking for advanced n8n templates utilizing multi-agent collaboration for drafting and polishing written content.
AI Automation Engineers: Developers requiring a robust framework for implementing self-correcting AI loops within an n8n workflow.
Technical Writers & Marketers: Professionals who need high-quality, iterative drafts generated automatically using the power of the OpenAI GPT-4o model.
n8n Users: Individuals seeking practical examples of how to use LangChain-based n8n node capabilities for complex task execution.

Overview

Generating polished, production-ready content often requires multiple rounds of review and revision. This specialized n8n workflow eliminates the manual back-and-forth by implementing a recursive feedback loop managed entirely by AI agents.

The core value of this n8n template lies in its multi-agent architecture: a dedicated Writing Agent generates the initial draft, and an Editing Agent critically reviews the draft, provides specific, actionable edits, and sets a 'status' flag. If the status is 'incomplete,' the workflow loops back, feeding the suggested edits directly to the Writing Agent for revision. This loop continues until the Editing Agent deems the content 'complete,' ensuring a high standard of output quality without human intervention. This sophisticated use of an n8n node structure demonstrates the power of orchestrated AI.

How it Works

This highly advanced n8n workflow follows a self-correcting iterative cycle:


  1. Trigger and Input: The n8n workflow starts with the When chat message received n8n trigger, which receives the initial content prompt from the user. The chatInput node stores this prompt.

  2. Initial Edit Handling: The handle edits n8n node checks for previous edits (on the first run, this is empty) and prepares the input for the writer.

  3. Writing Phase: The Writing Agent (powered by GPT-4o via the OpenAI Chat Model n8n node) generates a blurb based on the user prompt and any existing edits.

  4. Editing and Review: The output is immediately passed to the Editing Agent. This agent reviews the text, identifies necessary improvements, and uses the Structured Output Parser n8n node to format its feedback, providing both specific edits and a status (complete/incomplete).

  5. Variable Setting and Check: The set variables node captures the status and edits. The If Status Complete n8n node then executes a crucial flow control check.

  6. The Recursive Loop:

If Status is 'incomplete': The flow takes the secondary path, looping back to the handle edits n8n node, carrying the new suggested edits. The Writing Agent restarts its process, incorporating the feedback.
If Status is 'complete': The flow proceeds to the chatOutput node, marking the content generation process as finished. The final polished content from the Writing Agent is returned as the result of the n8n workflow.

Installation Guide

To utilize this complex n8n template, follow these steps:


  1. Import: Copy the entire n8n workflow JSON provided and import it directly into your n8n instance.

  2. Credentials Setup: You must configure credentials for the OpenAI Chat Model n8n node. This typically requires an OpenAI API key with access to the GPT-4o model.

  3. LangChain Nodes: Ensure you have the necessary LangChain n8n node package installed in your n8n environment, as this workflow heavily relies on the Agent, Memory, and Trigger nodes.

  4. Activation: Once credentials are set, activate the n8n workflow. The When chat message received n8n trigger will provide a webhook URL for external chat system integration.

Node Details

When chat message received (n8n trigger): The starting point for this n8n workflow, designed to receive text prompts from an integrated chat service, providing the session ID for memory context.
OpenAI Chat Model (n8n node): Serves as the large language model backend, configured specifically to use the high-performance gpt-4o model for both the Writing and Editing agents.
Window Buffer Memory (n8n node): Maintains conversational context for the agents using the user's sessionId, crucial for ensuring the recursive loop is aware of the previous context and revisions.
Writing Agent (n8n node): The creative engine. Its prompt dictates that it must incorporate previous edits passed through the recursive loop, demonstrating dynamic prompt engineering within the n8n workflow.
Editing Agent (n8n node): The quality control n8n agent. Its role is highly structured, requiring it to output a JSON object containing a 'complete' or 'incomplete' status and specific 'edits'.
Structured Output Parser (n8n node): Ensures the Editing Agent adheres to the required JSON schema (status and edits strings), making the feedback programmatically accessible to the subsequent n8n nodes.


  • If Status Complete (n8n node): The flow control mechanism. This critical n8n node determines whether the iteration is finished (status == 'complete') or if the workflow must loop back to the handle edits n8n node for another revision cycle.

Related n8n Workflows

Paid

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by

Student and Teacher | Designer and Builder | Helping Founders Flourish

Featured*