A visual tracer and debugger for LangChain and LangGraph
Project description
LangLens
Node-Level Observability for LangChain and LangGraph.
LangLens is a lightweight visual tracer and debugger designed specifically for LLM-powered applications. It captures detailed execution logs from your agents and chains, allowing you to inspect every LLM call, tool execution, and state transition with precision.
✨ Features
- 🔍 Interactive Trace Viewer: Explore complex workflows through a rich graphical interface.
- 🧩 Node-Level Granularity: Deep dive into individual chain runs, LLM inputs/outputs, and tool executions.
- 💻 VS Code Extension: Debug your traces directly inside VS Code with a custom editor experience.
- 🚀 CLI Tool: Quickly host a local viewer for any
.langlensfile. - 🔌 Seamless Integration: Add observability to your existing projects with a single line of code.
🏗️ How it Works
LangLens bridges the gap between your LLM execution and visual debugging:
graph TD
subgraph "Capture Phase"
A[LLM App] -- "1. LangChain Callbacks" --> B(LangLens Handler)
B -- "2. Stream Events" --> C[[.langlens file]]
end
subgraph "Visualization Phase"
C -- "3a. CLI Server" --> D[Web Browser]
C -- "3b. Custom Editor" --> E[VS Code IDE]
D --> F{Interactive UI}
E --> F
F -- "4. Inspect Nodes" --> G[Observability & Debugging]
end
- Capture: The
LangLensCallbackHandlerhooks into LangChain's event system to record starts, ends, and errors of every chain, tool, and LLM call. - Storage: Events are serialized and saved into a
.langlensfile (JSONL format), providing a portable trace of the entire execution. - Visualization:
- The CLI Tool launches a local Python server that hosts a Svelte-based frontend.
- The VS Code Extension registers as a custom editor for
.langlensfiles, embedding the same Svelte UI directly into your workspace.
- Debugging: Use the interactive graph to navigate complex agentic workflows and inspect raw inputs/outputs at any level of the tree.
📦 Installation
Since LangLens is currently in development and not yet published to PyPI or the VS Code Marketplace, you can install it from source.
1. Build the Web UI
The Python viewer and VS Code extension both require the bundled Web UI.
# Build the UI and copy assets to the Python/VS Code directories
./build_ui.sh
2. Python Package
Install the package in editable mode from the root directory:
pip install -e .
3. VS Code Extension
To use the extension locally:
- Open the
/vscode-extensionfolder in VS Code. - Run
pnpm install. - Press
F5to start a new Extension Development Host window with the extension loaded.
📦 Packaging and Releases
To build both the Python package and the VS Code extension for distribution, you can use the provided script:
./scripts/package.sh
This will:
- Build the Web UI.
- Generate Python
.whland.tar.gzfiles indist/. - Generate a VS Code
.vsixfile indist/.
Continuous Integration
This project includes a GitHub Action workflow in .github/workflows/release.yml. When you push a tag (e.g., v0.1.0), it will automatically:
- Build all packages.
- Create a GitHub Release with the artifacts attached.
🚀 Quick Start
1. Integrate the Callback
Add the LangLensCallbackHandler to your LangChain or LangGraph execution config.
from langlens import LangLensCallbackHandler
from langchain_openai import ChatOpenAI
# Initialize the handler (creates a logs.langlens file)
handler = LangLensCallbackHandler(filename="logs.langlens")
# Attach it to your run
llm = ChatOpenAI()
config = {"callbacks": [handler]}
response = llm.invoke("How does a sunrise look from Mars?", config=config)
2. Visualize the Trace
Option A: Using the CLI
Run the following command to start a local server and open the viewer in your browser:
langlens visualize logs.langlens
Option B: Using VS Code
Simply open any .langlens file. The LangLens Viewer will automatically render the interactive trace.
🛠️ Development
Building the Web UI
The UI is built with Svelte and Tailwind CSS.
cd web-ui
pnpm install
pnpm build
Building the VS Code Extension
cd vscode-extension
pnpm install
pnpm run package
📄 License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langlens-0.1.0.tar.gz.
File metadata
- Download URL: langlens-0.1.0.tar.gz
- Upload date:
- Size: 270.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25675559d096de4275ec3be6638c830e135b728f01dbd67623358b8b78d58097
|
|
| MD5 |
a068dce115fd57da4dade5e926c231c3
|
|
| BLAKE2b-256 |
a1344f46a0363679e149c45c590d5b114dfd10ba359e094cf079458c6e4ea2e4
|
File details
Details for the file langlens-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langlens-0.1.0-py3-none-any.whl
- Upload date:
- Size: 275.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61f1c5bcd2df091a38e7867526fb9263d317f39e3e7ebad0818fd41a84747adb
|
|
| MD5 |
fdad4daf57e61cae9621c2993b326345
|
|
| BLAKE2b-256 |
0ed9aa50a0f679626300cc53034a669403c1f77a1e169f16643589b76357ab41
|