Integration guide
LangChain prompt compression integration
Add SuperCompress to any LangChain application with a custom callback handler. Every LLM call in your chain automatically gets compressed context.
Installation
pip install supercompress langchain
Callback handler for LangChain
from supercompress import Compressor
from langchain.callbacks import BaseCallbackHandler
class CompressionHandler(BaseCallbackHandler):
def __init__(self):
self.comp = Compressor()
def on_llm_start(self, serialized, prompts, **kwargs):
result = self.comp.compress(prompts[0].text, "Continue.")
prompts[0].text = result.compressed_text
Using with LangChain agents
from langchain.agents import create_react_agent
agent = create_react_agent(llm, tools, prompt)
agent.callbacks = [CompressionHandler()]
Frequently asked questions
Does this work with LangChain streaming?
Yes. Compress first, then stream normally.
Can I use it with LangGraph?
Yes. Add the CompressionHandler to any node that calls an LLM.
Build with less context
Put compression in front of your next LLM call.
Use the hosted API or run SuperCompress locally. Keep the evidence, drop the token waste, and measure the savings before it reaches your model.