Building Agents with LangGraph
LangGraph 1.2
Build and compare self-contained code-review agents and workflows with LangGraph: tools, stop conditions, context and token budgets, timeouts, checkpoints, idempotent retries, verified outcomes, human approval and memory.
- Prerequisites
- Python 3.12, async Python and pytest, and a Gemini API key (or Ollama with gemma4:e2b).
- Duration
- about 4 hours of reading
- Cost
- Free, no sign-up
What you'll learn
- Build a StateGraph agent with tools, route each reply with conditional edges and stop it in a named state.
- Trim conversation history to a token budget, and time out tool and model calls.
- Checkpoint a workflow to SQLite, resume it after a crash, and make retried writes idempotent.
- Verify a multi-step task from the files it changed, not from the agent's report.
- Pause a graph for human approval and give an agent long-term memory.
Lessons
Module 1 · 4 lessonsAgent loops and limits
Build a graph agent with toolsRead
Build a code-review agent as a LangGraph StateGraph with a ToolNode and tools_condition, run it on Gemini, and handle tool errors and the step limit.
Add branches and stop conditions to a LangGraph agentRead
Replace tools_condition with a custom LangGraph router that stops repeated tool calls and runs near recursion_limit, and test every branch without a model.
Trim conversation history to a token budget in LangGraphRead
Trim a LangGraph code-review thread with trim_messages, pin key decisions, and compare the token estimate with Gemini’s reported input usage.
Add timeouts and token budgets to a LangGraph agentRead
Bound a LangGraph agent with tool and model timeouts and a soft token budget, then inspect a genuine tool proposal followed by a native local timeout.
Module 2 · 3 lessonsDurable workflows
Checkpoint a LangGraph workflow and resume it after a crashRead
Checkpoint a LangGraph workflow to SQLite with SqliteSaver, kill the process mid-run, resume without calling Gemini again and see which steps repeat.
Make LangGraph retries idempotentRead
Retry a ticket-filing write with a LangGraph RetryPolicy, see a retry file a duplicate, and stop duplicates across retries and resumes with an idempotency key.
Plan, execute and verify a multi-step task in LangGraphRead
Build a LangGraph plan, execute and verify graph that applies a review fix with a create_agent executor and grades it by running the project's tests.
Module 3 · 2 lessonsPeople and memory
Add human-in-the-loop interruptsRead
Pause a LangGraph code-review agent with interrupt() before it posts a comment, then resume it with Command(resume=...) to approve, edit or reject.
Add a long-term memory storeRead
Give a LangGraph code-review agent memory across threads with a store keyed by repository and topic, and see the stale-rule and namespace-prefix failures.
