Framework integration

LangGraph compression

LangGraph builds stateful, multi-step LLM workflows. Each node receives the full state, which grows with every step. Compression keeps state compact.

By Arjun Shah - Creator of SuperCompress - Updated 2026-07-03

LangGraph state compression

from langgraph.graph import StateGraph
from supercompress import Compressor

comp = Compressor()

def compress_state(state, next_node_query):
    "Compress the accumulated state before the next node."
    compressed = comp.compress(
        state.get("accumulated_context", ""), next_node_query
    )
    state["accumulated_context"] = compressed.compressed_text
    return state

# Add to your LangGraph workflow
graph = StateGraph(AgentState)
graph.add_node("compress", compress_state)
graph.add_edge("compress", "next_node")

Frequently asked questions

Should I compress at every node?

Yes. Compress before each node execution to prevent state bloat across multiple steps.

Does compression affect LangGraph's persistence?

No. The compressed state is persisted like any other state field.

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.

Get an API keyRead the guide