🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.

Project 9: Travel Recommendation Bot

AI Engineer

Builds on these lessons

Current Task

Objective

ConversationBufferWindowMemory keeps only the last k exchanges, bounding memory size for long-running conversations.

Task: create a windowed memory with k=2, add three turns, and print how many messages remain.

index.py
from langchain.memory import ConversationBufferWindowMemory memory = ConversationBufferWindowMemory(k=2) memory.save_context({"input": "Best time to visit Kyoto?"}, {"output": "Spring, for cherry blossoms."}) memory.save_context({"input": "What about Bali?"}, {"output": "April to October is dry season."}) memory.save_context({"input": "And Iceland?"}, {"output": "June to August for midnight sun."}) print(len(memory.chat_memory.messages))

* Hint: Correct characters turn green, incorrect ones turn red.

Live Preview
🖼️

Verify your code to see the preview