Complete the code to initialize the agent's state dictionary.
agent_state = [1]We use an empty dictionary {} to store the agent's state because it allows us to keep track of multiple key-value pairs representing different aspects of the agent's memory.
Complete the code to update the agent's state with a new observation.
agent_state['last_observation'] = [1]
We assign the new observation data to the key 'last_observation' in the agent's state dictionary to keep track of the latest input.
Fix the error in the code that tries to access a missing key in the agent's state safely.
last_action = agent_state.get([1], 'no_action')
Using get('last_action', 'no_action') safely retrieves the last action if it exists; otherwise, it returns the default string 'no_action'.
Fill both blanks to create a function that resets the agent's state and logs the reset event.
def reset_agent_state(): agent_state = [1] log_event([2])
Resetting the agent's state to an empty dictionary {} clears previous data. Logging the string 'Agent state reset' records this event.
Fill all three blanks to update the agent's state with a new action, check if the state has changed, and return the updated state.
def update_state(agent_state, new_action): old_state = agent_state.copy() agent_state[[1]] = [2] if agent_state != old_state: print([3]) return agent_state
The function updates the 'last_action' key with the new action. It compares the old and new state, printing 'State updated' if they differ, then returns the updated state.