AI Content Generator with Conversation History and Sheets Memory - n8n Workflow

Build an advanced n8n workflow for AI blog writing and editing. This powerful n8n automation uses LangChain Agents, Google Sheets for memory, and the OpenAI n8n node to generate context-aware content.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Content managers and marketing teams needing scalable AI writing solutions.

  • Developers looking for advanced examples of using LangChain Agents within an n8n workflow.

  • Users who need context-aware AI generation tracked across multiple sessions.

  • Anyone seeking robust n8n templates for integrating AI and database logic.

Overview

This comprehensive n8n workflow creates a powerful, persistent AI agent capable of writing or editing blog content while tracking its historical actions. Unlike simple prompts, this n8n automation uses Google Sheets as external memory. The core value lies in its ability to count the number of edits or writings performed for a specific user session ID, allowing you to implement flow control (e.g., limiting the number of revisions). This is a highly technical example of an n8n template utilizing advanced n8n node features like LangChain Tools (sub-workflows) and structured output parsing. Using this n8n workflow ensures context persistence and scalable data logging for all your AI interactions.

How it Works

The process begins with the Ask about blog topic n8n trigger, which initiates the chat interaction.


  1. Prompt Generation (Code n8n node): The Choose to Write or Edit Blog n8n node determines if the input is a new topic (Write) or existing text (Reword/Edit) based on the input data structure. It dynamically constructs the systemprompt and userprompt, explicitly instructing the Agent to use a dedicated tool to fetch the current session count.

  2. AI Agent Execution: The Blog Writer & Editor Agent n8n node takes the prompts and orchestrates the AI process. It uses the OpenAI Chat Model2 (GPT-4/5) for generation and the Simple Memory n8n node for short-term context.

  3. Memory Lookup (Google Tool n8n node): The Agent calls the embedded google n8n tool, passing only the session ID. This sub-workflow executes a memory lookup:

The When Executed by Another Workflow n8n trigger receives the session ID.
It calls the Get History Google Sheets n8n node to retrieve all sheet rows.
A Filter n8n node isolates only the rows matching the current session ID.
The Summarize1 n8n node counts these rows, returning the session history count to the Agent.

  1. Structured Output: The Agent uses the Structured Output Parser n8n node to guarantee the response is valid JSON, including the final blog body and the session history count.

  2. History Logging: The n8n History Google Sheets n8n node appends the structured results (session, Rows, output) to the memory sheet.

  3. Flow Control: The final Check if Ran 4+ times If n8n node evaluates the returned row count. If the count exceeds 3, the flow branches (e.g., to stop or notify). This demonstrates powerful control within the n8n workflow based on historical context.

Installation Guide

To deploy this powerful n8n template, follow these steps:


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

  2. Configure OpenAI Credentials: You must set up a new credential for the OpenAI Chat Model2 n8n node. Ensure your API key is configured with billing enabled, as this uses advanced models.

  3. Prepare Google Sheet Memory: Create a Google Sheet with the column names: session, Rows, and output. A sample sheet is often provided in the sticky notes.

  4. Configure Google Sheets n8n node: Update the credentials for both the main n8n History Google Sheets n8n node and the embedded Get History n8n node within the google tool. Select your specific spreadsheet ID and sheet name for both connections.

  5. Activate the Trigger: Ensure the Ask about blog topic LangChain Chat n8n trigger is active to start the automation.

Node Details

Ask about blog topic (LangChain Chat Trigger): Acts as the entry point or n8n trigger for the automation. It captures user input and session ID to maintain conversational context.
Choose to Write or Edit Blog (Code n8n node): This crucial n8n node acts as a prompt engineer. It dynamically generates tailored systemprompt and userprompt based on whether the task is a new write or an edit. It explicitly instructs the AI to use the attached google tool.
Blog Writer & Editor (LangChain Agent n8n node): The core intelligence of the n8n workflow. It utilizes GPT-4/5 via the OpenAI Chat Model2 and manages memory (Simple Memory) and tools (google). It is configured to enforce output structure using the Structured Output Parser n8n node.
google (LangChain Tool n8n node/Sub-workflow): This embedded n8n workflow executes the memory lookup logic. It uses the Google Sheets n8n node to fetch session history, the Filter n8n node to match the session ID, and the Summarize n8n node to count the results.
n8n History (Google Sheets n8n node): This n8n node is responsible for persistently storing the output from the AI agent, including the session ID and the final blog content, serving as the knowledge base for the next iteration.
Check if Ran 4+ times (If n8n node): A conditional n8n node that checks the returned row count (Rows > 3) to implement limits or branching logic based on the history stored in Google Sheets.

Related n8n Workflows

Free

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

Professional services consultant with over 10 years of experience solving complex business problems across industries. I specialize in n8n and process automation—designing custom workflows that integrate tools like Google Calendar, Airtable, GPT, and internal systems. Whether you need to automate scheduling, sync data, or streamline operations, I build solutions that save time and drive results.

Featured*