02. ConversationBufferWindowMemory
ConversationBufferWindowMemory
ConversationBufferWindowMemory Over time, we maintain a mutual list of conversations.
At this time, ConversationBufferWindowMemory Not all conversation use Recent K Use only for mutual use.
This can be useful for maintaining the most recent mutual sliding window so that the buffer does not get too big.
Copy
from langchain.memory import ConversationBufferWindowMemory
memory = ConversationBufferWindowMemory(k=2, return_messages=True)
memory.save_context(
inputs={
"human": "Hello, I would like to open a bank account remotely. How do I get started?"
},
outputs={
"ai": "Hello! I am glad that you would like to open an account. First, please prepare your ID for verification?"
},
)
memory.save_context(
inputs={"human": "Yes, I have my ID ready. What should I do now?"},
outputs={
"ai": "Thank you. Please upload a clear photo of the front and back of your ID. We will then proceed with the identity verification process."
},
)
memory.save_context(
inputs={"human": "I uploaded a photo. How do I verify my identity?"},
outputs={
"ai": "Thank you. Please upload a clear photo of the front and back of your ID. We will then proceed with the identity verification process."
},
)
memory.save_context(
inputs={"human": "I uploaded a photo. How do I verify my identity?"},
outputs={
"ai": "We have confirmed the photo you uploaded. Now, please proceed with identity verification via mobile phone. Please enter the verification number sent to you via text message."
},
)
memory.save_context(
inputs={"human": "I entered the verification number. How do I open an account now?"},
outputs={
"ai": "Your identity verification is complete. Now, please select the type of account you want and enter the required information. You can select the type of deposit, currency, etc."
},
)
memory.save_context(
inputs={"human": "I have completed all the procedures. Is the account opened?"},
outputs={
"ai": "Yes, your account has been opened. Your account number and related information have been sent to the email address you registered. Please contact us at any time if you need further assistance. Thank you!"
},
)Check the conversation record Last 2 You can confirm that only the message of is returned.
Copy
Copy
Last updated