Langflow Memory Chatbot: Message History and Sessions

9 min read

Build a memory chatbot in Langflow: Agent built-in memory, Message History, session IDs, external chat memory, and memory bases (SQLite by default since 1.13) for long-term recall.

A memory chatbot in Langflow keeps earlier messages of a session and feeds them back to the model. The Agent component does this by default, loading up to 100 past messages for the same session_id. For plain model flows, the Message History component retrieves and stores chat history. Memory bases (added in Langflow 1.10) add semantic recall across sessions.

The details below follow the Langflow memory docs for the 1.13 release line (1.13.0, 22 October 2026), its release notes and the Langflow source code. If you’re upgrading, the 1.13 changes matter most for memory bases.

What is a Langflow memory chatbot?

A Langflow memory chatbot is a flow that stores each chat message in Langflow’s database, grouped by session ID, and loads recent messages from that session into the next prompt. The Agent component handles this automatically; the Message History component does it explicitly in flows built around a Language Model component.

Langflow gives you three levels of memory:

MechanismWhat it recallsScopeAdded
Agent built-in memoryLast N messages (default 100)One sessionDefault for Agent
Message History componentLast N messages, filterable, Langflow or external storageOne session, or any session you nameEarlier releases
Memory baseMost relevant past messages by vector similarityCurrent session by default, or all sessions1.10 (June 2026)

The first two are short-term memory: a rolling window of recent messages. The third is closer to long-term memory. Our page on short-term vs long-term memory in agentic AI explains the difference.

Option 1: the Agent component’s built-in memory

The Agent docs say Langflow agents “have built-in chat memory that is enabled by default.” Each session gets its own context window, and the agent reads earlier messages with the same session_id.

The advanced setting Number of Chat History Messages controls how many past messages load. Its default in the Agent component code is 100; set it to 0 to turn memory off. For most chatbots, this is all you need. You only add a Message History component when you want external storage or finer control over filtering and order.

Option 2: the Memory Chatbot pattern with Message History

When you use a Language Model component instead of an Agent, wire memory yourself. The Message History docs give this layout:

  1. Add a Message History component in Retrieve mode at the start of the flow.
  2. Add a Prompt Template with a {memory} variable, and connect Message History’s output to it.
  3. Send the Prompt Template’s output to the Language Model’s System Message input.
  4. Connect Chat Input to the Language Model, and the Language Model to Chat Output.
  5. Add a second Message History component in Store mode at the end, fed by Chat Output.

A flow that reads and writes history needs both components; one component does one mode.

Retrieve mode settings and defaults:

  • Number of Messages: 100.
  • Order: Ascending.
  • Sender Type: Machine and User (or one of them).
  • Session ID: empty means the current run’s session.
  • Template: formats each message, with keys like {sender} and {text}.
  • External Memory: empty means Langflow storage.

The output comes as a Message (history as text for the prompt) or a DataFrame (for analysis).

External chat memory

Connect a provider component to Message History’s External Memory input to keep history outside Langflow. The docs name Redis Chat Memory, Mem0 Chat Memory and Cassandra Chat Memory. Use one when several Langflow instances serve the same users, or when chat data must live in a database you already run. Mem0 also extracts facts from conversations, which is a step toward user memory rather than raw history; see what Mem0 is for how it works.

Session IDs: keeping users apart

Memory is grouped by session_id. The docs warn that the default session ID is the flow ID, so every chat on a flow shares one history unless you set IDs. In production, pass a session ID per user or per conversation when you call the flow:

 1import os
 2
 3import requests
 4
 5BASE = "http://localhost:7860"
 6FLOW_ID = "your-flow-id"
 7HEADERS = {"x-api-key": os.environ["LANGFLOW_API_KEY"]}
 8
 9
10def chat(message: str, session_id: str) -> str:
11    resp = requests.post(
12        f"{BASE}/api/v1/run/{FLOW_ID}",
13        headers=HEADERS,
14        json={
15            "input_value": message,
16            "input_type": "chat",
17            "output_type": "chat",
18            "session_id": session_id,  # overrides component settings
19        },
20        timeout=120,
21    )
22    resp.raise_for_status()
23    return resp.json()["outputs"][0]["outputs"][0]["results"]["message"]["text"]
24
25
26chat("Hi, I'm Dana and I'm vegetarian.", session_id="user-dana")
27print(chat("Suggest a dinner for me.", session_id="user-dana"))  # remembers
28
29# Read or clear one session's stored messages
30msgs = requests.get(f"{BASE}/api/v1/monitor/messages",
31                    headers=HEADERS, params={"session_id": "user-dana"}, timeout=30).json()
32requests.delete(f"{BASE}/api/v1/monitor/messages/session/user-dana", headers=HEADERS, timeout=30)

The session ID in the API request takes precedence over whatever the components set. Derive it on your server from the logged-in user. Anyone who can guess another user’s session ID can read their history through the flow.

Per-user memory behind a login gateway (Langflow 1.12)

Langflow 1.12 added a safer option for the v2 workflow API (/api/v2/workflows), from PR #14443. A gateway that has already logged the user in puts an opaque user ID in a request header. Langflow then keys memory by user and session together (stored as <user id>::<session_id>), so two users who send the same session ID still get separate histories, and one user can keep several threads open.

