Metadata-Version: 2.4
Name: respan-instrumentation-langchain
Version: 0.1.0
Summary: Respan instrumentation plugin for LangChain, LangGraph, and Langflow
License: Apache 2.0
Author: Respan
Author-email: team@respan.ai
Requires-Python: >=3.11,<3.14
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Provides-Extra: all
Provides-Extra: langflow
Provides-Extra: langgraph
Requires-Dist: langchain-core (>=0.3.0)
Requires-Dist: langflow (>=1.0.0) ; extra == "langflow" or extra == "all"
Requires-Dist: langgraph (>=0.2.0) ; extra == "langgraph" or extra == "all"
Requires-Dist: respan-sdk (>=2.6.1)
Requires-Dist: respan-tracing (>=2.16.6,<3.0.0)
Description-Content-Type: text/markdown

# respan-instrumentation-langchain

Python instrumentation for LangChain-compatible callback flows. It emits
Respan/Traceloop spans through `respan-tracing`, so LangChain chains, chat
models, tools, retrievers, LangGraph runs, and Langflow components that execute
LangChain/LangGraph callbacks are exported into the normal Respan trace pipeline.

## Configuration

### 1. Install

```bash
pip install respan-instrumentation-langchain
```

### 2. Set Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `RESPAN_API_KEY` | Yes | Your Respan API key. |
| `RESPAN_BASE_URL` | No | Defaults to `https://api.respan.ai`. |

## Quickstart

### 3. Run Script

```python
from respan import Respan
from respan_instrumentation_langchain import LangChainInstrumentor

respan = Respan(instrumentations=[LangChainInstrumentor()])

chain.invoke({"question": "hello"})
respan.flush()
```

For explicit per-run callbacks:

```python
from respan_instrumentation_langchain import add_respan_callback

chain.invoke(
    {"question": "hello"},
    config=add_respan_callback({"tags": ["demo"]}),
)
```

The same config helper works with LangGraph:

```python
graph.invoke(
    {"messages": [{"role": "user", "content": "hi"}]},
    config=add_respan_callback({"configurable": {"thread_id": "thread-1"}}),
)
```

Langflow custom components can use `get_callback_handler()` or
`add_respan_callback()` when invoking LangChain or LangGraph objects.

### 4. View Dashboard

After running the script, traces appear on your [Respan dashboard](https://platform.respan.ai).

## Further Reading

- [Example projects](https://github.com/respanai/respan-example-projects)

