4.3 Orchestration
Where execution begins
The main orchestration happens in plan_travel_internal():
This function implements the following application lifecycle:
- build initial state
- build the graph
- compile it
- stream execution step by step
Knowledge Check
Question 1
Why does the code use compiled_app.stream(initial_state, config) instead of
simply calling the graph once and getting the final result?
Click here to see the answer
Because streaming executes the workflow step by step as each node runs. This lets the application observe intermediate states, track which node is executing, and monitor the workflow in real time instead of waiting only for the final output.
Question 2
Why do we create an initial_state before running the graph?
Click here to see the answer
Because LangGraph workflows operate on a shared state object. The initial_state
provides the starting data that nodes will read from, update, and pass along as
the workflow progresses.