0
0
Agentic AIml~10 mins

Memory persistence and storage 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 save the agent's memory to a file.

Agentic AI
with open('memory_store.txt', [1]) as file:
    file.write(memory_data)
Drag options to blanks, or click blank then click option'
A'w'
B'r'
C'x'
D'a'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'r' mode which is read-only and causes an error when writing.
Using 'a' mode which appends instead of overwriting.
2fill in blank
medium

Complete the code to load the agent's memory from a JSON file.

Agentic AI
import json
with open('memory_store.json', 'r') as file:
    memory_data = json.[1](file)
Drag options to blanks, or click blank then click option'
Adump
Bdumps
Cloads
Dload
Attempts:
3 left
💡 Hint
Common Mistakes
Using json.dump which writes JSON instead of reading.
Using json.loads which expects a string, not a file.
3fill in blank
hard

Fix the error in the code that appends new memory data to a list stored in a file.

Agentic AI
import json
with open('memory_store.json', 'r') as file:
    memory_list = json.load(file)
memory_list.[1](new_memory)
with open('memory_store.json', 'w') as file:
    json.dump(memory_list, file)
Drag options to blanks, or click blank then click option'
Aappend
Badd
Cinsert
Dextend
Attempts:
3 left
💡 Hint
Common Mistakes
Using extend which expects an iterable and would add each element separately.
Using add which is not a list method.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that stores memory keys and their lengths if length is greater than 5.

Agentic AI
memory_lengths = {key: [1] for key, value in memory_store.items() if [2] > 5}
Drag options to blanks, or click blank then click option'
Alen(value)
Blen(key)
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(key) which measures the key length, not the value.
Checking length of key instead of value in the condition.
5fill in blank
hard

Fill all three blanks to filter and store memory items where the value is a string longer than 3 characters.

Agentic AI
filtered_memory = { [1]: [2] for [3], val in memory_store.items() if isinstance(val, str) and len(val) > 3 }
Drag options to blanks, or click blank then click option'
Akey
Bval
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'item' which is not defined in the loop.
Mixing variable names inconsistently.