Bird
Raised Fist0
Agentic AIml~20 mins

Short-term memory (conversation context) in Agentic AI - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Short-term Memory Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Short-term Memory in Conversation Context
Which of the following best describes the role of short-term memory in conversation context for an AI agent?
AIt temporarily holds recent conversation details to maintain context during interaction.
BIt stores all past conversations permanently for future reference.
CIt deletes all conversation data immediately after each user input.
DIt only stores user preferences without any conversation details.
Attempts:
2 left
💡 Hint
Think about how an AI keeps track of what was just said to respond properly.
Model Choice
intermediate
1:30remaining
Choosing a Model for Short-term Memory in Dialogue
Which model architecture is best suited for capturing short-term memory in conversation context?
AK-Nearest Neighbors (KNN) for classification
BRecurrent Neural Network (RNN) with gated units like LSTM or GRU
CConvolutional Neural Network (CNN) for image recognition
DFeedforward Neural Network without recurrence
Attempts:
2 left
💡 Hint
Consider models designed to handle sequences and remember recent inputs.
Metrics
advanced
2:00remaining
Evaluating Short-term Memory Effectiveness
Which metric would best help evaluate how well an AI model retains short-term conversation context?
ABLEU score measuring translation quality
BPerplexity measuring prediction uncertainty on next tokens
CRecall measuring how many relevant recent context tokens are used in response
DMean Squared Error measuring regression accuracy
Attempts:
2 left
💡 Hint
Think about measuring how much recent relevant information is captured in the output.
🔧 Debug
advanced
2:00remaining
Debugging Short-term Memory Loss in Conversation
An AI agent forgets the last user question immediately after responding. Which of the following is the most likely cause?
AThe AI is using a large context window.
BThe training data is too large.
CThe model uses attention mechanisms correctly.
DThe short-term memory buffer is cleared after each response.
Attempts:
2 left
💡 Hint
Consider what happens if the memory holding recent conversation is reset too soon.
Predict Output
expert
2:30remaining
Output of Short-term Memory Simulation Code
What is the output of this Python code simulating short-term memory with a fixed-size queue?
Agentic AI
from collections import deque

memory = deque(maxlen=3)
inputs = ['Hi', 'How are you?', 'What is AI?', 'Tell me a joke']
outputs = []
for inp in inputs:
    memory.append(inp)
    outputs.append(list(memory))
print(outputs)
A[['Hi'], ['Hi', 'How are you?'], ['Hi', 'How are you?', 'What is AI?'], ['How are you?', 'What is AI?', 'Tell me a joke']]
B[['Hi'], ['How are you?'], ['What is AI?'], ['Tell me a joke']]
C[['Hi'], ['Hi', 'How are you?'], ['Hi', 'How are you?', 'What is AI?'], ['Hi', 'How are you?', 'What is AI?', 'Tell me a joke']]
D[['Hi'], ['Hi', 'How are you?'], ['How are you?', 'What is AI?'], ['What is AI?', 'Tell me a joke']]
Attempts:
2 left
💡 Hint
Remember that deque with maxlen drops oldest items when full.

Practice

(1/5)
1. What is the main purpose of short-term memory in an AI conversation?
easy
A. To remember recent messages and keep the conversation connected
B. To store all past conversations permanently
C. To delete irrelevant messages immediately
D. To speed up the AI's processing by ignoring context

Solution

  1. Step 1: Understand short-term memory role

    Short-term memory stores recent conversation parts to keep context.
  2. Step 2: Compare options with this role

    Only To remember recent messages and keep the conversation connected matches this purpose; others describe different or incorrect functions.
  3. Final Answer:

    To remember recent messages and keep the conversation connected -> Option A
  4. Quick Check:

    Short-term memory = recent context [OK]
Hint: Short-term memory = recent messages stored [OK]
Common Mistakes:
  • Confusing short-term with long-term memory
  • Thinking it stores all past conversations
  • Believing it deletes messages immediately
