langchain-distil
Reversible 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
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:
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:
from langchain_distil import compress_messages
resp = model.invoke(compress_messages(messages))
As a Runnable in a chain:
from langchain_distil import as_runnable
chain = as_runnable() | model
verbatim=True selects Tier-0 lossless mode (no digest stubs).
License
MIT
Metadata
Release files for langchain-distil 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_distil-0.1.0.tar.gz | 120.5 kB | Without provenance | Details for langchain_distil-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_distil-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for langchain_distil-0.1.0-py3-none-any.whl |
Total release size: 123.1 kB
Release files / langchain_distil-0.1.0.tar.gz
| Download URL | langchain_distil-0.1.0.tar.gz |
|---|---|
| Size | 120.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2de1d5fc432efcb41c4eed6544d1c675756ac1ac13fc3eb5322cefeaa64a1fa6
|
|
BLAKE2b-256 checksum How to use checksums |
499b03225dade27cefcb11f8e42775995197f045d9e7ad6a240561b67f787771
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / langchain_distil-0.1.0-py3-none-any.whl
| Download URL | langchain_distil-0.1.0-py3-none-any.whl |
|---|---|
| Size | 2.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e0185c8905ec7e04d6d5b4337e24f5df5305420945526017c1d4c9f796492c2
|
|
BLAKE2b-256 checksum How to use checksums |
806ad92ca46566a1d389a292c8eb5f84f1d2a2a9db6d696a27e7985300bfdd71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for langchain-distil 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.