Skip to main content
A LangGraph workflow is built using several core elements. Continuing our Restaurant Kitchen analogy, letโ€™s explore how these elements represent code in practice.

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 TypedDict or 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 StateGraph class.
  • 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 START and END from langgraph.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.

8. Messages ๐Ÿ“ฌ

In conversational agents, the State often contains a list of messages representing the chat history. LangGraph uses standard message classes: