Context compaction in Quarkus LangChain4j: eight strategies, one outage Quarkus LangChain4j 2.0 introduced a context-compaction extension with eight strategies that separates stored conversation history from the smaller view sent to the model, after a replayed incident showed default window-based chat memory evicting a critical constraint. In the fictional but test-replayed outage INC-20931, a Quarkus LangChain4j SRE assistant using the default MessageWindowChatMemory (last 10 messages) lost the instruction that eu-west-1 was frozen for a PCI audit until Friday and told the on-call engineer to restart pods there; tool output made up 73% of tokens across 17 tool calls in a two-and-a-half-hour incident. Sending the full conversation instead would have cost 221k prompt tokens for a roughly 9k-token chat, and the extension's default strategy summarizes earlier turns while keeping the full history in the ChatMemoryStore. "Yes, you can restart pods in eu-west-1. The rollback is complete…" That’s what the assistant answered. It was wrong. Elena is on call. Checkout returns HTTP 502 for 18% of requests. She opens incident INC-20931 and asks the team’s SRE assistant for help. Her first message sets the ground rules: Tomasz Wrona is the incident commander, and no pod restarts in eu-west-1, because the region is frozen for a PCI audit until Friday. The assistant is a Quarkus application: an @RegisterAiService interface with tools to query deployments, logs, config diffs, runbooks and metrics. Like most AI services, it uses the default chat memory of Quarkus LangChain4j. That memory keeps the most recent messages and evicts the rest: MessageWindowChatMemory keeps the last 10 messages by default, and TokenWindowChatMemory keeps as many as fit in a token budget. The memory needs a limit because every model has a context window : the most tokens it accepts in one call. And every call sends the conversation again. The incident lasts two and a half hours. The assistant calls tools 17 times. Most of the conversation is now tool output , the text a tool returns to the model: 73% of the tokens. Each new log and metric pushes older messages out of the window, and Elena’s first message is among them. So when she asks "Can we restart pods in eu-west-1?", the ground rule is gone, and the assistant gives the answer above. Asked who the incident commander is, it answers: "you are the incident commander." Elena knows she isn’t the commander, so that answer is harmless. The eu-west-1 one isn’t: it sounds plausible, and acting on it would break the audit freeze. The model doesn’t say "I don’t know." It answers, confidently, from what’s left. That’s the real cost of forgetting. Why not send everything? Over this conversation, the model would receive 221k prompt tokens for a chat of about 9k tokens. Every call pays again for the same logs, gets slower, and sooner or later exceeds the window. Long prompts also hurt answers when they fit: models find facts less reliably in the middle of a long prompt Lost in the Middle https://arxiv.org/abs/2307.03172 , and get worse as the input grows Context Rot https://research.trychroma.com/context-rot . Context compaction sits between the two: keep the conversation, send the model a smaller version of it. That’s what the new context-compaction extension, introduced in Quarkus LangChain4j 2.0, does. We’ll follow Elena’s outage through it: how it works, how to turn it on, what each strategy forgot, and how to test your own. Elena, her team and the outage are fiction, but the failure isn’t: it is inspired by a real situation we recently helped a user with. The model’s answers and the numbers below are real too: they come from replaying the conversation in a test, described in the results section eight-strategies . Elena’s assistant forgot because its memory did two jobs at once. It stored the conversation, and it decided what the model would see. To keep the prompt small, it deleted messages from the store. Once evicted, the ground rule was gone for good. Compaction splits those two jobs. The history is every message, untouched, in your ChatMemoryStore in memory, Redis, MongoDB… . Nothing is deleted to make room. The view is what the model receives. When the conversation gets too big, a strategy computes a smaller view from the history: it can prune tool outputs, summarize old turns, or drop them. The view is never written back. Let’s replay Elena’s outage, this time with the compaction extension and its default strategy instead of a window. Here is what the model saw two and a half hours in, when she asked about draining a region shortened : user: