What you will be able to do
- Explain why raw tool outputs are the first place to look for room in a deep message history
- Classify a raw tool output as consumed, superseded, re-fetchable or still needed
- Rank several clearing candidates and pick the one to clear first
- Distill the facts from an output and keep a pointer to it before dropping the payload
Key concept
Clearing candidate — A raw tool output in the message history that no pending step still reads, because the agent has already used it, a later call has replaced it, or it can be fetched again. You clear it once the facts the agent took from it are recorded elsewhere in the history.
1.Why raw tool outputs are the first place to look
Once an agent's context window is nearly full, the next turn either fails or pushes useful material out. Something has to go, and the useful question is which item frees the most room while costing the task nothing. In a deep history, the answer is nearly always a raw tool output.
The reason is how agents grow their context. Every turn re-sends the full history to the model, so each item stays in every later request (Per-turn context accumulation). Most of that history is small: a user question is a sentence, an assistant plan is a paragraph, a tool call is a name plus some arguments. Tool results are a different size. One SQL query through a Unity Catalog function can return tens of thousands of rows. A document fetch can return a whole file. A schema lookup can return hundreds of column definitions. A handful of these can outweigh everything else in the history combined.
Most of that bulk has also stopped working by the time the window fills. An agent calls a tool to learn something specific: which three rows match, whether a column exists, what an error code means. After the next reasoning step it has the answer and has written it down in its own words. The raw payload stays in the history afterwards. It still costs tokens on every turn but no longer contributes information.
Checkpoint 1 of 7· Check yourself
An agent is 30 turns into a task and its context window is nearly full. Which item in its history should it look at first to free room without hurting the rest of the task?
The full history is re-sent on every turn, so the raw query result still costs tokens even though the agent has already taken its answer from it. The system prompt, the latest question and the tool schemas are small and still steer the turns ahead, so clearing them saves little and does a lot of damage.
“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.”Source: docs.databricks.com
Checkpoint 2 of 7· Exam question
An agent invoked a Unity Catalog function that returned a 50,000-row raw query result. The agent has already extracted the three relevant rows and written a summary of its findings into its response earlier in the conversation. The context window is now approaching capacity. Which item in the message history is the best candidate for clearing?
Correct answer: A — The raw 50,000-row tool output, since its findings are already summarized in the response
- A. Correct. The raw output's useful content has already been extracted and preserved as a summary elsewhere in the context, so keeping the full 50,000-row payload adds token cost without adding retrievable information.
- B. Incorrect. The system prompt anchors the agent's role, tone, and constraints for the entire session; clearing it would degrade behavior on every subsequent turn.
- C. Incorrect. The most recent user question is still active context the agent needs to keep working on the current turn; it has not been superseded by anything.
- D. Incorrect. Tool schemas are needed for the agent to correctly invoke the tool again later and are typically small and reused, not a meaningful source of context bloat.
Sources1
2.Consumed, superseded, re-fetchable — or still needed
A raw tool output is a clearing candidate when at least one of three things is true about it and nothing ahead still reads it.
- Consumed. The agent has already pulled what it needed from the output into its own reasoning or response. A 50,000-row query result whose three relevant rows are already summarised in an earlier assistant message fits this case.
- Superseded. A later call has replaced the output. A failed call followed by a successful retry, or an older version of a file read again after an edit, leaves the earlier output carrying nothing the agent will act on.
- Re-fetchable. The same call with the same arguments would return the same content. If the agent needs it again it can ask again, so the history only has to remember that the call happened.
The exception overrides all three: an output that a pending step still reads is not a candidate, however large it is and however long it has sat there. Take an agent on a multi-part data-cleaning task. It fetched table A's schema, wrote and ran a cleaning query against it, and confirmed the query succeeded. It then moved on to formatting table B and fetched table B's schema. Table A's schema is consumed and finished. Table B's schema has been used once too, but the formatting work is reading it right now. Clearing it would make the agent guess at column names or call the tool again in the middle of the step.
So "already used" and "done with" are different things. The question to ask is whether any remaining step still depends on the output, not whether the agent has looked at it. Removing context that is still needed has a real cost. Genie warns about the same thing when it filters context under token pressure.
Notice what the success confirmation is. It is not a payload waiting to be distilled. It is already the distilled outcome: one line saying the cleaning query ran. Clearing it frees almost nothing and removes the agent's record of what it has done, which is how agents end up re-running finished work.
Checkpoint 3 of 7· Check yourself
Which of these raw tool outputs should stay in the history when the agent clears context to free room?
An output that a pending or current step still reads is not a clearing candidate, even if the agent has already looked at it. The failed call and the pre-edit file read have both been replaced by later calls, and the finished table's schema has been used up, so all three can be cleared.
“quality may be reduced if important context is filtered out.”Source: docs.databricks.com
Checkpoint 4 of 7· Exam question
An agent is working through a multi-part data-cleaning task. It first called a tool to fetch a table's schema, used that schema to write and run a cleaning query, and confirmed the query executed successfully. The agent has now moved on to an unrelated formatting sub-task for a different table and will not need the earlier schema again. The context window is close to its limit. Which raw tool output is the strongest candidate for clearing?
Correct answer: A — The schema tool output from the completed cleaning sub-task, since it is no longer needed
- A. Correct. The schema was only relevant to the finished cleaning sub-task; with that sub-task closed and no dependency from the new sub-task, it is safe to clear.
- B. Incorrect. A brief success confirmation is cheap to retain and useful as a record of completed work; it is not the item consuming the most unnecessary context.
- C. Incorrect. Instructions for the sub-task currently in progress are actively needed and should not be cleared.
- D. Incorrect. This schema is being actively used for the agent's current formatting work, so it must stay in context.
3.Which candidate to clear first
When more than one output qualifies, clear first the one that loses the least information per token freed. That gives a fairly stable order.
- Failed and superseded outputs. Nothing in them needs saving, so they can go without any distillation step.
- Large consumed outputs whose findings are already written down. The facts survive in the agent's own messages, so the raw rows are pure overhead.
- Re-fetchable outputs the agent may want again later. Clear them, but keep the call so the agent can repeat it.
Never on the list: anything a pending step reads, plus the non-tool items that steer the remaining work.
Retries show why the order matters. Agents routinely call a tool again after an error until they get valid data. Suppose an MCP tool call fails with a transient network error, the retry succeeds, and the agent uses the returned data in its next step. Both outputs have now been "consumed" in a loose sense. But the error output told the agent only to try again, and that instruction is spent. The successful output holds the data the task is built on, and the agent may want to check it again. The failed call's error output is the first to clear. The successful output, if it is large, comes later, after its facts are recorded.
The error output contains nothing the agent will act on again: the retry has replaced it. The successful output is the source of the facts the agent is working from. Clearing it before those facts are written down, or while a later step might check them, risks losing the one thing the retry was for.
Checkpoint 5 of 7· Check yourself
Context is nearly full. Three outputs qualify for clearing. The first is a transient network error from an MCP call. The second is the large result of the successful retry, which the agent used in its next step but has not yet restated. The third is a large query result whose findings the agent has already written down. Which should go first?
The failed call's error output only told the agent to try again, and the successful retry has replaced it. It loses no information, so it goes before the consumed query result. The retry's result holds the data the task depends on, so it waits until its facts are recorded.
“or tools repeatedly until an objective is achieved or a certain condition is met, such as receiving valid data or resolving an error.”Source: docs.databricks.com
Checkpoint 6 of 7· Exam question
While completing a task, an agent's MCP tool call failed with a transient network error. The agent retried, and the second call succeeded, returning the data it needed, which it then used in its next step. The failed call's error output still sits in the message history and the context window is nearly full. Which output should be cleared first?
Correct answer: A — The failed first call's error output, since the retry already produced the needed data
- A. Correct. Once a retry succeeds, the earlier failed attempt's error output is superseded and carries no information the agent still needs; it is a prime clearing candidate.
- B. Incorrect. Although this output was already consumed, it is the record of the data the agent actually acted on and is more useful to retain than a stale error from a failed retry.
- C. Incorrect. The original task instruction still frames what the agent is trying to accomplish and should stay available.
- D. Incorrect. A not-yet-executed plan is forward-looking and still needed to guide the agent's next action, so it should not be cleared.
Sources3
4.Distill first, then drop the payload
Clearing is safe only once the history keeps everything later steps need from the output. That means three things stay when the payload goes.
- The facts the agent extracted. For a 50,000-row result, that is the three matching rows and the conclusion drawn from them, written into an assistant message or a short note that replaces the raw result.
- The call record. The tool name and arguments show that the call happened and what it asked for, so the agent does not repeat finished work.
- A pointer to fetch it again. The same call, a query, a table name or a file path that brings back the full content if a later step needs a detail that was not distilled.
With those three in place, a raw output passes the downstream dependency test: later steps get the facts they need from the distillate, and the pointer covers anything nobody foresaw. Without the distillate, clearing a consumed output turns into losing it. Without the pointer, a detail that turns out to matter later can't be recovered.
Clearing an output from the working context also does not have to destroy the record. On Databricks, an agent session can keep the full transcript, including tool calls and results, apart from what the agent sends to the model on a given turn, and MLflow tracing records every step of every execution. The payload you drop from the model's input can still be found in the session or the trace when someone needs to debug the run.
Checkpoint 7 of 7· Check yourself
A team adds a context-clearing step to their Databricks agent. Their agent uses MLflow tracing. For a consumed 50,000-row query result, which version of the step clears it safely?
Only the payload is dropped. The distilled facts give later steps what they need. The call record stops the agent from repeating finished work, and the pointer recovers details nobody foresaw. The trace keeps the full result for debugging, but the agent does not read the trace, so deleting the call loses context the agent needs.
“every intermediate step — such as model calls, tool calls, and retrieval — with the inputs, outputs, latency, token usage, and cost”Source: docs.databricks.com
Sources
(5)
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.”
↩︎ Why raw tool outputs are the first place to look“so the twentieth message in a chat costs more than the first”
↩︎ Why raw tool outputs are the first place to look“restating table names or earlier results in each prompt adds tokens without adding information”
↩︎ Consumed, superseded, re-fetchable — or still needed“The goal is to keep each chat's context relevant to the task at hand.”
↩︎ Key concept - 2.
“quality may be reduced if important context is filtered out”
↩︎ Consumed, superseded, re-fetchable — or still needed“quality may be reduced if important context is filtered out”
↩︎ Exam trap 2“quality may be reduced if important context is filtered out.”
↩︎ Checkpoint - 3.
“calling an LLM or tools repeatedly until an objective is achieved or a certain condition is met, such as receiving valid data”
↩︎ Which candidate to clear first“You still need carefully designed prompts and constraints to keep the agent focused and relevant.”
↩︎ Exam trap 1“calling an LLM or tools repeatedly until an objective is achieved or a certain condition is met, such as receiving valid data”
↩︎ Exam trap 3“or tools repeatedly until an objective is achieved or a certain condition is met, such as receiving valid data or resolving an error.”
↩︎ Checkpoint - 4.
“Reconstruct full context (including tool calls and reasoning) on a follow-up message.”
↩︎ Distill first, then drop the payload - 5.
“Agent tracing captures a complete record of every agent execution.”
↩︎ Distill first, then drop the payload“Agent tracing captures a complete record of every agent execution.”
↩︎ Exam trap 4“every intermediate step — such as model calls, tool calls, and retrieval — with the inputs, outputs, latency, token usage, and cost”
↩︎ Checkpoint