0
0
Prompt Engineering / GenAIml~20 mins

Agent memory and state in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Agent Memory Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary role of agent memory in AI systems?

In AI agents, what does the agent memory mainly help with?

AIncreasing the speed of the AI's calculations
BReducing the size of the AI model
CStoring past interactions to improve future decisions
DEncrypting data for security purposes
Attempts:
2 left
💡 Hint

Think about how remembering past events can help an AI act better next time.

Predict Output
intermediate
2:00remaining
Output of agent state update code

What will be the value of state after running this code?

Prompt Engineering / GenAI
state = {'count': 0}

# Agent receives new input
input_signal = 3

# Update state by adding input_signal
state['count'] += input_signal

# Agent receives another input
input_signal = 2

# Update state again
state['count'] += input_signal

print(state)
A{'count': 5}
B{'count': 3}
C{'count': 2}
D{'count': 0}
Attempts:
2 left
💡 Hint

Remember the state updates add the input signals cumulatively.

Hyperparameter
advanced
2:00remaining
Choosing memory size for an AI agent

You want your AI agent to remember recent conversations but limit memory size to save resources. Which memory size hyperparameter is best?

AStore all interactions indefinitely
BKeep memory size to last 5 interactions
CForget all past interactions after each step
DStore only the first interaction
Attempts:
2 left
💡 Hint

Think about balancing memory usefulness and resource limits.

Metrics
advanced
2:00remaining
Evaluating agent memory effectiveness

Which metric best measures how well an AI agent uses its memory to improve task success?

ATask completion accuracy over time with memory enabled
BCPU usage during agent execution
CNumber of lines of code in the memory module
DSize of the training dataset
Attempts:
2 left
💡 Hint

Focus on measuring the agent's performance improvement due to memory.

🔧 Debug
expert
2:00remaining
Why does the agent state not update correctly?

Consider this code snippet for updating an agent's state. Why does the state not reflect the new input?

Prompt Engineering / GenAI
class Agent:
    def __init__(self):
        self.state = {'value': 0}

    def update(self, input_val):
        state = self.state.copy()
        state['value'] = input_val

agent = Agent()
agent.update(10)
print(agent.state)
AThe print statement is called before the update method
BThe state dictionary is immutable and cannot be changed
CThe input_val is not passed correctly to the update method
DThe update method modifies a local variable 'state' instead of the instance's state
Attempts:
2 left
💡 Hint

Check if the update method changes the actual agent's state or just a copy.