0
0
Prompt Engineering / GenAIml~10 mins

Agent memory and state in Prompt Engineering / GenAI - 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 an agent's memory as an empty list.

Prompt Engineering / GenAI
agent_memory = [1]
Drag options to blanks, or click blank then click option'
ANone
B{}
C[]
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using {} which creates an empty dictionary instead of a list.
2fill in blank
medium

Complete the code to add a new state entry to the agent's memory list.

Prompt Engineering / GenAI
agent_memory.[1](new_state)
Drag options to blanks, or click blank then click option'
Aappend
Bextend
Cinsert
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using extend which expects an iterable, not a single item.
3fill in blank
hard

Fix the error in the code to retrieve the last state from the agent's memory.

Prompt Engineering / GenAI
last_state = agent_memory[1]
Drag options to blanks, or click blank then click option'
A[-1]
B[0]
C[-2]
D[1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using [0] which gets the first state, not the last.
4fill in blank
hard

Fill both blanks to update the agent's current state and save it in memory.

Prompt Engineering / GenAI
current_state = [1]
agent_memory.[2](current_state)
Drag options to blanks, or click blank then click option'
Aget_new_state()
Bappend
Cpop
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop which removes an item instead of adding.
5fill in blank
hard

Fill all three blanks to create a dictionary of states with their timestamps and filter recent states.

Prompt Engineering / GenAI
state_log = [1]: [2] for [3] in agent_memory if [2]['timestamp'] > cutoff_time
Drag options to blanks, or click blank then click option'
Astate['id']
Bstate
Dstate['timestamp']
Attempts:
3 left
💡 Hint
Common Mistakes
Using timestamp as key which may not be unique.