2. Which of the following is the correct way to represent short-term memory storing the last 3 messages in Python?
easy
A. short_term_memory = messages[0]
B. short_term_memory = messages[:3]
C. short_term_memory = messages[3:]
D. short_term_memory = messages[-3:]

Solution

  1. Step 1: Understand Python list slicing for last 3 items

    Using messages[-3:] gets the last 3 messages from the list.
  2. Step 2: Check other options

    messages[:3] gets first 3, messages[3:] gets from 4th to end, messages[0] gets only first message.
  3. Final Answer:

    short_term_memory = messages[-3:] -> Option D
  4. Quick Check:

    Last 3 messages slice = messages[-3:] [OK]
Hint: Negative slice gets last items in list [OK]
Common Mistakes:
  • Using positive slice for last items
  • Selecting only one message instead of three
  • Confusing start and end indices
3. Given the code below, what will be the output of print(short_term_memory)?
messages = ['Hi', 'How are you?', 'I am fine', 'What about you?', 'Good!']
short_term_memory = messages[-2:]
print(short_term_memory)
medium
A. ['Hi', 'How are you?']
B. ['I am fine', 'What about you?']
C. ['What about you?', 'Good!']
D. ['Good!']

Solution

  1. Step 1: Understand list slicing with negative indices

    messages[-2:] selects the last two items from the list.
  2. Step 2: Identify last two messages

    The last two messages are 'What about you?' and 'Good!'.
  3. Final Answer:

    ['What about you?', 'Good!'] -> Option C
  4. Quick Check:

    messages[-2:] = last two messages [OK]
Hint: Negative slice picks last elements [OK]
Common Mistakes:
  • Selecting wrong slice range
  • Confusing order of messages
  • Printing only one message instead of two
4. The following code is intended to keep only the last 3 messages in short-term memory, but it has a bug. What is the bug?
messages = ['Hello', 'What is AI?', 'Tell me more', 'Thanks']
short_term_memory = messages[3:]
print(short_term_memory)
medium
A. It causes an IndexError
B. It keeps only the last message instead of last three
C. It keeps the first three messages instead of last three
D. It clears the list completely

Solution

  1. Step 1: Analyze the slice messages[3:]

    This slice starts at index 3 and goes to the end, so it keeps only the last message 'Thanks'.
  2. Step 2: Compare with intended behavior

    The goal was to keep last 3 messages, but this code keeps only one message.
  3. Final Answer:

    It keeps only the last message instead of last three -> Option B
  4. Quick Check:

    messages[3:] = last message only [OK]
Hint: Check slice start index carefully [OK]
Common Mistakes:
  • Assuming slice keeps last 3 messages
  • Expecting an error when none occurs
  • Confusing slice start and end
5. You want an AI agent to remember the last 4 messages in a conversation to keep context. The conversation messages are stored in a list called chat_history. Which code snippet correctly updates the short-term memory to always hold the last 4 messages after adding a new message new_msg?
hard
A. chat_history.append(new_msg) short_term_memory = chat_history[-4:]
B. short_term_memory = chat_history[:4] chat_history.append(new_msg)
C. short_term_memory = chat_history[-4:] chat_history.append(new_msg)
D. chat_history = chat_history[-4:] short_term_memory = new_msg

Solution

  1. Step 1: Add new message to chat_history first

    Appending new_msg to chat_history updates the conversation.
  2. Step 2: Slice last 4 messages for short-term memory

    Using chat_history[-4:] gets the last 4 messages including the new one.
  3. Final Answer:

    chat_history.append(new_msg) short_term_memory = chat_history[-4:] -> Option A
  4. Quick Check:

    Append then slice last 4 messages [OK]
Hint: Append first, then slice last 4 [OK]
Common Mistakes:
  • Slicing before appending new message
  • Assigning new message alone as memory
  • Slicing first 4 messages instead of last 4