Metadata-Version: 2.4
Name: langchain-distil
Version: 0.1.0
Summary: Reversible distil context compression for LangChain and LangGraph
Project-URL: Homepage, https://github.com/dshakes/distil
Project-URL: Repository, https://github.com/dshakes/distil
Author-email: shakes <chandu1221@gmail.com>
License-Expression: MIT
Keywords: agents,compression,distil,langchain,langgraph,tokens
Requires-Python: >=3.9
Requires-Dist: distil-llm>=1.19.0
Provides-Extra: runnable
Requires-Dist: langchain-core>=0.3; extra == 'runnable'
Provides-Extra: test
Requires-Dist: pytest>=8; extra == 'test'
Description-Content-Type: text/markdown

# langchain-distil

Reversible [distil](https://github.com/dshakes/distil) context compression for LangChain
and LangGraph.

distil compresses an agent's accumulated messages before the model call: tool/function
messages get a reversible digest, human/system messages get lossless compression, and the
model's own (ai/assistant) messages are never rewritten. Originals persist in a local
handle store and are recoverable via distil's `distil_expand` MCP tool or
`distil.mcp_server.load_restore(handle)`.

Decision-equivalence between compressed and full context is certified separately, offline,
by `distil bench` / `distil validate`. This package performs the compression only.

## Install

```bash
pip install langchain-distil                 # message-dict hooks
pip install "langchain-distil[runnable]"     # + as_runnable() (needs langchain-core)
```

## Usage

LangGraph — drop distil in as a `pre_model_hook`:

```python
from langgraph.prebuilt import create_react_agent
from langchain_distil import pre_model_hook

agent = create_react_agent(model, tools, pre_model_hook=pre_model_hook())
```

Any message list — compress before `.invoke`:

```python
from langchain_distil import compress_messages

resp = model.invoke(compress_messages(messages))
```

As a Runnable in a chain:

```python
from langchain_distil import as_runnable

chain = as_runnable() | model
```

`verbatim=True` selects Tier-0 lossless mode (no digest stubs).

## License

MIT
