1. Learn
  2. /
  3. Courses
  4. /
  5. Designing Agentic Systems with LangChain

Connected

Exercise

Enable multi-turn conversation with memory

You are just about ready to share your chatbot update with the school administration! For students to have a smooth learning experience, it's important to enable them to ask follow-up questions. This way, if any information is missing from the chatbot's first answer, the students can modify their questions by having a conversation. You'll now adapt your chatbot's streaming function to enable multiple turns, printing both the user's query as well as the chatbot's answer. To enable memory, LangGraph will send the full conversation to the LLM when follow-up questions are asked. To start with, your config parameters have already been set for one user:

config = {"configurable": {"thread_id": "1"}}

Instructions

100 XP
  • For each turn, start by printing the user's query from the queries list.
  • Iterate through msg and metadata using app.stream(), passing query as the content of HumanMessage along with config, and join the msg.content values.
  • To extract the chatbot's responses, print msg.content while excluding any msg labeled HumanMessage, adding a new line before the next query.