Picture this: a graph with no LLM
LangGraph is a state machine. This lab’s nodes are plain Python so you can see every hop.
START
→
step_1hello → HELLO
→
step_2Processed: HELLO
→
ENDfinal_result
Nodes return a patch of state. Module 5 hid these hops inside create_react_agent. Module 7 adds a fork (router).
What is LangGraph?
LangGraph is a way to define agent workflows as state machines. Instead of a simple loop, you can create complex, multi-branching flows:
Graph nodes: Agent thinking steps
Edges: Decisions & transitions
State: Shared data between nodes
Use case: Complex workflows with branching logic, loops, and parallel execution
Before you click Practice — Module 6 notebook
LangGraph is a state machine: nodes are functions, edges are the next hop. This lab uses no LLM inside the graph so you can see orchestration clearly — then you will trust graphs that do call Groq (Modules 4, 5, 7, 8).
TypedDict state→step_1 node→step_2 node→START → END
You still run the key cell (habit for the rest of the workshop). The graph itself only uppercases a string.
Practice task 1
Install packages into this notebook’s Python
Run the first code cell. It uses sys.executable -m pip so packages go into Kodin’s Jupyter kernel, not a random Windows pip.
# Install into THIS notebook kernel (not Windows pip).
import sys
import subprocess
print("Installing into:", sys.executable)
subprocess.check_call([
sys.executable, "-m", "pip", "install", "-qU",
"langgraph", "langchain-groq", "langchain-core",
])
print("Done. Run the next cells.")
Expected: Prints the kernel path, then “Done.”
Why this cell: A plain !pip install on Windows often installs into a different Python, then the next cell fails with ModuleNotFoundError: langgraph. If import still fails: Kernel → Restart Kernel, then Run All.
Practice task 2
API key + MODEL + groq_text (same as Module 1)
Every practice notebook repeats this cell. Run it before any Groq call. Key stays in os.environ["GROQ_API_KEY"] for this kernel session.
import os
MODEL = "openai/gpt-oss-20b"
def groq_text(msg) -> str:
# GPT-OSS may return text, a list of parts, or reasoning_content
...
if not os.getenv("GROQ_API_KEY"):
os.environ["GROQ_API_KEY"] = input("Enter GROQ_API_KEY: ").strip()
print("API key ready. Model:", MODEL)
Expected: “API key ready. Model: openai/gpt-oss-20b”
Why this cell: Without this cell, ChatGroq has no key. Without groq_text, later prints can look empty even when the model answered.
Practice task 3
Custom StateGraph (no LLM in the nodes)
State has three fields. Each node returns only the keys it changes. Edges are hardcoded: always step_1 then step_2. That is a pipeline, not a ReAct loop.
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
class WorkflowState(TypedDict):
input_text: str
processed_text: str
final_result: str
def step_1(state: WorkflowState):
print("Running Step 1...")
return {"processed_text": state["input_text"].upper()}
def step_2(state: WorkflowState):
print("Running Step 2...")
return {"final_result": f"Processed: {state['processed_text']}"}
workflow = StateGraph(WorkflowState)
workflow.add_node("step_1", step_1)
workflow.add_node("step_2", step_2)
workflow.add_edge(START, "step_1")
workflow.add_edge("step_1", "step_2")
workflow.add_edge("step_2", END)
app = workflow.compile()
result = app.invoke({"input_text": "hello langgraph"})
print("\nFinal Output:", result["final_result"])
- Nodes return a patch of state, not the whole object.
compile() freezes the graph; invoke runs it once.
- Compare with Module 5: there the framework hid these nodes inside
create_react_agent.
Expected: Running Step 1... / Running Step 2... / Final Output: Processed: HELLO LANGGRAPH
Why this cell: This is why LangGraph exists versus a black-box agent: you can see every hop. Module 7 adds a conditional edge (router). Module 8 uses a prebuilt ReAct graph plus a real search tool.