What you will be able to do
- Explain what aggressive and conservative compaction each trade away, in token cost and in fidelity
- Recognise the symptoms of compaction that was too aggressive for the task, such as repeated tool calls and contradicted conclusions
- Set compaction aggressiveness from how sensitive a task is to nuance, exact values and long-range constraints, including settings between the two extremes
- Plan a sweep that puts each compaction setting on a cost axis and a fidelity axis so you can pick the cheapest setting that keeps quality
Key concept
Compaction aggressiveness — How much of the earlier conversation survives when an agent summarizes its history and carries on from the summary. Aggressive settings keep little and cost fewer tokens on every later turn. Conservative settings keep more detail, so the agent stays more faithful to what came before but costs more per turn.
1.What the compaction dial trades
Compaction replaces an agent's long history with a summary, and the agent carries on from that summary. The real design choice is how much the summary keeps. At the aggressive end, the summary is short, it fires early, and it keeps almost nothing word for word. At the conservative end, it keeps decisions, qualifications, identifiers and recent turns in detail, and it fires later. Neither end is free. One end costs tokens and the other costs fidelity.
The cost side compounds because history is sent again on every turn. This is per-turn context accumulation: whatever stays in context gets billed again with each new message. So the compaction setting is a per-turn price, not a one-off saving. If a conservative summary is 8,000 tokens and an aggressive one is 1,500, the gap is 6,500 tokens on every remaining turn. Over a 40-turn task, that adds up to the main line on the bill. An agentic task makes it worse, because a single user request can run several model turns.
Even a conservative setting still compacts. It summarizes less hard, but it still summarizes, and what it keeps is still re-sent every turn. The only thing that empties a context completely is starting fresh. Databricks Genie Code shows this split: it compacts long chats automatically, but only a new chat clears them.
Checkpoint 1 of 7· Check yourself
A team's long-running agent uses aggressive compaction and keeps losing earlier qualifications, so the team switches it to conservative compaction for the rest of a 40-turn task. What changes?
Conservative compaction still summarizes. It just keeps more, and that bigger summary goes back to the model on every turn, so the extra cost repeats with each turn instead of being paid once. Only starting fresh clears the context completely.
“Each turn re-sends the whole chat's context to the model”Source: docs.databricks.com
2.What aggressive compaction loses, and how it shows
Aggressive summaries lose the subtle things first. A short summary keeps the headline, such as "investigating a failed pipeline", and drops what sits under it: which tool calls already ran, what each one returned, which hypotheses were ruled out, and why. Once those are gone, the agent cannot tell that a step is already done, so it does it again. When it re-derives a conclusion from scratch, it can land somewhere different, and the result is a contradiction within the same session.
These symptoms are not bad luck that happens alongside the cost savings. They are the risk the team accepted when it chose an aggressive setting. Multi-step debugging needs fine-grained continuity: step 12 depends on the exact outcome of step 4. A setting that worked for a chat assistant is too lossy for this kind of task. The fix is to move the dial toward conservative. Making the summaries even shorter would remove more of the continuity the task needs. To work out which category of information was dropped, use compaction failure diagnosis.
Losses at this stage are hard to undo. A Databricks memory store keeps durable facts that carry across sessions. It is not a backup of the qualifications negotiated in the current conversation, and it only holds what something chose to write into it. Dropping turns by a fixed rule loses information too. A rule that drops the oldest turns discards whatever those turns held, whether it mattered or not. Any method that removes context to save tokens can lower quality when the removed context was important.
Checkpoint 2 of 7· Check yourself
Midway through a session, a debugging agent on aggressive compaction reruns queries it already ran and names a different root cause from the one it reached earlier. Which response deals with the cause?
Repeated steps and contradictions are the expected cost of a setting too lossy for multi-step debugging, so the fix is to keep more continuity. The memory store holds durable facts that carry across sessions, not this session's dropped details. Dropping the oldest turns throws away important context just as a short summary does.
“quality may be reduced if important context is filtered out.”Source: docs.databricks.com
Checkpoint 3 of 7· Exam question
An engineering team deployed an agent for multi-step data-pipeline debugging with aggressive compaction to minimize cost. After several summarization passes, the agent began repeating tool calls it had already run and contradicting root-cause conclusions it had reached earlier in the same session. What does this outcome illustrate about the compaction tradeoff the team made?
Correct answer: A — The team accepted a level of context-loss risk from aggressive compaction that was too high for a task requiring fine-grained continuity across many steps
3.Setting the dial from the task's sensitivity
Set the dial by how far the task's dependencies reach back, not by how important the task feels. Ask what a later turn needs from an earlier one. Some tasks need nuance that does not survive paraphrase, exact values such as IDs, amounts or thresholds, or constraints set early that must still hold dozens of turns later. Those tasks need a conservative setting. Other tasks have loose, local dependencies, where each turn mostly stands on its own. Those tolerate aggressive compaction, and a conservative setting would just pay for tokens nobody uses.
Legal drafting is the clear conservative case. Suppose a memo agent agrees in turn 6 that a clause applies "except for subcontractors engaged before the effective date". That exception is exactly the kind of detail a short summary flattens into "clause applies". When accuracy matters more than token cost, choose conservative compaction and accept the higher cost per turn as the price of keeping that wording.
Most real agents are mixed, so the best setting usually sits between the two ends, and it can vary by kind of information. Write the compaction prompt so that it summarizes routine exchanges briefly but copies a named set of items word for word, such as open order numbers, negotiated terms and unresolved errors. That gives you aggressive compaction for most of the history and conservative handling for the parts that last. Databricks memory pipelines draw a similar line for long-term memory. They keep explicit corrections and preferences, skip details the agent can look up again with its tools, and record how to find or compute a changing value rather than the value itself. For which raw content can safely be removed, see safe content removal.
| Dependency pattern | Example task | Setting | What goes wrong if set the other way |
|---|---|---|---|
| Nuanced qualifications agreed earlier | Drafting legal memoranda over dozens of turns | Conservative | Aggressive: exceptions and conditions get flattened in the summary |
| Exact values and step-by-step continuity | Multi-step pipeline debugging | Conservative | Aggressive: repeated tool calls and contradicted root causes |
| Loose, local dependencies | Answering independent how-to questions | Aggressive | Conservative: tokens re-sent every turn for context nobody uses |
| Mostly routine, with a few long-lived details | Retail support with open orders | Between the extremes, keeping named items verbatim | Either extreme: lost order details, or full-fidelity cost on every routine turn |
Checkpoint 4 of 7· Match them up
An architect is setting compaction for four agents. Match each agent's task to the compaction setting that fits how its turns depend on earlier ones.
Tap a term, then the definition that fits it.
The setting depends on how far a task's dependencies reach back. Nuanced qualifications and step-by-step continuity need conservative compaction. Loose, local turns can take aggressive compaction. A mostly routine task with a few long-lived details is best served in between, keeping only the named items verbatim.
“apply compaction and trimming strategies so that agents can operate efficiently without losing essential information”Source: www.databricks.com
Checkpoint 5 of 7· Exam question
A team builds an agent that drafts legal memoranda over dozens of turns, where subtle qualifications negotiated earlier in the conversation must not be lost. Token cost is a secondary concern compared to accuracy. Which compaction approach should the team adopt, and why?
Correct answer: A — Conservative compaction, because it preserves higher fidelity of prior context even though it costs more tokens
Checkpoint 6 of 7· Exam question
A retail support agent occasionally needs to recall a customer's order history from many turns earlier, but most turns are routine and low-stakes. The team wants to avoid both the high cost of always preserving full fidelity and the risk of losing the occasional important order detail. Which conclusion best reflects sound tradeoff evaluation for this scenario?
Correct answer: A — Compaction aggressiveness should be tuned between the two extremes so that routine turns are compacted more aggressively while details tied to open orders are preserved with higher fidelity
Sources5
4.Measuring where fidelity starts to fall
Measure the tradeoff instead of guessing. Run a ladder of compaction settings, from aggressive to conservative, over the same evaluation dataset of long, realistic sessions. Use a controlled comparison with mlflow.genai.evaluate() so that the compaction setting is the only thing that changes between runs.
Give each setting two numbers. For cost, record the tokens of the compacted context per turn, using token cost metrics from traces, and use input tokens in particular, since that is where re-sent history shows up. For fidelity, record correctness on the tasks that depend on earlier context. Plot them together. Usually the curve stays flat as you compact harder, then drops at the point where the summary starts dropping something the task depends on. Pick the cheapest setting before that drop, and test the tasks with long-range constraints specifically, because an average over easy turns can hide the drop.
When the evaluation dataset does not include the long-range cases the agent will meet in production. For example, it may have no sessions where a constraint set early is tested 30 turns later. Matching scores then only show that the dataset never tested what the cheaper setting drops. Add those cases before trusting the result.
Checkpoint 7 of 7· Check yourself
An engineer runs four compaction settings over the same long-session dataset. A is the most aggressive and D the most conservative. Results: A uses 1,200 input tokens per turn, with 94% correctness over all turns and 62% on tasks with constraints set many turns earlier. B: 2,600 tokens, 95% and 89%. C: 4,100 tokens, 95% and 90%. D: 7,800 tokens, 96% and 91%. What should the engineer conclude?
Long-range correctness stays nearly flat from D down to B and then falls sharply at A. That drop is where the summary starts losing something the task depends on, so B is the cheapest safe setting. The overall average hides the drop, which is why the long-range tasks have to be tested separately. Re-sent history shows up in input tokens, not output tokens.
“Candidates are expected to measure how changes to context impact agent performance and use those insights to iterate and improve.”Source: www.databricks.com
Sources6
Sources
(7)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Each turn re-sends the whole chat's context to the model, and an agentic task runs several turns to plan, act, and check its work.”
↩︎ What the compaction dial trades“so the twentieth message in a chat costs more than the first”
↩︎ What the compaction dial trades“Genie Code automatically summarizes, compacts, and truncates long context, but only a new chat clears it completely.”
↩︎ Exam trap 1“The goal is to keep each chat's context relevant to the task at hand.”
↩︎ Exam trap 4“Each turn re-sends the whole chat's context to the model”
↩︎ Checkpoint“The goal is to keep each chat's context relevant to the task at hand.”
↩︎ Prediction - 2.https://www.databricks.com/blog/ai-harnessSecondary source
“As conversations grow longer, the harness decides what stays active and what gets summarized, a process known as context compaction.”
↩︎ What the compaction dial trades“As conversations grow longer, the harness decides what stays active and what gets summarized, a process known as context compaction.”
↩︎ Key concept - 3.
“quality may be reduced if important context is filtered out.”
↩︎ What aggressive compaction loses, and how it shows“quality may be reduced if important context is filtered out.”
↩︎ Exam trap 3 - 4.
“Agent memory stores durable facts, preferences, and decisions that an agent recalls in later, separate conversations, retrieved by semantic search.”
↩︎ What aggressive compaction loses, and how it shows“Agent memory stores durable facts, preferences, and decisions that an agent recalls in later, separate conversations, retrieved by semantic search.”
↩︎ Exam trap 2 - 5.
“Corrections and explicit feedback, such as which source to use for revenue figures.”
↩︎ Setting the dial from the task's sensitivity“Details that the agent can look up with its tools, such as a table's schema.”
↩︎ Setting the dial from the task's sensitivity“It records how to find or compute the value instead.”
↩︎ Setting the dial from the task's sensitivity - 6.https://docs.databricks.com/aws/en/agents/tutorials/ai-cookbook/evaluate-assess-performanceOfficial docs
“total_token_count, total_input_token_count, total_output_token_count”
↩︎ Measuring where fidelity starts to fall“Overall, did the agent generate a correct response?”
↩︎ Measuring where fidelity starts to fall
Also cited
“apply compaction and trimming strategies so that agents can operate efficiently without losing essential information”
↩︎ Checkpoint“Candidates are expected to measure how changes to context impact agent performance and use those insights to iterate and improve.”
↩︎ Checkpoint