CertSafari
    Databricks Certified Context Engineer Associate· Lessons

    Domain 6 · Lesson 38/45

    Safe Content Removal in Agent Traces During Compaction

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

    12 min read
    2.2% of exam
    7 sources
    Published 3 Oct 2026
    Docs as of 30 Sep 2026

    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?

    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?

    Sources12

    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.

    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?

    Sources34

    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.

    The call-center agent trace from the Databricks design-patterns page, judged just before the final response step
    Trace stepWhat it producedSafe to remove before the response?
    Reason and planPlan: look up the order, check the return policyYes. The steps that followed carried out and replaced the plan
    Find information (data intelligence)Order record and policy document textMostly. Keep the order identity and the eligibility facts, drop the raw document
    Reason (return-window check)Eligible or escalate to a humanNo. Keep the decision, because it controls what the agent says
    ActionReturn triggered, shipping label generatedNo. 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?

    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?

    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?

    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?

    Sources516

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 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. 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. 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. 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. 2.
      “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. 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. 4.
      “With only an input and final response, you cannot tell which intermediate decision caused a failure.”
      ↩︎ Reading a trace for downstream dependencies
    5. 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. 6.
      “mlflow.genai.scorers.KnowledgeRetention - Retention of information from earlier turns”
      ↩︎ Content that looks removable but isn't

    Also cited

    Ready to test yourself?

    Practise Databricks Certified Context Engineer Associate in quiz mode.

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