This tutorial builds on Add human-in-the-loop controls.
1. Add keys to the state
Update the chatbot to research the birthday of an entity by addingname
and birthday
keys to the state:
2. Update the state inside the tool
Now, populate the state keys inside of thehuman_assistance
tool. This allows a human to review the information before it is stored in the state. Use Command
to issue a state update from inside the tool.
3. Prompt the chatbot
Prompt the chatbot to look up the โbirthdayโ of the LangGraph library and direct the chatbot to reach out to thehuman_assistance
tool once it has the required information. By setting name
and birthday
in the arguments for the tool, you force the chatbot to generate proposals for these fields.
interrupt
in the human_assistance
tool again.
4. Add human assistance
The chatbot failed to identify the correct date, so supply it with information:5. Manually update the state
LangGraph gives a high degree of control over the application state. For instance, at any point (including when interrupted), you can manually override a key usinggraph.update_state
:
6. View the new value
If you callgraph.get_state
, you can see the new value is reflected:
interrupt
function is generally recommended instead, as it allows data to be transmitted in a human-in-the-loop interaction independently of state updates.
Congratulations! Youโve added custom keys to the state to facilitate a more complex workflow, and learned how to generate state updates from inside tools.
Check out the code snippet below to review the graph from this tutorial:
- OpenAI
- Anthropic
- Azure
- Google Gemini
- AWS Bedrock
Next steps
Thereโs one more concept to review before finishing the LangGraph basics tutorials: connectingcheckpointing
and state updates
to time travel.