Build a LangGraph agent with memory
Build a research agent using LangGraph with two tools: web search (via Tavily or DuckDuckGo) and a persistent memory store. The agent should accept a topic, plan sub-questions, search for each, store results in memory, and synthesise a structured summary; all within a typed, resumable graph.
Why this matters
Single-turn agents break on any task requiring more than one tool call. LangGraph's checkpoint system lets you pause, inspect, and resume mid-run; the critical capability for agents in production where things go wrong mid-task. Understanding how state flows through a graph makes every agentic system you build after this easier to debug.
Before you start
- Comfortable with Python async and type hints
- Understanding of what a tool call is in the context of LLMs
- LangGraph installed (pip install langgraph langchain-anthropic)
- A Tavily API key or access to another search tool
Step-by-step guide
- 1
Define your state schema
Create a TypedDict for the agent state: messages list, a memory dict keyed by topic, and a plan list. Every node in your graph reads from and writes to this state. Getting the schema right before writing nodes saves significant refactoring later.
- 2
Build the planner node
Write a node that calls Claude with the user's research topic and asks it to decompose it into 3-4 specific sub-questions. Parse the output into the plan list in state. Test this node in isolation by calling it with a mock state before wiring it into the graph.
- 3
Build the search node
Write a node that pops the next sub-question from the plan, runs a web search, and stores the result in the memory dict under the sub-question as key. Add a conditional edge: if the plan is empty, route to the synthesis node; otherwise loop back.
- 4
Build the synthesis node
Write a final node that reads all entries from the memory dict and asks Claude to synthesise them into a structured summary with headings. The summary should cite which sub-question each section came from.
- 5
Wire the graph and add checkpointing
Connect the nodes: START -> planner -> search -> (conditional) -> synthesis -> END. Add a MemorySaver checkpointer and test that you can interrupt after the planner, inspect state, and resume. This is the feature that separates production agents from demos.