Chat Memory
Chat Memory is a simple tool that lets you pull past conversation messages into your workflow. Whether you want to review what was said, feed the history into another AI component, or just keep a record, this component makes it easy to fetch the data you need.
How it Works
When you drop the Chat Memory component into your dashboard, it looks for chat history in one of two places:
- External Memory – If you connect a memory object (anything that implements
BaseChatMessageHistory
), the component will read messages directly from that source. - Langflow Tables – If no external memory is supplied, it pulls messages from the built‑in Langflow storage that keeps all chat logs.
You can tell the component which messages to bring back by setting a few options:
- Sender Type – Pick “AI”, “User”, or “Machine and User” to filter messages by who sent them.
- Sender Name – Narrow the results to a specific user or bot name.
- Session ID / Conversation ID – Target a particular chat session or conversation thread.
- Number of Messages – Decide how many recent messages you want (default 100).
- Order – Choose whether the oldest or newest messages come first.
- Template – If you want the messages as plain text, you can format them with a template that uses placeholders like
{text}
or{sender}
.
The component then returns the messages in one of three ways:
- Messages (Data) – A structured list of message objects that can be fed into other components.
- Messages (Text) – A single text block that concatenates all selected messages using your template.
- Memory – A ready‑to‑use LangChain memory object that can be passed to other AI components.
Inputs
- External Memory – Retrieve messages from an external memory. If empty, it will use the Langflow tables.
- Conversation ID – Conversation ID of the chat history.
- Number of Messages – Number of messages to retrieve.
- Order – Order of the messages.
- Sender Type – Filter by sender type.
- Sender Name – Filter by sender name.
- Session ID – Session ID of the chat history.
- Template – The template to use for formatting the data. It can contain the keys
{text}
,{sender}
or any other key in the message data.
Outputs
- Messages (Data) – Type:
Data
(method:retrieve_messages
).
A list of message objects that include the text, sender, and other metadata. - Messages (Text) – Type:
Message
(method:retrieve_messages_as_text
).
A single text string that combines all selected messages according to the template. - Memory – Type:
BaseChatMemory
(method:build_lc_memory
).
A LangChain memory instance that can be reused by other components.
Usage Example
-
Pull the last 20 user messages
- Set Number of Messages to
20
. - Set Sender Type to
User
. - Leave External Memory empty to use Langflow tables.
- Connect the Messages (Data) output to a component that needs the raw message objects.
- Set Number of Messages to
-
Create a summary of the conversation
- Set Template to
{sender}: {text}
. - Connect the Messages (Text) output to a summarization component.
- The summarizer will receive a single string that lists each message with its sender.
- Set Template to
Related Components
- Chat – Sends messages to an AI model and stores the conversation.
- Summarize – Generates a concise summary of a block of text.
- Filter Messages – Further refines a list of messages based on custom criteria.
Tips and Best Practices
- Use Session ID and Conversation ID when you have multiple parallel chats; this keeps the history tidy.
- Keep Number of Messages reasonable (e.g., 50–100) to avoid performance hits on large histories.
- If you only need a quick preview, choose Messages (Text) and a simple template to avoid handling complex data structures.
- When connecting to an external memory, make sure the memory object is properly initialized and has the correct
session_id
andconversation_id
set.
Security Considerations
- The component only reads data; it does not modify or delete any messages.
- If you use an external memory that stores sensitive information, ensure that the memory object is secured and that access is restricted to authorized users.
- The template feature can expose message content; avoid using it in public dashboards where sensitive data might be displayed.