CertSafari
    Databricks Certified Context Engineer Associate· Lessons

    Domain 6 · Lesson 38/45

    Safe content removal in agent trace compaction

    Given a Databricks agent trace, identify which content is safe to remove during compaction without affecting downstream task execution.

    13 min read
    2.2% of exam
    6 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    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?

    Sources12

    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.

    Applying the dependency test to the retry trace
    Trace itemLater step that depends on itVerdict
    User request that started the searchEvery later step: it defines what the task isKeep
    Tool call 1 and call 2, both timeoutsNone: the retry resolved themSafe to remove
    Tool call 3 and the returned function definitionThe agent's next message uses itKeep
    Agent message using the definitionLater reasoning and the final output build on itKeep

    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?

    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?

    Sources21

    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?

    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?

    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?

    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?

    Sources4

    Sources

    (6)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 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. 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. 3.
    4. 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

    Ready to test yourself?

    Practise Databricks Certified Context Engineer Associate in quiz mode.

    Spotted a mistake, or was something unclear? Tell us.