14. How to convert input and output of subgraph
subgraph state end parent graph It can be completely independent of the state.
In other words, there may not be a state keys that overlap between the two graphs.
In this case subgraph You need to convert the input before calling, and the output before returning.
Preferences
Copy
# Configuration file for managing API keys as environment variables
from dotenv import load_dotenv
# Load API key information
load_dotenv()Copy
True Copy
# Set up LangSmith tracking. https://smith.langchain.com
# !pip install -qU langchain-teddynote
from langchain_teddynote import logging
# Enter a project name.
logging.langsmith("CH17-LangGraph-Modules")Copy
graph Wow subgraph Justice
graph Wow subgraph JusticeThree as follows graph Let me define.
parent graphparent graphTo be called bychild subgraphchild graphTo be called bygrandchild subgraph
grandchild Justice
grandchild JusticeCopy
Visualize the graph.
Copy
Copy
Copy
child Justice
child JusticeCopy
Copy
Copy
Copy
grandchild_graph Separate function of call call_grandchild_graph ) Is wrapped.
This function converts the input state before calling the grandchild graph, and converts the output of the grandchild graph back to the child graph state.
If there is no such conversion grandchild_graph directly .add_node If you pass it to, LangGraph will get an error because there is no state key shared between the child and grandchild states.
important
child subgraph Wow grandchild subgraph has parent graph Your own not shared with Independent state Please note that you have.
parent Justice
parent JusticeCopy
Visualize the graph.
Copy

child_graph Separate function of call call_child_graph Wrapped in, this function converts the input state before calling the child graph and converts the output of the child graph back to the parent graph state.
Without conversion child_graph directly .add_node If you pass it to, LangGraph will get an error because there is no State Key shared between parent and child status. So, I'll run the parent graph to see if the child and grandson subgraphs are called correctly.
Copy
Copy
Last updated