Skip to main content

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)

Source distribution for langchain-distil 0.1.0
File Size Uploaded
langchain_distil-0.1.0.tar.gz 120.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-distil 0.1.0
File Interpreter ABI Platform
langchain_distil-0.1.0-py3-none-any.whl Python 3 none any Details

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}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page