Memory Chatbot
This flow extends the basic prompting flow to include a chat memory. This makes the AI remember previous user inputs.
Prerequisites
Create the memory chatbot flow
- From the Langflow dashboard, click New Flow.
- Select Memory Chatbot.
- The Memory Chatbot flow is created.
This flow uses the same components as the Basic Prompting one, but extends it with a Chat Memory component. This component retrieves previous messages and sends them to the Prompt component to fill a part of the Template with context.
By clicking the template, you'll see the prompt editor like below:
This gives the OpenAI component a memory of previous chat messages.
Run the memory chatbot flow
- Open the Playground.
- Type multiple questions. In the Memories tab, your queries are logged in order. Up to 100 queries are stored by default. Try telling the AI your name and asking
What is my name?
on a second message, orWhat is the first subject I asked you about?
to validate that previous knowledge is taking effect.
Check and adjust advanced parameters by opening the Advanced Settings of the Chat Memory component.
Use Session ID with the memory chatbot flow
SessionID
is a unique identifier in Langflow that stores conversation sessions between the AI and a user. A SessionID
is created when a conversation is initiated, and then associated with all subsequent messages during that session.
In the Memory Chatbot flow you created, the Chat Memory component references past interactions by Session ID. You can demonstrate this by modifying the Session ID value to switch between conversation histories.
- In the Session ID field of the Chat Memory and Chat Input components, add a Session ID value like
MySessionID
. - Now, once you send a new message the Playground, you should have a new memory created on the Memories tab.
- Notice how your conversation is being stored in different memory sessions.
Every chat component in Langflow comes with a SessionID
. It defaults to the flow ID. Explore how changing it affects what the AI remembers.
Learn more about memories in the Chat Memory section.