Introduction
When chatting with an AI, it can be frustrating if it forgets what you said earlier. Keeping track of past messages helps the AI understand the flow and respond better.
Jump into concepts and practice - no test required
Imagine talking to a friend who takes notes during your chat. They remember what you said earlier and use that to keep the conversation smooth and meaningful.
┌─────────────────────────────┐
│ Conversation Input │
└─────────────┬───────────────┘
│
┌───────▼────────┐
│ Memory Store │
└───────┬────────┘
│
┌───────▼────────┐
│ AI Response │
└────────────────┘append() to add an item at the end.append() is the correct method to add a new message.memory = ['Hi', 'How are you?'] new_message = 'I am fine' memory.append(new_message) print(len(memory))
memory = [] new_message = 'Hello' memory.add(new_message)
add() method; this causes an AttributeError.append() to add an item to a list, so replace add() with append().append() to add the new message at the end.memory[-3:] keeps the last 3 items, removing older ones.