Get to know Cadenya
We’re developers who love to build. We set out to create a yes-code platform that makes building agents feel like the best parts of building software.
Context compaction keeps a long-running agent inside its context window: when the conversation grows too long, the older turns get summarized or cleared, and the recent ones stay word for word. The Claude API and the OpenAI Responses API compact on the server; Mastra, Google ADK, Spring AI, and LangGraph compact inside your framework; and Cadenya compacts inside the hosted agent loop it runs, from a compaction config on the variation.
So pick Claude API compaction or OpenAI Responses API compaction when you call one model provider directly and want it to write the summary. Pick Mastra observational memory, ADK’s EventsCompactionConfig, Spring AI chat memory, or LangGraph’s SummarizationMiddleware when your agent already lives in that framework and you’re fine storing the conversation in your own database. And if you’d rather host nothing, Cadenya is a hosted agent loop that keeps the conversation in a durable event log, compacts it when input tokens reach a share of the model’s context window, and compacts on demand through one endpoint. A coding agent can set it up with no account, in a temporary workspace you claim later. What it offers is at the end.
Every price and limit below comes from each vendor’s own pages, checked on November 11, 2026.
Claude API vs OpenAI vs Mastra vs ADK vs Spring AI vs LangGraph compaction
Here’s how the six options agents compare line up:
| How it compacts | What triggers it | Where the conversation lives | Long-term memory | License or price | |
|---|---|---|---|---|---|
| Claude API | Claude writes a summary into a compaction block. Context editing clears old tool results | Input tokens reach your trigger (150,000 by default), or your own compaction request | Your app, which resends the messages | The memory tool, run by your code | Tokens. Compaction adds a sampling step |
| OpenAI Responses API | An encrypted compaction item, written on the server | compact_threshold, or a call to /responses/compact | Your input array, previous_response_id, or a Conversation | Your own, through tools | Tokens. The whole chain bills as input |
| Mastra | Observational memory: an Observer writes observations, and a Reflector condenses them | 30,000 message tokens, then 40,000 observation tokens, by default | A storage provider you configure | Working memory and semantic recall | Apache 2.0, except ee/ folders |
| Google ADK | EventsCompactionConfig summarizes older session events | A token threshold, or a set number of invocations | A session service, such as DatabaseSessionService on PostgreSQL | MemoryService, a searchable archive | Apache 2.0 |
| Spring AI | MessageWindowChatMemory evicts whole turns. spring-ai-session adds summarization | 20 messages by default, or turn and token triggers | A chat memory repository: in memory, JDBC, Cassandra, Neo4j | A vector store, through VectorStoreChatMemoryAdvisor | Apache 2.0 |
| LangGraph and LangChain | SummarizationMiddleware, or trim messages | Tokens, messages, or a fraction of the context window | A checkpointer, such as PostgresSaver | Stores, with semantic search | MIT |
| Cadenya | Tool result clearing, then summarization, from a compaction config on the variation | 75% of the model’s context window by default, or the Compact an objective endpoint | A durable event log per objective, on Cadenya | Memory layers, plus episodic memory by episodic_key | Free for 1,000 loops a month. Growth is $49 a month for 50,000, then $0.0015 a loop |
LangGraph’s docs name the split most plainly. Checkpointers hold “short-term, thread-scoped memory.” Stores hold “long-term, cross-thread memory, including user preferences, facts, and shared knowledge.” Compaction works on the short-term side: it shrinks the thread, and something still has to store it.
Claude API compaction and context editing
“Compaction replaces the older turns of a conversation with a summary that Claude writes on the server, so you need no summarization code of your own.” It comes in two kinds.
Compaction at a token threshold uses the compact-2026-01-12 header and a compact_20260112 edit on ordinary requests:
response = client.beta.messages.create(
betas=["compact-2026-01-12"],
model="claude-opus-5-5",
max_tokens=4096,
messages=messages,
context_management={"edits": [{"type": "compact_20260112"}]},
)
Compaction “starts at 150,000 input tokens by default,” and a custom trigger “must be at least 50,000 tokens.” You append the response as usual, and “the API automatically drops all content blocks prior to the compaction block.”
Compaction on demand uses compact-2026-09-04. Your app sends "compaction": {"type": "summarize"}, and Claude “returns a summary in place of a reply.” Claude Managed Agents compacts for you: it’s “always on.”
Context editing is the other half. The clear_tool_uses_20250919 strategy “clears tool results when conversation context grows beyond your configured threshold,” and leaves placeholder text in their place. Summaries cost tokens: “Compaction requires an additional sampling step, which contributes to rate limits and billing.”
Long-term memory stays on your side. “The memory tool operates client-side: Claude requests file operations, and your application runs them.”
Claude compaction through LiteLLM passthrough
LiteLLM offers “pass-through endpoints for Anthropic,” which call the provider “in native format (no translation).” You replace https://api.anthropic.com with LITELLM_PROXY_BASE_URL/anthropic. On its own completion API, LiteLLM “forwards the native context_management payload when you call Anthropic models” and attaches the context-management-2025-06-27 header.
OpenAI Responses API compaction: compact_threshold and /responses/compact
The Responses API takes a context_management setting on an ordinary request:
response = client.responses.create(
model="gpt-5.3-codex",
input=conversation,
store=False,
context_management=[{"type": "compaction", "compact_threshold": 200000}],
)
“When the rendered token count crosses the configured threshold, the server runs server-side compaction.” The compaction item “is opaque and not intended to be human-interpretable.” The standalone /responses/compact endpoint “is fully stateless.”
The OpenAI Agents SDK wraps it in OpenAIResponsesCompactionSession, which “can automatically compact after each turn.”
On the Claude Messages API you resend the messages each turn, while OpenAI’s Conversations API can store the thread for you. It keeps the thread “as a long-running object with its own durable identifier.” But “all previous input tokens for responses in the chain are billed as input tokens,” even with previous_response_id. OpenAI Agents SDK sessions covers the session types.
Mastra memory and observational memory
Mastra recommends observational memory, which “uses background agents to maintain a dense observation log that replaces raw message history as it grows.” Two background agents share the work:
- The Observer takes notes. “When message history tokens exceed a threshold (default: 30,000), the Observer creates observations.”
- The Reflector condenses them. At 40,000 tokens of observations, it “condenses them and combines related items.”
Mastra says “the compression is typically between 5x and 40x.” Working memory “stores persistent, structured information about the user, the application, or the task,” and semantic recall finds old messages by meaning.
The database is yours. “Memory requires a storage provider to persist message history.” Mastra for AI agents covers the rest of the framework.
Google ADK EventsCompactionConfig
ADK compacts session events “based on the rules you set in the EventsCompactionConfig.” It offers two strategies: token-based, which “triggers cleanup based on the actual volume of tokens consumed,” and a sliding window, which runs “after a fixed number of conversational turns.” Set both, and “the system prioritizes token-based compaction.”
The Python version looks like this:
from google.adk.apps.app import App, EventsCompactionConfig
app = App(
name="my_compacting_agent_app",
root_agent=root_agent,
events_compaction_config=EventsCompactionConfig(
token_threshold=4000,
event_retention_size=5,
),
)
Past 4,000 tokens, ADK summarizes older events and keeps the 5 most recent ones raw.
The session store is your choice. With InMemorySessionService, “all conversation data is lost if the application restarts.” DatabaseSessionService “connects to a relational database (e.g., PostgreSQL, MySQL, SQLite).” Google ADK agents in Python and ADK for Go go further.
Spring AI chat memory and compaction
Spring AI’s default is MessageWindowChatMemory, which “maintains a sliding window of messages up to a specified maximum size.” “The default window size is 20 messages,” and it “always removes whole turns rather than cutting mid-turn.” So it evicts. It doesn’t summarize.
Messages go to a chat memory repository. The default is in memory, and Spring AI picks up Cassandra, JDBC, or Neo4j when one is configured. One gotcha: “JdbcChatMemoryRepository does not support tool call messages.”
For summarization, the spring-ai-community project spring-ai-session adds “event-sourced session management with context compaction.” It ships TurnCountTrigger, TokenCountTrigger, and a RecursiveSummarizationCompactionStrategy that “uses a ChatClient to summarize the events being archived.” AI agent frameworks in Java compares the JVM options.
LangGraph SummarizationMiddleware, Pydantic AI, and the AI SDK
LangChain packages summarization as middleware on create_agent:
from langchain.agents import create_agent
from langchain.agents.middleware import SummarizationMiddleware
agent = create_agent(
model="gpt-5.5",
tools=[...],
middleware=[
SummarizationMiddleware(
model="gpt-5.4-mini",
trigger=("tokens", 4000),
keep=("messages", 20),
),
],
)
Past 4,000 tokens, a smaller model summarizes the thread, and the last 20 messages stay word for word. A trigger can also be a fraction of the model’s context size. Trimming is cheaper, but “you may lose information from culling of the message queue.”
The thread needs a home. InMemorySaver keeps checkpoints in RAM, and “when the process restarts, all checkpoints are lost.” So the docs say to “use a checkpointer backed by a database,” such as PostgresSaver. LangGraph in production covers that setup.
Pydantic AI wraps OpenAI and Anthropic compaction as capabilities and adds model-agnostic strategies in Pydantic AI Harness, where “all strategies preserve tool-call / tool-return pairing.” Storage stays yours: “Deciding where those bytes live, which conversation they belong to, and when to reload them is left to your application.” The AI SDK uses prepareStep, which “is useful for compaction, and you decide when compaction should happen,” with pruneMessages as the built-in helper.
What does Cadenya offer that the Claude API, OpenAI, Mastra, ADK, Spring AI and LangGraph don’t?
The model APIs shrink the context you send, and the frameworks compact a thread you store in your own database. Cadenya keeps the conversation, compacts the context window, and serves long-term memory inside the hosted agent loop it runs. Here’s what that covers:
- A compaction config on the variation. Set it once, and compaction triggers “when input tokens reach this percentage of the model’s limit,” 75% by default. The trigger is a share of the model’s context window, not a fixed token count.
- Tool result clearing, then summarization. Clearing keeps the 2 most recent tool results by default and replaces older content with
[result cleared], while the tool call itself stays. With neither strategy set, Cadenya summarizes with its default prompt. - Your own summarization instructions. Replace the default prompt with what must survive, such as “Preserve all code snippets, variable names, and technical decisions.”
- Compaction on demand. Call the Compact an objective endpoint (
client.objectives.compact(...)orcadenya objectives compact), with an optional config override for that call. A waiting objective compacts at once, and a busy one compacts before its next assistant turn. - Every compaction on the record. “Every Objective carries a durable event log of its agent loop.” A
contextWindowCompactedevent names the strategies used and the number of messages compacted. A context usage call breaks down the latest request by component. - Conversations that pick up where they left off. When an objective waits, send a Continue message to resume the loop. Widget sessions with the same tenant and subject share history across tabs.
- Long-term memory layers. Entries hold text or uploaded files, each with a key. The agent sees each key and description in its system prompt, reads the full entry when it needs it, and every read shows up as a
memoryReadevent. - Episodic memory across objectives. Objectives that share an
episodic_keygetstore_memory,get_memory, andsearch_memorytools, and each new objective moves the TTL forward. - One price, and your model keys. Free covers 1,000 loops a month. Growth is $49 a month for 50,000 loops and memory layers, then $0.0015 a loop. You connect your own provider keys, and SDKs for TypeScript, Python, Ruby, and Go are all at 1.9.0 under Apache-2.0.
Compact an objective shows the endpoint and the compaction config, and the free plan needs no card.
No account yet? A coding agent can create a temporary workspace with cadenya workspaces create --temporary, run its first objectives there, and hand you a link to claim it, as auth.md explains. To create an account, sign up at app.cadenya.com/signup, then copy your API key from the API keys page at app.cadenya.com/account/apiKeys.
Related articles
- Mastra for AI agents (2026)Mastra
- Cloudflare Agents SDK: AIChatAgent, resumable streaming and tool approvalCloudflare Agents SDK
- Google ADK agents in Python (2026)Google ADK
Grow wherever AI goes next.
Start shipping agents that are equipped to evolve.