Metadata-Version: 2.1
Name: trulens-apps-langgraph
Version: 1.5.2
Summary: Library to systematically track and evaluate LangGraph based applications.
Home-page: https://trulens.org/
License: MIT
Author: Snowflake Inc.
Author-email: ml-observability-wg-dl@snowflake.com
Requires-Python: >=3.9,<4.0
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: langgraph (>=0.5.2)
Requires-Dist: pydantic (>=2.4.2,<3.0.0)
Requires-Dist: trulens-apps-langchain (>=1.0.0,<2.0.0)
Requires-Dist: trulens-core (>=1.0.0,<2.0.0)
Project-URL: Documentation, https://trulens.org/getting_started/
Project-URL: Repository, https://github.com/truera/trulens
Description-Content-Type: text/markdown

# 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

## Installation

```bash
pip install trulens-apps-langgraph
```

## Quick Start

```python
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:

```python
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:

1. **Decorator Monkey-Patching**: TruGraph patches the `@task` decorator at import time
2. **Intelligent Attribute Extraction**: Automatically extracts information from function arguments:
   - Handles `BaseChatModel` and `BaseModel` objects
   - Extracts data from dataclasses and Pydantic models
   - Skips non-serializable objects like LLM pools
   - Captures return values and exceptions
3. **No Code Changes Required**: Works with existing `@task` decorated functions

This approach follows TruLens conventions and is more robust than scanning `sys.modules`.

## Usage

See the [TruLens documentation](https://trulens.org/getting_started/) for complete usage instructions.

