> ## Documentation Index
> Fetch the complete documentation index at: https://genai.codewithsiva.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Core Elements

> Learn the fundamental components that make up a LangGraph application

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:

| Message Type      | Purpose                      | Kitchen Analogy                             |
| ----------------- | ---------------------------- | ------------------------------------------- |
| **HumanMessage**  | Input from the user          | Customer placing an order                   |
| **AIMessage**     | Response from the AI model   | Chef describing what they cooked            |
| **SystemMessage** | Guidelines for the model     | Restaurant recipe booklet instructions      |
| **ToolMessage**   | Output from a tool execution | Thermometer reading value written on ticket |
