How to maintain conversation context/memory with AI Agent for follow-up questions?

Hi n8n community,

I’m building a workflow that acts as a smart chatbot for construction workers to submit their daily reports via Telegram. The goal is for the AI to collect 5 specific pieces of information in a natural conversation.

My Workflow Setup:

  1. Telegram Trigger: Receives a message from a worker.
  2. AI Agent (using Gemini): Analyzes the message. Its system prompt tells it to check for 5 data points (hours worked, breaks, tasks today, tasks tomorrow, and delays).
  3. The Logic (using IF node):
    If the AI has all 5 pieces of information, it it continues the workflow.
    If information is missing, it requests more information from the construction worker via telegram

The Problem: “Amnesia” on the second interaction

The workflow works perfectly if the user provides all the information in the first message. The problem occurs during the follow-up.

This is what happens

  1. User sends an initial message, but forgets one detail. For example: “I worked 8 hours, had a 30-minute break, painted the walls, and tomorrow I’ll do the floors.” (The “delays” part is missing).
  2. The AI Agent correctly identifies this. It outputs taskCompleted: false and the question “Thanks! And were there any delays or issues today?”. My workflow successfully sends this question to the user on Telegram.
  3. The user replies to the bot with only the missing information: “No, everything went smoothly.”
  4. Here is the issue: This reply triggers a new workflow execution. The AI Agent now only receives the text “No, everything went smoothly.” It has no memory of the first message (with the hours, tasks, etc.). It gets confused and asks for all the other information, as it can’t combine the old and new information.

My Question:

What is the best practice in n8n to handle this kind of conversational context? How can I make my AI Agent “remember” the previous messages from the same user within the same session?

I want the AI Agent, upon receiving the second message, to be able to access the context of the first message, combine the information, and then conclude that the task is complete.

Thanks so much in advance for your help

I just tried to build something similar to test, here is what worked for me.

With this workflow, this is the conversaion I had in Telegram with the bot:

jabbson, [2025-06-25 2:48 PM]
I worked 8 hours, had a 30-minute break, painted the walls, and tomorrow I’ll do the floors.

n8n-bot, [2025-06-25 2:48 PM]
Thanks! Could you also tell me: any delays encountered?

jabbson, [2025-06-25 2:48 PM]
no, there were no delays

n8n-bot, [2025-06-25 2:48 PM]
Thanks for your report!

and this is what the google sheet looks like after this conversation:
image

Hope this helps.

The simplest approach that works reliably is using the Window Buffer Memory node connected to your AI Agent.
Set the session ID to something unique per user or conversation thread, either a user ID or a timestamp based key.
This keeps memory scoped per session so agents do not bleed context between different users. If you need longer memory across sessions, write a summary of each session to a Postgres or Airtable node and inject it back into the system prompt on the next conversation start.