SettingDefaultWhat it does
LANGFLOW_SERVING_END_USER_HEADERunsetName of the header holding the user ID, such as X-End-User-Id. Unset means the feature is off.
LANGFLOW_SERVING_TRUST_PROXY_HEADERSfalseThe header is read only when this is true.
LANGFLOW_SERVING_END_USER_REQUIREDfalseWhen true, requests without a user ID get a 401.

Two things catch people out. First, a request with no user ID runs in a random, throwaway session and Langflow writes none of its messages, so it has no memory at all. With the header name set but trust left at false, the header is ignored and every request is like that. Second, this covers only Langflow’s own database: an external chat memory you wire in (Redis, Mem0) still stores what it’s sent. Turn trust on only when the gateway overwrites the header and is the only thing that can reach Langflow; otherwise any caller can claim to be any user. With the feature off, Langflow behaves exactly as before.

Where Langflow stores chat memory

Chat Input and Chat Output write every message to Langflow’s application database:

  • Default: SQLite, langflow.db for the open-source server or database.db for Langflow Desktop.
  • PostgreSQL: set LANGFLOW_DATABASE_URL. Use this for anything multi-user or multi-instance.
  • No storage: LANGFLOW_USE_NOOP_DATABASE=True stores nothing, which is handy for tests and means no memory at all.

Messages accumulate forever by default, so plan retention: delete old sessions through the monitor API, or keep chat history in an external store with its own TTL.

Option 3: memory bases for long-term recall

Langflow 1.10 added memory bases. In 1.12, the built-in Memory Chatbot starter template uses them: Chat Input feeds an Agent, a Memory Base component is wired in as the agent’s tool, and the Agent feeds Chat Output. A memory base turns a flow’s chat messages into vectors, so an agent can retrieve past conversations by meaning instead of by recency. Unlike a knowledge base, which you fill with files, it fills itself from the flow’s message table.

How it works:

  1. Create one under Memories in the sidebar: pick a name, an embedding model and a vector database. The database can’t be changed later.
  2. Each flow run’s messages count toward an ingestion threshold. When enough unprocessed runs pile up, a background job embeds them. Auto-capture is on by default.
  3. Optionally turn on LLM preprocessing: a model distills each batch into a summary before embedding. If its reply contains the kill phrase (default NO_INGEST), the batch is skipped.
  4. Add the Memory Base component to a flow in Tool Mode and connect its Toolset to an Agent’s Tools input.

Filter by Session is on by default, so the agent searches only the current session’s memories. Turn it off to search across all ingested sessions, which is what you want for “remember this user next week,” provided your session IDs map to users. Since 1.13 the default store is local SQLite with sqlite-vec (vectors under ~/.langflow/knowledge_bases unless you set LANGFLOW_KNOWLEDGE_BASES_DIR); OpenSearch and Postgres pgvector are the other options. The docs say to keep SQLite storage on local disk on one host, so use pgvector or OpenSearch for multi-instance setups. A memory base attaches to one flow.

This is retrieval over past messages or summaries. It doesn’t resolve contradictions or track when a fact stopped being true. For a deeper look at those problems, see the AI agent memory guide.

If you need that, connect a dedicated memory server as a tool. Langflow’s MCP Tools component can point an Agent at Hindsight’s MCP endpoint (one per memory bank, such as one per user), which exposes retain, recall and reflect. Hindsight extracts facts with dates, merges them into observations over time, and leads Mem0 on the long-history BEAM benchmark (64.1 vs 48.6 at 10M tokens, vendor-run). There’s no native Langflow component, and its README says it may be overkill for simple flows, so stay with memory bases unless users return over weeks or months. If your low-code stack is n8n rather than Langflow, the n8n agent memory guide covers the same choices there.

What changed for memory in Langflow 1.13

Langflow 1.13.0 (22 October 2026) moved memory bases and knowledge bases from Chroma to SQLite, and fixed several memory base bugs. Chat history in the message table is unchanged. From the 1.13.0 release notes and the linked pull requests:

Change in 1.13.0What it means for a memory chatbot
Local Chroma replaced by SQLite with sqlite-vec (PR #15509)New memory bases use SQLite. Langflow no longer installs Chroma. On a supported single-host install, existing local Chroma bases migrate in the background on first startup, keeping their vectors with no new embedding calls; interrupted migrations resume on restart. pgvector and OpenSearch are unchanged.
Memory Base component fixes (PR #15864)Clicking Update on a reopened Memory Base component no longer fails with “flow_id is not available”; ingestion no longer aborts at random with “Memory source messages changed during preprocessing”; LLM preprocessing works with OpenAI reasoning models that reject temperature.
Erasing one end user’s memory works on SQLite memory bases (PR #15674)The erase deletes that person’s chunks from the store and updates the stored counts. The bug was caught on the 1.13 branch, before release.
Memory bases cleaned up when a flow is deleted (PR #14915)Deleting a flow now deletes its memory bases and their remote vector collections too. Before, a flow whose memory base held messages could fail to delete, or leave an orphaned memory base.
The editor no longer freezes on flows with thousands of chat sessions (PR #15579)Flows called through the API with a session ID per user or request pile up sessions; one production flow in the PR reached about 10,000.

If you ran memory bases on local Chroma, check after upgrading that each one shows Ready before you rely on recall: during migration the base isn’t available to the agent, while chat history and other flows keep working.