What you will be able to do
- Apply the downstream dependency test to any item in a Databricks agent trace and decide whether compaction can remove it
- Recognise superseded, redundant and resolved content in a trace and explain why it usually passes the dependency test
- Spot trace items that look removable but have later steps depending on them, such as the original request, the consumed result and the final answer
Key concept
Downstream dependency test — A piece of trace content can be removed during compaction only if no later step reads it, references it or relies on it. Age, size and whether the content succeeded don't decide it. The only question is whether anything after it still needs it.
1.What compaction removes, and why the trace decides it
Compaction removes content from the agent's working context so that a long task can keep running inside the context window. Each removal is a bet that nothing later in the task needs what was dropped. Lose the bet and the agent continues without a fact it needed. It might re-run a search, contradict a constraint it was given, or answer a question nobody asked. You get the evidence for that bet from the agent trace.
On Databricks, an MLflow trace is a structured record of one complete execution of the agent. It holds every intermediate step, including LLM calls, retriever lookups and tool invocations, along with latency and any errors. Each step is a span that records what went into it and what came out. The trace view lays the spans out in execution order. That order is what you need here, because the question about any item is what happens after it.
The stored trace and the agent's context are two different things. Traces persist in Unity Catalog as Delta tables, and compaction doesn't delete anything from them. A failed call, a discarded draft or a huge raw result is still there for debugging after it leaves the context. "We might want to look at this later" is therefore never a reason to keep something in context. The only reason is that a later step of the task needs it.
Checkpoint 1 of 7· Check yourself
In a Databricks agent trace, a SQL tool call at step 2 failed with a timeout. Step 3 retried it and succeeded, and every later step uses only step 3's result. A teammate wants to keep the step 2 error in the agent's context in case the team wants to investigate the timeout later. What is the right call during compaction?
Compaction removes content from the agent's working context, not from the trace stored in Unity Catalog, so the error is still there for debugging. The only reason to keep something in context is that a later step needs it, and here no later step does. Age is not the test.
“Traces are stored in Unity Catalog as Delta tables (recommended).”Source: docs.databricks.com
2.The downstream dependency test
Content is safe to remove only if no later step in the trace reads it, references it or relies on it. To apply the test, take each candidate item and walk forward through the spans that follow it. Look for three kinds of dependency:
- A later step quotes or restates the content, such as an answer citing a document or a message repeating a computed value.
- A later step uses something only this content supplied, such as a table name, file path, function definition or record ID.
- A later step behaves as it does because of the content, even without mentioning it. A constraint the agent keeps respecting, or a requirement that shapes the final output, falls here.
If you find none of these, the item fails to earn its place and compaction can drop it. If you find even one, keep it, or keep the part the later step depends on. The span view makes this practical because inputs and outputs are visible for every step. You can check whether the value that appears in step 9 first entered the trace in step 4.
The retry case shows that the test looks forward, not backward. The timeouts happened, and they shaped the agent's behaviour at the time, since it retried. Once the third call succeeded, though, nothing after that point reads them. The success has no such luck. The agent's next message is built from it, so dropping it would leave that message referring to a definition that no longer exists anywhere in context.
| Trace item | Later step that depends on it | Verdict |
|---|---|---|
| User request that started the search | Every later step: it defines what the task is | Keep |
| Tool call 1 and call 2, both timeouts | None: the retry resolved them | Safe to remove |
| Tool call 3 and the returned function definition | The agent's next message uses it | Keep |
| Agent message using the definition | Later reasoning and the final output build on it | Keep |
Checkpoint 2 of 7· Check yourself
You are compacting a Databricks agent trace. At step 4 a lookup tool returned a 6,000-token JSON payload. The input of the SQL span at step 9 contains customer ID C-1182, and that ID appears nowhere else in the trace except in step 4's output. The final answer never quotes step 4. What should compaction do with step 4?
Quoting is only one kind of dependency. Step 9 uses a value that only step 4 supplied, so that part of step 4 has a dependent and must stay. You remove content, not whole tool messages, so the parts of the payload that nothing reads can still go. Size alone never decides it.
“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.Superseded, redundant and resolved content
Three kinds of content usually pass the dependency test, and recognising them is the fastest way to find what compaction can drop. Session history is an ordered transcript of messages, tool calls and results. Much of it falls into one of these kinds once the task has moved on.
Superseded content has been replaced by a later, smaller form that the rest of the trace uses instead. Picture a tool call that returns a 50,000-row query result. The agent's very next reasoning step states three aggregate totals computed from it, and only those totals appear for the rest of the trace. The totals now carry the dependency, and the raw rows have none, so the raw result is safe to remove. Its size makes the removal worth doing, but size isn't what makes it safe. The forward scan does that. The same logic covers an earlier draft of a SQL query that a corrected version replaced, or a plan the agent revised.
Redundant content was never used, or it duplicates something still in context. Suppose a retrieval step returns five chunks from Databricks AI Search for a policy question. The answer cites and quotes chunk 2, and chunks 1, 3, 4 and 5 never come up again. The four unused chunks are safe to remove and chunk 2 is not. What you remove is the content, not the whole tool message. A retrieval result or tool output can be split, keeping the part a later step depends on and dropping the rest. A second fetch of a table schema the agent already holds is redundant in the same way.
Resolved content is a problem or dead end the trace has already closed. Examples include timeouts that a retry got past, a permission error the agent fixed by switching to the correct catalog, or a hypothesis it tested and ruled out. The fix is what later steps build on. A dead end still matters only while it is a live warning, for example when the agent would otherwise try the same failing path again. In that case a later step does rely on it, and it fails the test.
Checkpoint 4 of 7· Check yourself
An agent is asked for Q3 revenue for EMEA and APAC only (step 1). Its SQL call against the dev catalog fails with a permission error (step 2). It switches to the prod catalog and gets back 40,000 raw rows (step 3). Its next reasoning step states the two regional totals (step 4), and the final answer quotes only those totals (step 5). Which content can compaction remove without affecting the rest of the task?
The error is resolved: the switch to the prod catalog fixed it, and the stored trace keeps the exception details. The raw rows are superseded: from step 4 on, the totals carry the dependency. The request is still needed because it sets the scope, and the totals are what the answer quotes. Being the source of the totals does not give the raw rows a dependent.
“the span is automatically marked as failed and the exception details are recorded in the span's Events tab”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.
Checkpoint 6 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.
Sources3
4.Content that looks removable but has later dependents
Some trace items look like clutter yet fail the dependency test, because the later step depending on them doesn't quote them. Lesson 6.1 covers these as the categories compaction must keep: goals and constraints, decisions and their rationale, identifiers, and unresolved issues. Here they are hard to spot because the dependency is easy to miss when you scan the trace.
A constraint stated once, early in the trace, is the classic case. Take "only use tables in the finance.certified schema." No later message repeats it, so a quick scan finds no references. Yet every later query the agent writes complies with it, and that compliance is a dependency. Identifiers are another case. A long tool output may be mostly noise but contain the one run ID or file path that a step much later passes as an argument. Drop the output wholesale and that later step breaks. Keep the identifier even when you discard everything around it.
Errors that remain unresolved belong here too. A failed write that the agent planned to retry after another step finishes has a dependent: the retry it hasn't made yet. With only the input and the final response, you can't see which intermediate step a failure came from. That is why the forward scan has to run over the spans themselves, not over the final answer.
Checkpoint 7 of 7· Check yourself
Mid-task, a teammate suggests a compaction shortcut. Compare the user's request with the agent's latest response, and drop every intermediate step that neither one mentions. The trace contains two such steps. Step 2 is the rule "only use tables in finance.certified", which no later message repeats. Step 5 is a failed write that the agent plans to retry once step 7 finishes. Which of these two steps must stay in context?
The shortcut checks only the request and the latest response, so it misses dependencies that never quote their source. Every query the agent writes still complies with the constraint, and the unresolved failed write is needed by the retry the agent has planned. Only a forward scan over the spans shows these dependencies.
“With only an input and final response, you cannot tell which intermediate decision caused a failure. With traces, you can inspect every step”Source: docs.databricks.com
Sources4
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“A trace is a structured record of one complete execution of your agent”
↩︎ What compaction removes, and why the trace decides it“Traces are stored in Unity Catalog as Delta tables (recommended).”
↩︎ What compaction removes, and why the trace decides it“Each span represents one operation: it records what went in, what came out, how long it took, and any metadata.”
↩︎ The downstream dependency test“Each span represents one operation: it records what went in, what came out, how long it took, and any metadata.”
↩︎ Exam trap 2“every intermediate step (LLM calls, retriever lookups, tool invocations), latency, and any errors”
↩︎ Exam trap 3 - 2.
“It shows all spans in the trace, their parent-child relationships, and their execution order and duration.”
↩︎ What compaction removes, and why the trace decides it“Inputs / Outputs: The raw input passed to the operation and the raw output it returned.”
↩︎ The downstream dependency test“Events: For spans that raised errors, the exception details and stack traces.”
↩︎ Exam trap 1“It shows all spans in the trace, their parent-child relationships, and their execution order and duration.”
↩︎ Exam trap 4“Events: For spans that raised errors, the exception details and stack traces.”
↩︎ Prediction - 3.
“the ordered transcript of messages, tool calls, and results”
↩︎ Superseded, redundant and resolved content - 4.
“With only an input and final response, you cannot tell which intermediate decision caused a failure.”
↩︎ Content that looks removable but has later dependents“With only an input and final response, you cannot tell which intermediate decision caused a failure. With traces, you can inspect every step”
↩︎ Checkpoint
Also cited
- https://www.databricks.com/blog/ai-harnessOfficial docs
“As conversations grow longer, the harness decides what stays active and what gets summarized, a process known as context compaction.”
↩︎ Key concept “the span is automatically marked as failed and the exception details are recorded in the span's Events tab”
↩︎ Checkpoint