0
0
Agentic AIml~10 mins

Short-term memory (conversation context) in Agentic AI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize a short-term memory buffer as an empty list.

Agentic AI
short_term_memory = [1]
Drag options to blanks, or click blank then click option'
ANone
B0
C{}
D[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces {} which creates a dictionary instead of a list.
Setting the memory to None or 0 which cannot hold conversation data.
2fill in blank
medium

Complete the code to add a new user message to the short-term memory list.

Agentic AI
short_term_memory.[1](user_message)
Drag options to blanks, or click blank then click option'
Apop
Binsert
Cappend
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using insert without specifying an index.
Using remove or pop which delete items instead of adding.
3fill in blank
hard

Fix the error in the code to retrieve the last message from short-term memory safely.

Agentic AI
last_message = short_term_memory[1] if short_term_memory else None
Drag options to blanks, or click blank then click option'
A[-1]
B[-2]
C[0]
D[1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 0 which gets the first message, not the last.
Using index 1 or -2 which may cause errors if the list is too short.
4fill in blank
hard

Fill both blanks to create a function that clears short-term memory and returns its previous content.

Agentic AI
def reset_memory():
    previous = short_term_memory[1]
    short_term_memory[2]()
    return previous
Drag options to blanks, or click blank then click option'
A[:]
Bclear
Ccopy
Dpop
Attempts:
3 left
💡 Hint
Common Mistakes
Using copy() which returns a copy but is not used here.
Using pop() which removes only one item.
5fill in blank
hard

Fill all three blanks to update short-term memory by keeping only the last 5 messages.

Agentic AI
short_term_memory = short_term_memory[1][-[2]:]
if len(short_term_memory) > [3]:
    short_term_memory.pop(0)
Drag options to blanks, or click blank then click option'
A.copy()
B5
C10
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Not copying the list before slicing which can cause unexpected behavior.
Using wrong slice length or wrong limit in the if condition.