Welcome to the fourth installment of our Agentic AI with LangGraph series. In this post, we transition from the “why” to the “how” by exploring the fundamental building blocks of LangGraph. This documentation will provide you with the conceptual framework needed to build, compile, and execute complex AI agents
1. Understanding LLM Workflows #
A workflow is a series of tasks executed in a specific order to achieve a goal, such as hiring an employee or planning a trip. An LLM Workflow is simply one where specific tasks such as reasoning, decision-making, or tool calling rely on an LLM.
LangGraph allows us to implement five common architectural patterns found in modern AI applications:
- Prompt Chaining: Breaking a complex task into sequential sub-tasks where the output of one LLM call becomes the input for the next (e.g., Topic → Outline → Detailed Report).
- Routing: Using an LLM as a “router” to classify a query and send it to the most capable specialised handler (e.g., directing a customer query to “Refunds,” “Technical Support,” or “Sales”).
- Parallelisation: Splitting a task into multiple sub-tasks that execute simultaneously, then aggregating their results (e.g., checking a video for community guidelines, misinformation, and sexual content all at once).
- Orchestrator-Worker: Similar to parallelization, but the sub-tasks are determined dynamically by a lead “Orchestrator” LLM based on the input query (e.g., a research assistant deciding which specific databases to search).
- Evaluator-Optimizer: An iterative loop where a “Generator” produces a solution and an “Evaluator” provides feedback for refinement until a quality threshold is met (ideal for creative tasks like writing poems or emails).
2. The Core Trio: Graphs, Nodes, and Edges
At its heart, LangGraph represents every LLM workflow as a graph.
- Nodes: These are the “muscles” of your agent. Each node represents a single task and is implemented as a simple Python function.
- Edges: These are the “nervous system” that determines the flow of execution. They define which node runs next and can be sequential, parallel, conditional (branching), or looping.
Essentially, nodes define what to do, while edges define when to do it.
3. State: The Shared Memory #
The State is a shared, mutable memory object that flows through every node in your graph. It holds all the data points required for execution such as the user’s input, intermediate scores, or the final output.
- Implementation: In code, the State is typically a Typed Dictionary or a Pydantic object.
- Evolution: As the graph runs, each node receives the current state as input, performs its task, and returns a partial update to that state, which is then passed to the next node.
4. Reducers: Governing State Updates #
Because the state is mutable, you need rules for how new data interacts with existing data. This is handled by Reducers.
- Replace: The default behaviour where new data overwrites the old value.
- Add/Append: Used in scenarios like chatbots or document drafting where you want to preserve the history of messages or drafts rather than erasing them.
- Merge: Combining complex data structures.
Each key in your state can have its own unique Reducer.
5. The Execution Model: Supersteps and Message Passing #
LangGraph’s execution model is inspired by Google Pregel, a system designed for large-scale graph processing. The process follows three distinct phases:
- Definition & Compilation: You define nodes, edges, and state, then call a
compile()function to ensure the graph’s structure is logically sound (e.g., checking for “orphaned nodes” that aren’t connected). - Invocation: You trigger the graph by passing an initial state to the first node.
- Supersteps: Execution happens in “rounds” called Supersteps. A Superstep involves one or more nodes (if running in parallel) executing their functions and sending their state updates through edges to the next set of nodes. This process of moving data between nodes is known as Message Passing.
The workflow continues automatically until there are no more active nodes and no messages left to pass through the edges.
Conclusion
By understanding Workflows, Graphs, State, Reducers, and Supersteps, you now have the theoretical foundation to build production-grade AI agents. In our next session, we will move to the code and build our very first practical workflow using LangGraph
Q.1 What is the primary role of LangGraph in the development of AI applications?
It is a specialized vector database used for storing high-dimensional embeddings.
It is a programming language designed to replace Python for AI development.
It is a hardware acceleration library specifically for training large language models.
It is an orchestration framework that represents LLM workflows as graphs.
Explanation
LangGraph is an orchestration framework that models AI workflows as graphs, allowing developers to build complex applications with branching, loops, state management, and multi-agent coordination.
Q.2 In the context of a LangGraph workflow, what does a Node fundamentally represent?
The connection path between two different tasks.
A specific piece of data stored in memory.
A Python function that executes a sub-task.
A decision-making logic that branches the flow.
Explanation
A node represents a unit of execution, typically implemented as a Python function that performs a specific task such as calling an LLM, invoking a tool, or processing data.
Q.3 Which LLM workflow pattern involves a single LLM deciding which specialized LLM or tool should handle a specific user query?
Prompt Chaining.
Routing.
Parallelization.
Evaluator-Optimizer.
Explanation
Routing uses an LLM to analyse the user’s request and direct it to the most appropriate specialised model, prompt, or tool for execution.
Q.4 What is the key difference between the Parallelization workflow and the Orchestrator-Worker workflow?
Orchestrator-Worker dynamically determines sub-tasks based on the input.
Parallelization uses multiple LLMs while Orchestrator-Worker uses only one.
Orchestrator-Worker does not allow result aggregation.
Parallelization is sequential, while Orchestrator-Worker is concurrent.
Explanation
In Parallelization, tasks are predefined and executed simultaneously. In the Orchestrator-Worker pattern, the orchestrator dynamically decides what sub-tasks are needed and assigns them to workers during execution.
Q.5 How is State defined within a LangGraph environment?
A local variable that exists only within a single node.
The final output generated at the end of graph execution.
A hard-coded configuration file.
A shared memory that persists and evolves across all nodes in the graph.
Explanation
State is a shared data structure that carries information throughout graph execution. Every node can read from it and update it, enabling coordinated workflows.
Q.6 Why might a developer use a Reducer when defining a State key for a chatbot?
To ensure every new message replaces the previous one.
To prevent nodes from accessing sensitive data.
To automatically compress text.
To append new messages to a list instead of overwriting the conversation history.
Explanation
Reducers define how state updates are merged. For chatbot conversations, reducers typically append new messages to the existing history instead of replacing earlier messages.
Q.7 In the LangGraph execution model, what occurs during the Compilation step?
The LLM generates the first task.
The framework validates the graph structure for logical issues before execution.
Python code is converted into machine code.
The initial state is automatically filled with user input.
Explanation
Compilation validates the workflow by checking node connections, edges, entry and exit points, and identifying structural errors before execution begins.
Q.8 What is a Superstep in the context of LangGraph's execution?
A manual override by a human operator.
A complex reasoning prompt.
The transition from a subgraph back to the parent graph.
A single execution round that may include multiple nodes running in parallel.
Explanation
A Superstep is one execution cycle in which all eligible nodes run simultaneously. After they finish, their state updates are merged before the next Superstep begins.
Q.9 In an Evaluator-Optimizer workflow, when does the execution loop typically stop?
After exactly three iterations.
When the Evaluator determines the generated solution satisfies the required quality criteria.
Immediately after the Generator produces its first draft.
When the Reducer clears the state.
Explanation
The Evaluator reviews the generated output. If it meets the desired quality threshold, the loop terminates; otherwise, feedback is provided for another optimisation cycle.
Q.10 Which feature of LangGraph allows a workflow to recover from a failure at the exact point it broke down?
Resumability.
Branching.
Prompt Chaining.
Parallelization.
Explanation
Resumability allows a workflow to continue from its most recent checkpoint after a failure, interruption, or human approval, avoiding the need to restart the entire process.