What you will be able to do
- Read a Databricks agent trace span by span and check whether any later step depends on an earlier output
- Pick out content that is usually safe to remove during compaction: superseded reasoning, redundant tool outputs and resolved sub-tasks
- Spot content that looks old but still matters downstream, and tell compaction apart from trace redaction
Key concept
Downstream-dependency test — You can remove a piece of context during compaction only if no later step needs it, either as an input or as a fact that decides what the agent does next. The test is about dependency, so how old the content is doesn't settle it.
1.What compaction decides, and what it works on
An agent that runs for a long time builds up context: user messages, its own reasoning, tool calls and the results those calls return. A base model can only see what fits in its context window. So the harness around the model has to choose what stays word for word, what gets shortened, and what gets dropped. Databricks' AI harness article calls this summarize-and-continue step context compaction. It is a choice about what stays active, and summarizing is only part of it.
Checkpoint 1 of 7· Check yourself
According to Databricks' AI harness article, what does the harness decide as conversations grow longer?
The harness manages memory within a task and decides what stays active versus what gets summarized. Databricks names this process context compaction.
“As conversations grow longer, the harness decides what stays active and what gets summarized, a process known as context compaction.”Source: www.databricks.com
Compaction works on the session state. Databricks describes this as the working transcript that the agent replays to continue an interaction. Most of that transcript is tool calls and tool results, and those are also what take up the most tokens. This lesson teaches one skill: given a trace of that transcript, decide which parts can go without changing what the agent does next. Diagnosing a compaction that went wrong, tuning the compaction prompt, and weighing aggressive against conservative compaction are separate objectives. This lesson only asks one question: is this content safe to remove?
2.Reading a trace for downstream dependencies
A Databricks agent trace, recorded by MLflow Tracing, is a tree of spans. The root span is the whole request. Each child span is one LLM call, retriever lookup or tool call, with its inputs and outputs recorded. That structure is what makes it possible to judge compaction. For each earlier output, look forward through the trace and ask whether any later span used it as an input, or whether any later reasoning step relied on it to make a decision.
Every output falls into one of three groups. Consumed and still live: a later step used it, and work that hasn't happened yet will need it again, such as an order ID that is about to be used to create a return label. Consumed and finished: a later step used it, its result is now recorded somewhere else, and nothing ahead depends on the raw content. Never consumed: nothing used it, for example a retrieval result the agent ignored. The second and third groups are where you can safely remove content. The first group has to stay word for word, or as an exact fact inside a summary.
Checkpoint 2 of 7· Match them up
Match each Databricks term to what it holds
Tap a term, then the definition that fits it.
Spans carry the inputs and outputs you check for dependencies. The session transcript is what compaction shrinks. Memory sits outside the session and survives when the session is cleared.
“Each span represents one operation: it records what went in, what came out, how long it took, and any metadata.”Source: docs.databricks.com
Checkpoint 3 of 7· Exam question
An agent trace shows three consecutive tool calls to a code-search tool: the first two calls returned network timeout errors, and the third call succeeded and returned the needed function definition. The agent's next message uses only the result from the third call. During compaction, which content is safe to remove without affecting downstream task execution?
Correct answer: A — The two failed tool calls and their timeout error messages
- A. Correct. The two failed attempts were superseded by the successful third call, and nothing later in the trace depends on the timeout errors or the retries themselves, so they can be dropped without losing information the agent still needs.
- B. Incorrect. The successful result is the one piece of tool output the agent actually relies on going forward, so removing it would strip the fact the downstream reasoning needs.
- C. Incorrect. The original request defines the task's goal and is needed to judge whether the final answer satisfies it; removing it risks the agent losing track of what it was asked to do.
- D. Incorrect. This message is the agent's current working conclusion built on the retrieved definition; discarding it would remove active reasoning still in use, not superseded content.
3.Content that passes the test: superseded, redundant, resolved
Most of what you can safely remove falls into three categories. Superseded reasoning: plans and intermediate thoughts that a later decision replaced. Once the agent has settled on a plan, the first draft of that plan no longer drives anything. Redundant tool outputs: repeated or overlapping calls whose results also appear later in the trace, plus large payloads where the agent only used a few fields. You can drop the bulky payload as long as the fields the agent used are kept. Resolved sub-tasks: a self-contained piece of work, such as the failed call and retry above, whose outcome is already recorded. Keep the outcome, for example 'order 123 confirmed eligible', and drop the steps that produced it.
In the Databricks call-center example, the agent plans, looks up the order and the policy, checks the return window, triggers the return and then responds. Look at that trace just before the response step. The full policy document and the raw database row have done their job. What the response still needs is the result: the order is eligible, and a label was created.
| Trace step | What it produced | Safe to remove before the response? |
|---|---|---|
| Reason and plan | Plan: look up the order, check the return policy | Yes. The steps that followed carried out and replaced the plan |
| Find information (data intelligence) | Order record and policy document text | Mostly. Keep the order identity and the eligibility facts, drop the raw document |
| Reason (return-window check) | Eligible or escalate to a human | No. Keep the decision, because it controls what the agent says |
| Action | Return triggered, shipping label generated | No. The response hands this label to the customer |
Checkpoint 4 of 7· Check yourself
Databricks' design guidance names one specific risk that a single-agent system must guard against, compared with a hard-coded chain. If compaction removes a tool result that the agent still needs, which risk does it make more likely?
A single agent decides for itself whether to call a tool. If a result it still depends on has been removed, it can call the same tool again, which is the repeated-call risk Databricks warns about.
“Compared to a hard-coded chain, you must guard against repeated or invalid tool calls.”Source: docs.databricks.com
Checkpoint 5 of 7· Exam question
A Databricks agent trace includes a tool call that retrieved a 50,000-row query result table. The agent's very next reasoning step states three aggregate totals it computed from that table, and only those totals are used for the remainder of the trace. During compaction, which content is safe to remove without affecting downstream task execution?
Correct answer: A — The raw 50,000-row result, already summarized into the totals
- A. Correct. Every value the downstream steps rely on has already been distilled into the three totals, so the bulky raw row data is redundant and can be dropped without losing information.
- B. Incorrect. These totals are exactly the values later steps consume; removing them would delete the only surviving record of what the raw data actually contained.
- C. Incorrect. The original question anchors what the totals are supposed to answer, and downstream evaluation of correctness depends on knowing what was asked.
- D. Incorrect. This is the agent's current deliverable to the user, not superseded content, so removing it would discard active output rather than redundant history.
Sources5
4.Content that looks removable but isn't
The costly mistakes come from content that looks finished but still controls later behavior. Examples: a constraint the user stated early on ('never ship to the PO box'); a guardrail or human-approval result, such as the agent's decision to escalate to a human; an identifier that a later action will pass as an argument; and a fact the agent checked and turned down, where removing it would let the agent reconsider that option. These items are small, so keeping them costs little, and removing them can change what the agent does. A useful habit is to separate the result from how the agent got there. You can usually drop the steps that produced a result, but you have to keep the result itself.
Some facts should still matter after the session ends. Databricks' managed memory gives those facts a home outside the session. As a session accumulates, the agent or application can extract durable facts and write them to memory, so the session transcript can later be shortened or cleared without losing them.
One more distinction shows up on the exam. Redacting a trace and compacting context are different operations. MLflow span processors, and ai_mask pipelines run on stored traces, change what is written to the trace record. Databricks states that the agent still receives and returns the original content. Removing something from the stored trace does nothing to shrink the agent's context window. Compaction has to happen in the harness, on the session state the agent replays.
Checkpoint 6 of 7· Check yourself
A team registers an MLflow span processor that replaces every TOOL span output with [REDACTED]. What happens to the agent's own working context?
Span processors change trace data before it is exported. The agent still sees the full content, so this is not compaction.
“the agent itself still receives and returns the original, unredacted content.”Source: docs.databricks.com
Run the compacted conversations through MLflow's multi-turn scorers. KnowledgeRetention checks whether the agent still uses information from earlier turns. ToolCallEfficiency-style scorers flag duplicate tool calls, which suggest a needed result was removed.
Checkpoint 7 of 7· Exam question
An agent trace shows a retrieval step that returned five document chunks from Databricks AI Search for a policy question. The agent's answer cites and quotes only chunk 2; chunks 1, 3, 4, and 5 are never referenced again anywhere in the trace. During compaction, which content is safe to remove without affecting downstream task execution?
Correct answer: A — The four unused chunks not referenced again in the trace
- A. Correct. Chunks 1, 3, 4, and 5 were retrieved but never used in reasoning or in the final answer, so they are redundant retrieval results that can be discarded without any loss of used information.
- B. Incorrect. This is the chunk the answer actually quotes; removing it would strip the source evidence the final answer relies on.
- C. Incorrect. The original question is needed to verify the answer addressed the right policy topic and to support any follow-up questions in the same session.
- D. Incorrect. This is the agent's live deliverable built from the cited chunk, not superseded retrieval noise, so it should be preserved.
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.Once a tool has returned its result, the tool call and its output are always safe to remove.Why is that wrong?
A tool result is only safe to remove once nothing ahead depends on it. If the agent still needs it, it may call the tool again, which is the repeated-call risk Databricks says single agents must guard against.
Covered in Content that passes the test: superseded, redundant, resolved
2.Redacting or masking tool outputs in MLflow traces reduces the agent's context, so it counts as compaction.Why is that wrong?
Trace redaction only changes what is recorded. The agent still receives the full content, so compaction has to happen on the session state in the harness.
Covered in Content that looks removable but isn't
3.Facts from early turns are old, so they are the safest content to remove.Why is that wrong?
Age doesn't make content safe to remove. Durable facts such as stated preferences or past decisions should be extracted and kept, for example in memory, before the transcript is shortened.
Covered in Content that looks removable but isn't
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Most commonly this is the conversation history (the ordered transcript of messages, tool calls, and results)”
↩︎ What compaction decides, and what it works on“As a session accumulates, an agent (or your application) distills the durable facts out of it and writes them to memory.”
↩︎ Content that looks removable but isn't“As a session accumulates, an agent (or your application) distills the durable facts out of it and writes them to memory.”
↩︎ Exam trap 3 - 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 compaction decides, and what it works on - 3.
“Each span represents one operation: it records what went in, what came out, how long it took, and any metadata.”
↩︎ Reading a trace for downstream dependencies“Each span represents one operation: it records what went in, what came out, how long it took, and any metadata.”
↩︎ Key concept - 4.
“With only an input and final response, you cannot tell which intermediate decision caused a failure.”
↩︎ Reading a trace for downstream dependencies - 5.
“Find information (data intelligence): The agent queries the order database to retrieve the relevant order and references a policy document.”
↩︎ Content that passes the test: superseded, redundant, resolved“Integrate tool outputs into the conversation.”
↩︎ Content that passes the test: superseded, redundant, resolved“If the item falls into a certain category or is outside the normal return window, escalate to a human.”
↩︎ Content that looks removable but isn't“Compared to a hard-coded chain, you must guard against repeated or invalid tool calls.”
↩︎ Exam trap 1“Iterate if needed, calling an LLM or tools repeatedly until an objective is achieved or a certain condition is met”
↩︎ Prediction“Compared to a hard-coded chain, you must guard against repeated or invalid tool calls.”
↩︎ Checkpoint - 6.
“mlflow.genai.scorers.KnowledgeRetention - Retention of information from earlier turns”
↩︎ Content that looks removable but isn't
Also cited
“the agent itself still receives and returns the original, unredacted content.”
↩︎ Exam trap 2“the agent itself still receives and returns the original, unredacted content.”
↩︎ Checkpoint