Observability & Debugging
Master LangSmith Observability in LangGraph — track execution traces, optimize token costs, debug latent subtasks, and configure LLMOps metrics.
Because LLMs are non-deterministic, debugging agent loops without proper observability tools is like driving blind. This module details integrating your graphs with LangSmith to track latency, evaluate outputs, and trace variable inputs at each step.
LangSmith & LLMOps
Why this matters
LangSmith traces every node execution — essential for debugging non-deterministic agent flows.
LangSmith records traces for every node: inputs, outputs, latency, token usage.
- Set
LANGCHAIN_TRACING_V2=trueandLANGCHAIN_API_KEY. - Tag runs by project/environment for staging vs production comparison.
- LLMOps: eval datasets, regression tests on graph changes.
Common mistakes
- Forgetting to compile the graph with a checkpointer when persistence is required.
- List state fields without reducers — updates overwrite instead of append.
- Infinite loops in cyclic graphs with no max iteration or termination edge.
Interview checkpoints
- Q: Explain langsmith in LangGraph. A: One-sentence definition + one API.
- Q: Common bug? A: State, checkpointer, or routing loop issue.
Practice
- Basic: Sketch a minimal langsmith example.
- Intermediate: Run a notebook cell demonstrating LangSmith.
- Advanced: Break LangSmith intentionally and read the LangSmith trace.
Recap
- You can explain langsmith clearly.
- You know one mistake to avoid.
- You see how this connects to the next lesson.
Next: Debugging
Debugging Agent Flows
Why this matters
Agent bugs often hide in routing logic; structured traces expose latency spikes and wrong tool calls.
Debug agent flows by comparing trace trees: which node ran, which tool fired, where latency spiked.
- Common issues: wrong conditional edge, missing tool schema, runaway loops.
- Cost debugging: count LLM calls per thread; cache retrieval where possible.
Common mistakes
- Forgetting to compile the graph with a checkpointer when persistence is required.
- List state fields without reducers — updates overwrite instead of append.
- Infinite loops in cyclic graphs with no max iteration or termination edge.
Interview checkpoints
- Q: Explain debugging in LangGraph. A: One-sentence definition + one API.
- Q: Common bug? A: State, checkpointer, or routing loop issue.
Practice
- Basic: Sketch a minimal debugging example.
- Intermediate: Run a notebook cell demonstrating Debugging.
- Advanced: Break Debugging intentionally and read the LangSmith trace.
Recap
- You can explain debugging clearly.
- You know one mistake to avoid.
- You see how this connects to the next lesson.
Next: MCP
