Introduction
Imagine talking to a helpful assistant that remembers what you said before and uses that to give better answers. Without memory, the assistant would forget everything after each question, making conversations confusing and less useful.
Jump into concepts and practice - no test required
Imagine chatting with a friend who remembers what you talked about yesterday and knows what you are trying to do right now. They keep notes in their mind and adjust their help based on your current situation and past talks.
┌───────────────┐ ┌───────────────┐
│ Agent │ │ Agent │
│ Memory │──────▶│ State │
│ (Past Info) │ │ (Current Info)│
└───────────────┘ └───────────────┘
▲ │
│ ▼
Stores past info Updates with new
from conversations inputs and decisionsagent memory in AI systems?=.== is comparison, := is assignment expression but not typical for state update, += adds values, not replaces.agent_memory = []
agent_state = {'mood': 'neutral'}
# Agent receives new info
new_info = 'happy'
# Update memory and state
agent_memory.append(new_info)
agent_state['mood'] = new_info
print(agent_memory, agent_state)
What will be the output?new_info ('happy') to agent_memory, so memory becomes ['happy'].agent_memory = []
agent_state = {'status': 'idle'}
new_data = 'active'
# Intended to update memory and state
agent_memory = agent_memory.append(new_data)
agent_state['status'] == new_data
print(agent_memory, agent_state)
What is the main error causing unexpected output?append() modifies list in place and returns None. Assigning it back sets agent_memory to None.== which compares but does not assign, so state remains unchanged.