LangChain & LangGraph
LangChain & LangGraph
LangChain is the most widely used AI application framework. If you’ve built anything with LLMs beyond a simple API call, you’ve probably encountered it — or something inspired by it.
But LangChain the library and LangGraph the agent engine are different things, and the distinction matters. LangChain gives you building blocks. LangGraph gives you control over how agents think and act.
LangChain — The Building Blocks
LangChain provides abstractions for the common things AI applications do:
| Component | What It Does | Example |
|---|---|---|
| Chat models | Unified interface to any LLM | Talk to OpenAI, Anthropic, Gemini, local models — same code |
| Prompts | Template and manage prompts | System prompts, few-shot examples, dynamic injection |
| Output parsers | Structure LLM output | Extract JSON, lists, structured data from freeform text |
| Retrievers | Fetch relevant data | Vector search, database queries, web search |
| Tools | Give LLMs actions | Web search, code execution, API calls, file operations |
| Chains | Compose operations | Retrieve → prompt → generate → parse → store |
Available in: Python and TypeScript/JavaScript
The honest assessment: LangChain was criticised in 2023-2024 for being over-abstracted — too many layers between you and the LLM. The team responded. Recent versions are much cleaner. But if you’re doing something simple, you might not need it at all. The native APIs from Anthropic or OpenAI are excellent for basic tool use.
LangGraph — The Agent Engine
LangGraph is where the interesting work happens. It’s a framework for building stateful, controllable agent workflows using a graph-based architecture.
flowchart TD
Start([User Input]) --> Router{Route}
Router -->|Simple| Direct[Direct Response]
Router -->|Needs Research| Research[Research Node]
Router -->|Needs Code| Code[Code Node]
Research --> Evaluate{Good Enough?}
Code --> Evaluate
Evaluate -->|No| Research
Evaluate -->|Yes| Respond[Generate Response]
Direct --> End([Output])
Respond --> End Why Graphs?
An agent’s workflow isn’t linear. It branches, loops, backtracks, and makes decisions. A graph is the natural data structure:
- Nodes = actions (call the LLM, execute a tool, check a condition)
- Edges = transitions (what happens next, based on what just happened)
- State = persistent memory across the graph (what has the agent learned so far?)
You define the graph. LangGraph executes it. The LLM makes decisions at each node. You control the structure.
Key Features
| Feature | Why It Matters |
|---|---|
| State management | The agent remembers what it’s done. Persists across turns. |
| Human-in-the-loop | Pause at any node for human approval before proceeding |
| Checkpointing | Save and resume agent state. Crucial for long-running tasks. |
| Streaming | See what the agent is doing in real time |
| Multi-agent | Multiple agents collaborating in the same graph |
| Subgraphs | Compose complex workflows from smaller, reusable workflows |
When LangGraph Shines
- Complex research tasks that require multiple search → evaluate → refine cycles
- Multi-step workflows where the order depends on intermediate results
- Any task requiring human approval gates
- Production agent systems that need observability and debugging
LangSmith — Observability
You can’t debug what you can’t see. LangSmith is the companion observability platform:
- Trace every step — See exactly what the LLM received, what it returned, what tool was called
- Evaluate quality — Run test datasets through your agent, measure performance
- Debug failures — When an agent goes wrong, trace backwards to find where
- Monitor production — Latency, cost, error rates, quality metrics
This is the part people underestimate. Building an agent is one thing. Knowing why it failed on a Tuesday at 3am is another.
Comparison with Alternatives
| Aspect | LangGraph | CrewAI | Native API (Anthropic, OpenAI) |
|---|---|---|---|
| Control | Maximum — you define every node and edge | Moderate — role-based, framework decides flow | Basic — single-agent loop |
| Multi-agent | Yes, explicit graph connections | Yes, role-based delegation | No (must build yourself) |
| Learning curve | Steep | Moderate | Gentle |
| Best for | Complex, production workflows | Quick multi-agent prototypes | Simple tool use, single agent |
| Observability | LangSmith (excellent) | Limited built-in | Roll your own |
What I’m Still Learning
- The right level of graph complexity — too few nodes and you lose control, too many and it’s brittle
- When to use LangGraph vs just calling the API directly (the 80/20 rule: most tasks don’t need a graph)
- How LangGraph interacts with MCP — the integration is still maturing
Go Deeper
- Agent Frameworks — Overview of all frameworks
- AI Agents — What agents are and how they work
- Model Context Protocol — The universal tool protocol
- RAG & Retrieval — A common pattern inside LangGraph workflows
- Prompt Engineering — Designing the prompts inside your nodes
- AI Intelligence Hub — Back to the hub home
Sources
- LangChain Docs — Full framework documentation
- LangGraph Docs — Agent engine documentation
- LangSmith — Observability platform
- LangChain GitHub — Source code
- LangGraph Examples — Practical implementations