Skip to main content

Run a multi-session chat agent with OpenAI and data table memory

Workflow preview

Workflow preview
100%
Run a multi-session chat agent with OpenAI and data table memory preview
Open on n8n.io

1. Workflow Overview

Quick overview This workflow powers an OpenAI based chat agent in n8n that persists long term conversation memory in an n8n Data Table by session ID, optionally recalling past context via name/emai...

Best for

  • Support Chatbot automation workflows
  • AI Chatbot automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.memorybufferwindow, @n8n/n8n-nodes-langchain.chattrigger, n8n-nodes-base.datatable, n8n-nodes-base.if, n8n-nodes-base.set, @n8n/n8n-nodes-langchain.lmchatopenai, n8n-nodes-base.datatabletool

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Ted Chan.

Original n8n.io source

1.1 Workflow description

Title
Run a multi-session chat agent with OpenAI and data table memory
Workflow name
Run a multi-session chat agent with OpenAI and data table memory

Quick overview

This workflow powers an OpenAI-based chat agent in n8n that persists long-term conversation memory in an n8n Data Table by session ID, optionally recalling past context via name/email lookups while enforcing an identity-verification flow.

How it works

  1. Receives a chat message via the n8n Chat Trigger and uses the provided sessionId to identify the conversation.
  2. Searches the n8n Data Table for an existing row with the same session_id and either loads the saved fields or creates a new session record.
  3. Uses an OpenAI chat model with a sliding window memory (last 10 turns) to generate the assistant response based on the user message and any loaded session context.
  4. Updates the current session’s Data Table row with newly captured details (for example name, email, company, interests, topics, and chat history) according to the agent’s rules.
  5. When the user provides a name or email, queries the Data Table for past sessions via the lookup-by-name and lookup-by-email tools to support a privacy-preserving “welcome back” flow.

Setup

  1. Create or select an n8n Data Table (for example, chat_session_data) with columns that match the workflow fields you want to store (such as session_id, first_name, last_name, user_id/email, company, interested_in, last_topic, and chat_history).
  2. Add an OpenAI API credential and select the model in the OpenAI Chat Model node.
  3. Update the Data Table ID references in the Data Table and Data Table Tool nodes to point to your table.
  4. Activate the Chat Trigger and use the generated chat/webhook endpoint in your chat entry point (or test from n8n’s chat UI).
  5. Set the workflow timezone in n8n settings to ensure timestamps and session timing align with your locale.

Requirements

  • OpenAI GPT-5.2

Customization

  • Change the agent name, company name, and role description in the system prompt to match your own use case
  • Add or remove data table fields to capture different information relevant to your business domain
  • Swap OpenAI for any other LLM that supports tool calling (Anthropic Claude, Google Gemini, etc.)
  • Replace email as the identity verification key with phone number or membership ID by updating the lookup tool filters
  • Extend to additional chat channels such as WhatsApp or Telegram by adding a channel-specific trigger and reusing the same data table
  • Write a schedule triggered workflow to clean-up old session records based on updateAt date, or just manually delete

Additional info

Works on self-hosted and cloud

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 3.1

Block 2 - Simple Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.4

Block 3 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.4

Block 4 - Search session_id

Type / Role
n8n-nodes-base.dataTable - dataTable
Config choices
Version 1.1

Block 5 - Found session_id

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.3

Block 6 - New session record

Type / Role
n8n-nodes-base.dataTable - dataTable
Config choices
Version 1.1

Block 7 - Load past session data

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 8 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.3

Block 9 - lookup_past_session_by_email

Type / Role
n8n-nodes-base.dataTableTool - dataTableTool
Config choices
Version 1.1

Block 10 - update_chat_session_record

Type / Role
n8n-nodes-base.dataTableTool - dataTableTool
Config choices
Version 1.1

Block 11 - lookup_past_session_by_name

Type / Role
n8n-nodes-base.dataTableTool - dataTableTool
Config choices
Version 1.1

Block 12 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 13 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 14 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 15 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow Run a multi-session chat agent with OpenAI and data table memory
Complexity advanced
Nodes 15
Categories Support Chatbot, AI Chatbot
Author Ted Chan
Published 01 Jun 2026

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/16052/16052.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Run a multi-session chat agent with OpenAI and data table memory do?

Quick overview This workflow powers an OpenAI based chat agent in n8n that persists long term conversation memory in an n8n Data Table by session ID, optionally recalling past context via name/emai...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Support Chatbot, AI Chatbot use case.