Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
Using 'w' opens the file for writing and overwrites existing content, which is suitable for saving memory data.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
json.load reads JSON data from a file object and converts it into a Python object.
3fill in blank
hardFix 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'
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.
✗ Incorrect
append adds a single new item to the list, which is correct for adding one memory entry.
4fill in blank
hardFill 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'
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.
✗ Incorrect
We want the length of the value for the dictionary value and to check if the length of the value is greater than 5.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'item' which is not defined in the loop.
Mixing variable names inconsistently.
✗ Incorrect
The dictionary comprehension uses key and val variables to filter and store items correctly.