1. State ๐งฎ
The State is a shared data structure that holds the current information or context of the entire application. It acts as the applicationโs memory.- Code representation: Usually defined as a Python
TypedDictor a Pydantic model. - Analogy: The Order Tray that holds the ticket and the plate of food as it travels through the kitchen.
2. Nodes ๐
Nodes are individual functions or operations that perform specific tasks within the graph. They receive the current state, do some processing, and return an updated dictionary to modify the state.- Code representation: Python functions or LangChain
Runnables. - Analogy: The Stations (Prep station, Grill station) where cooks perform tasks on the plate.
3. Graph ๐ก
The Graph is the overarching structure that maps out how different tasks (nodes) are connected and executed.- Code representation: Configured using the
StateGraphclass. - Analogy: The Kitchen Blueprint showing where all stations are located and how trays move between them.
4. Edges ๐ฅ
Edges are the connections between nodes that determine the flow of execution. They tell the graph which node to go to next.- Code representation: Added using
graph.add_edge(source_node, target_node). - Analogy: The Conveyor Belt or the rule directing a tray from Prep Station straight to Grill Station.
5. Conditional Edges ๐
Conditional Edges are specialized connections that decide the next node to execute based on specific conditions or logic applied to the current state.- Code representation: Added using
graph.add_conditional_edges(), pointing to a routing function. - Analogy: The Quality Control Inspector who checks if the food is cooked correctly and routes the tray accordingly.
6. START ๐ & END ๐ฉ
These are special virtual nodes that define where the graph begins and where it finishes execution.- Code representation: Imported as
STARTandENDfromlanggraph.graph. - Analogy:
START: The Order slip printer printing a new customer order.END: The Service Window where the waiter picks up the finished dish.
7. Tools ๐ & ToolNode ๐
- Tools: Executable utilities that nodes can call (like web search, calculations, or API requests).
- ToolNode: A specialized node in LangGraph designed to execute tools automatically and write their outputs back to the State.
-
Analogy:
- Tools: The kitchen appliances (microwave, blender, meat thermometer).
- ToolNode: The assistant cook whose sole job is to operate the blender when requested by the Chef.