Chat Memory
Langflow allows every chat message to be stored, and a single flow can have multiple memory sessions. This enables you to create separate memories for agents to store and recall information as needed.
In any project, as long as there are Chat being used, memories are always being stored by default. These are messages from a user to the AI or vice-versa.
To see and access this history of messages, Langflow features a component called Message history. It retrieves previous messages and outputs them in structured format or parsed.
To learn the basics about memory in Langflow, check out the Memory Chatbot starter example.
Memories can be visualized and managed directly from the Playground. You can edit and remove previous messages to inspect and validate the AI’s response behavior. You can remove or edit previous messages to get your models acting just right.
Modifying these memories will influence the behavior of the chatbot responses, as long as an agent uses them. Here you have the ability to remove or edit previous messages, allowing them to manipulate and explore how these changes affect model responses.
To modify chat memories, from the playground, click the Options menu of any session, and then select Message Logs.
Session ID​
Chat conversations store messages categorized by a Session ID
. A single flow can host multiple session IDs, and different flows can also share the same one.
The Chat Memory component also retrieves message histories by Session ID
, which users can change in the component's Controls pane.
By default, if the Session ID
value is empty, it is set to the same value as Flow ID
.
You can also display all messages stored across every flow and session by going to Settings > Messages.
Store chat memory in an external database​
Chat memory is retrieved from an external database or vector store using the Chat Memory component.
Chat memory is stored to an external database or vector store using the Store Message component.
The Chat Memories components provide access to their respective external databases as memory. This allows AIs to access external memory for persistence and context retention. For example, connect the Chat Memory component to an AstraDBChatMemory component to store the message history in an external Astra DB database.
This example stores and retrieves chat history from an AstraDBChatMemory component with Store Message and Chat Memory components.
Prerequisites​
- An OpenAI API key
- An Astra DB vector database with:
- Application Token
- API Endpoint
Connect the chat memory component to an external database​
- Load the Memory Chatbot starter project. This starter project extends the basic prompting flow to include a chat memory component.
- Add the Store Message component to the flow. The Store message component stores messages in the external database.
- Add the AstraDBChatMemory Component to the flow. The Astra DB Chat Memory component stores and retrieves messages from Astra DB.
- Configure the AstraDBChatMemory component with your AstraDB instance details.
- In the Astra DB Application Token field, add your Astra token. (
AstraCS:...
) - In the API Endpoint field, add your Astra database's endpoint. (for example,
https://12adb-bc-5378c845f05a6-e0a12-bd889b4-us-east-2.apps.astra.datastax.com
)
- In the Astra DB Application Token field, add your Astra token. (
- Connect the AstraDBChatMemory component output to the external memory inputs of the Chat Memory and Store Message components.
- Link the Chat Output component to the input of the Store Message component.
Your completed flow should look like this:
- In Langflow, create message traffic by running a flow.
- Inspect your Astra database's tables and activity. You will see new tables and traffic created.