0
0
Agentic AIml~10 mins

State persistence across sessions 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 state to a file.

Agentic AI
with open('agent_state.pkl', [1]) as f:
    pickle.dump(agent_state, f)
Drag options to blanks, or click blank then click option'
A'r'
B'wb'
C'w'
D'rb'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' instead of 'wb' causes errors when saving binary data.
Using 'r' or 'rb' opens the file for reading, not writing.
2fill in blank
medium

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

Agentic AI
with open('agent_state.pkl', [1]) as f:
    agent_state = pickle.load(f)
Drag options to blanks, or click blank then click option'
A'r'
B'w'
C'wb'
D'rb'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'r' instead of 'rb' causes errors when loading binary data.
Using 'w' or 'wb' opens the file for writing, not reading.
3fill in blank
hard

Fix the error in the code to correctly save the agent's state.

Agentic AI
pickle.dump(agent_state, open('state.pkl', [1]))
Drag options to blanks, or click blank then click option'
A'r'
B'w'
C'wb'
D'rb'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' causes errors because pickle needs binary mode.
Using 'r' or 'rb' is for reading, not writing.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that saves only keys with values greater than 10.

Agentic AI
filtered_state = {k: v for k, v in agent_state.items() if v [1] 10 and isinstance(v, [2])}
Drag options to blanks, or click blank then click option'
A>
Bint
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '==' instead of '>' changes the filter condition.
Using wrong type in isinstance causes no filtering.
5fill in blank
hard

Fill all three blanks to update the agent's state, save it, and then load it back.

Agentic AI
agent_state[[1]] = [2]
with open('agent_state.pkl', [3]) as f:
    pickle.dump(agent_state, f)

with open('agent_state.pkl', 'rb') as f:
    loaded_state = pickle.load(f)
Drag options to blanks, or click blank then click option'
A'last_action'
B'new_value'
C'wb'
D'rb'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong file mode causes errors when saving.
Using wrong key or value names breaks the update.