aiml

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.

What is LangGraph?

LangGraph is a framework for building stateful applications as graphs. A graph names the operations in an application and the routes between them. A model node may propose a tool call; application routing decides whether to execute it, answer or stop. Checkpoints preserve graph state, while the tools still need rules for repeated external writes.

Follow a code-review assistant checking pull requests and CI results. Add stop conditions, history limits and timeouts, then inspect a release-note restart and a retried ticket write. Later lessons check edits independently and pause before posting a review comment.

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 share repository conventions across threads through a store.

Lessons

Module 1 · 4 lessons · about 2 hoursAgent loops and limits

Connect a model to tools and enforce explicit stop, context, timeout and resource limits.

  1. Build a graph agent with toolsRead

    Build a LangGraph code-review agent that chooses read-only tools, receives their results and answers, then test tool errors and graph step limits.

    25 min readLabQuiz

  2. 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.

    20 min readLabQuiz

  3. 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.

    25 min readLabQuiz

  4. 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.

    22 min readLabQuiz

Module 2 · 3 lessons · about 1 hourDurable workflows

Resume saved workflows, handle repeated writes and check task outcomes independently.

  1. 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.

    22 min readLabQuiz

  2. 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.

    22 min readLabQuiz

  3. 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.

    25 min readLabQuiz

Module 3 · 2 lessons · about 1 hourPeople and memory

Pause for human review and retain scoped information across conversations.

  1. 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.

    30 min readLabQuiz

  2. 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.

    30 min readLabQuiz