Retrieval agent · Part 2 · Debugging

Step-thru Debugging your LangGraphs

Run the API server with --debug-port, attach debugpy from VS Code, and put a breakpoint on any graph node to step through execution instead of inferring it from the outside.

· ~2 min read · Part 2 of 5

What the tutorial already covers

Most of the details required are already covered in langgraph tutorial here: https://langchain-ai.github.io/langgraph/tutorials/langgraph-platform/local-server/

Key points covered there are:

  1. Install LangGraph CLI
    pip install --upgrade "langgraph-cli[inmem]"
    
  2. Install the dependencies
    pip install -e .
    
  3. Use the CLI to run langGraph server
    langgraph dev
    
  4. You may now use LangGraph Studio Web UI at: https://smith.langchain.com/studio/?baseUrl=http://localhost:2024

The additions for step-thru debugging

Here are the additions to enable step-thru-debugging:

  1. Install debugpy in your virtual environment for the langgraph project

    pip install debugpy
    
  2. Start langgraph API server in debug mode. In the following we are telling langgraph-cli to allow clients to listen on Port 2025 for debugger events

    langgraph dev --debug-port 2025
    
  3. Attach to debugger from your IDE. E.g., in here's my VS Code launch config:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python Debugger: Remote Attach",
                "type": "debugpy",
                "request": "attach",
                "connect": {
                    "host": "localhost",
                    "port": 2025
                },
                "pathMappings": [
                    {
                        "localRoot": "${workspaceFolder}",
                        "remoteRoot": "."
                    }
                ],
                "justMyCode": false
            }
        ]
    }
    
  4. I can now put a breakpoint on any of my langgraph code files and step-thru the execution!

Code & references

  1. LangGraph tutorial, running a local server - langchain-ai.github.io
  2. LangGraph Studio against a local server - smith.langchain.com/studio

Retrieval agent · Part 2 of the series · ← Expanding the LangGraph Retrieval Agent Deploying to LangGraph Cloud →