Library to systematically track and evaluate LangGraph based applications.
Project description
trulens-apps-langgraph
TruLens integration for LangGraph applications. This package provides comprehensive instrumentation and evaluation capabilities for LangGraph-based multi-agent workflows.
Features
- Automatic Detection: TruGraph automatically detects LangGraph applications
- Combined Instrumentation: Inherits all LangChain instrumentation plus LangGraph-specific methods
- Multi-Agent Evaluation: Comprehensive evaluation capabilities for complex workflows
- Automatic @task Instrumentation: Automatically detects and instruments functions decorated with
@task - Smart Attribute Extraction: Intelligently extracts information from function arguments
- OpenTelemetry Compatibility: Full support for both traditional TruLens instrumentation and OTel tracing mode
Installation
pip install trulens-apps-langgraph
Quick Start
from langgraph.graph import StateGraph, MessagesState, END
from langchain_core.messages import HumanMessage
from trulens.apps.langgraph import TruGraph
# Create your LangGraph application
workflow = StateGraph(MessagesState)
workflow.add_node("agent", your_agent_function)
workflow.add_edge("agent", END)
workflow.set_entry_point("agent")
graph = workflow.compile()
# Automatically instrument with TruGraph
tru_app = TruGraph(graph, app_name="MyLangGraphApp")
# Use normally - all interactions are automatically logged
with tru_app as recording:
result = graph.invoke({"messages": [HumanMessage(content="Hello!")]})
Automatic @task Instrumentation
TruGraph automatically instruments functions decorated with LangGraph's @task decorator by monkey-patching the decorator itself. This follows TruLens instrumentation patterns and ensures seamless integration:
from langgraph.func import task
@task # Automatically instrumented by TruGraph when TruGraph is imported
def my_agent_function(state, config):
# Your agent logic here
return updated_state
How it works:
- Decorator Monkey-Patching: TruGraph patches the
@taskdecorator at import time - Intelligent Attribute Extraction: Automatically extracts information from function arguments:
- Handles
BaseChatModelandBaseModelobjects - Extracts data from dataclasses and Pydantic models
- Skips non-serializable objects like LLM pools
- Captures return values and exceptions
- Handles
- No Code Changes Required: Works with existing
@taskdecorated functions
This approach follows TruLens conventions and is more robust than scanning sys.modules.
OpenTelemetry (OTel) Compatibility
TruGraph supports both traditional TruLens instrumentation and OpenTelemetry tracing mode for interoperability with existing telemetry stacks:
Traditional Mode (Default)
Uses TruLens native instrumentation with combined LangChain and LangGraph method tracking.
OTel Mode
Enable OpenTelemetry tracing by setting the environment variable:
import os
os.environ["TRULENS_OTEL_TRACING"] = "1"
# TruGraph will automatically:
# - Detect the main method (invoke or run)
# - Use OTel-compatible instrumentation
# - Disable traditional instrumentation system
from trulens.core.session import TruSession
session = TruSession()
tru_app = session.App(graph, app_name="MyOTelApp")
In OTel mode, TruGraph seamlessly integrates with OpenTelemetry spans, enabling:
- Language-agnostic tracing
- Distributed system observability
- Interoperability with existing telemetry infrastructure
Usage
See the TruLens documentation for complete usage instructions.
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 trulens_apps_langgraph-1.5.3.tar.gz.
File metadata
- Download URL: trulens_apps_langgraph-1.5.3.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19682c92b32278373f1df10f5ee6951de10ded28dc0b90b5b27aa81500d49f87
|
|
| MD5 |
2cde16090baece68368f48f78cd478ef
|
|
| BLAKE2b-256 |
d969a2264358de47af1a00843b51324144208d986b03833dfd4454bbd4d5e111
|
File details
Details for the file trulens_apps_langgraph-1.5.3-py3-none-any.whl.
File metadata
- Download URL: trulens_apps_langgraph-1.5.3-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4d87aac68712f848bffa1321283f5a637aea8c8abaf01e9b24375e02b4dd914
|
|
| MD5 |
c872e2a6418ba79ba8c7e4d28cb33561
|
|
| BLAKE2b-256 |
22dd43a644e44d49029e7effa5e2b836eb67c645bcae51385f9d19c223a68044
|