Memory Chatbot

Build a Memory Chatbot flow for a chatbot application using the Message history component.

This flow extends the Basic prompting flow with a Message history component that stores previous chat messages and uses them to provide context for the current conversation.

The Message history component is named Chat Memory prior to Langflow version 1.1.0.

Open Langflow and start a new project

  1. In the Astra Portal header, switch your active app from Astra DB Serverless to Langflow.

  2. In Langflow, click New Project, and then select the Memory Chatbot project.

This opens a starter project with the necessary components to run a chatbot application using Message history.

Memory Chatbot flow

starter flow memory chatbot

The Memory Chatbot flow consists of these components:

  • The Chat Input component accepts user input to the chat.

  • The Prompt component combines the user input with a user-defined prompt.

  • The OpenAI model component sends the user input and prompt to the OpenAI API and receives a response.

  • The Chat Output component prints the flow’s output to the chat.

  • The Message History component retrieves previous messages and sends them to the Prompt component to fill the template with context. The Message history component was named Chat memory prior to Langflow version 1.1.0.

This flow adds a Message history component to the Basic Prompting flow. This component retrieves previous messages and sends them to the Prompt component to fill a part of the Template with context.

To examine the template, click the Template field in the Prompt component. The Prompt tells the OpenAI model component how to respond to input.

You are a helpful assistant that answers questions.
Use markdown to format your answer, properly embedding images and urls.
History:
{memory}

The {memory} code in the prompt creates a new input port in the Prompt component called memory. The Message history component connected to this port stores chat messages from the Playground.

This provides the OpenAI component with a memory of previous chat messages.

Run the Memory Chatbot flow

  1. Add your credentials to the Open AI component. The fastest and most secure way to add credentials is with Langflow’s Global Variables.

    1. Click settings Settings, and then click language Global Variables.

    2. Click Add New.

    3. Name your variable. Paste your API key in the Value field.

    4. In the Apply To Fields field, select the field you want to globally apply this variable to.

    5. Click Save Variable.

  2. Open the Playground.

  3. Type multiple questions. For example, try entering this conversation:

    Hi, my name is Luca.
    Please tell me about PostgreSQL.
    What is my name?
    What is the second subject I asked you about?

    The chatbot remembers your name and previous questions.

  4. To view the Message Logs pane, click more_horiz, and then click Message Logs. The Message Logs pane displays all previous messages, with each conversation sorted by session_id.

messages logs

Use Session ID with the memory chatbot flow

session_id is a unique identifier in Langflow that stores conversation sessions between the AI and a user. A session_id 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 Message history component references past interactions by Session ID. You can demonstrate this by modifying the Session ID value to switch between conversation histories.

  1. In the Session ID field of the Message history component, add a Session ID value like MySessionID.

  2. When you send a new message in the Playground, a new chat session called MySessionID is also created in the Playground, with a conversation history that is separate from the default session.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2025 DataStax | Privacy policy | Terms of use | Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com