Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize a LangGraph agent with a state.
Agentic AI
agent = LangGraphAgent(state=[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using None instead of an empty dictionary causes errors when updating state.
Using a list [] does not allow key-based state storage.
✗ Incorrect
The agent's state should be initialized as an empty dictionary {} to hold key-value pairs representing the agent's memory.
2fill in blank
mediumComplete the code to update the agent's state with a new key-value pair.
Agentic AI
agent.state[[1]] = 'active'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the key causes a NameError.
Using an incorrect key name that doesn't match the intended state.
✗ Incorrect
Keys in dictionaries must be strings enclosed in quotes, so 'status' is correct.
3fill in blank
hardFix the error in the code to retrieve the agent's current mode safely.
Agentic AI
current_mode = agent.state.get([1], 'idle')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted keys causes NameError.
Using wrong key names returns unexpected results.
✗ Incorrect
The key must be a string in quotes, so 'mode' is correct to safely get the value or default to 'idle'.
4fill in blank
hardFill both blanks to create a LangGraph agent that updates state and then retrieves a value.
Agentic AI
agent.state[[1]] = 'running' mode = agent.state.get([2], 'stopped')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up keys causes wrong state updates or retrievals.
Forgetting quotes around keys causes errors.
✗ Incorrect
First, update the 'status' key to 'running', then retrieve the 'mode' key with default 'stopped'.
5fill in blank
hardFill all three blanks to define a function that updates the agent's state and returns the updated value.
Agentic AI
def update_agent_state(agent, key, value): agent.state[[1]] = [2] return agent.state.get([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string literals instead of variables.
Forgetting to return the updated value.
✗ Incorrect
Use the function parameters key and value to update and then retrieve the state by key.