Complete the code to define an AI agent that takes actions based on observations.
class AIAgent: def __init__(self): pass def act(self, observation): return [1]
The act method should return an action. Returning None means no action is taken yet.
Complete the code to initialize the AI agent's internal state.
class AIAgent: def __init__(self): self.state = [1]
[] which is less descriptive for state.The internal state is best represented as an empty dictionary {} to store key-value pairs.
Fix the error in the method that updates the agent's state with new observations.
def update_state(self, observation): self.state.update([1])
The update method requires a dictionary argument, so passing observation (assumed to be a dict) updates the state correctly.
Fill both blanks to create a method that decides an action based on the agent's state.
def decide_action(self): if 'goal' in self.state and self.state['goal'] [1] 0: return 'move_towards_goal' else: return [2]
The agent checks if the goal value is greater than zero to decide to move. Otherwise, it returns 'idle' to do nothing.
Fill all three blanks to implement a simple AI agent loop that updates state, decides action, and acts.
def run_agent(agent, observation): agent.state.update([1]) action = agent.[2]() return agent.[3](action)
The agent updates its state with the observation, decides an action, then acts on that action.