What you will be able to do
- Explain why the compaction prompt is the main lever for changing what a compacted summary keeps and drops
- Build an expected-facts list from real Databricks agent traces and use it to drive a recall-first tuning pass
- Run a precision pass that removes superfluous content one class at a time while re-checking recall against the same expected facts
Key concept
Recall-first compaction tuning — Tune the compaction prompt until its summaries contain every fact the agent will still need, measured against an expected-facts list taken from real traces. Only after that, cut superfluous content, checking after every cut that recall has not dropped.
1.The compaction prompt decides what survives
Compaction replaces a long agent history with a summary, and the agent carries on from that summary as if it were the history. For a Databricks agent that has spent two hours profiling Unity Catalog tables, opening tickets and testing SQL fixes, the summary is all it has left of that work. Whatever the summary leaves out is gone. The agent cannot ask about it, because it no longer knows the thing ever existed.
The compaction prompt is the instruction that produces the summary, so it is the lever you tune. The model that writes the summary keeps what the prompt asks for and drops the rest. Changing the trigger threshold or the context window size changes when compaction runs. Changing the prompt changes what comes out of it. Treat the prompt as a versioned artifact: register it, evaluate each version, and keep the history, the same as you would for any other prompt in the agent.
Tuning has two objectives, and you take them in a fixed order: maximize recall first, then improve precision. Recall asks whether the summary contains everything the agent still needs. Precision asks whether everything in the summary earns its tokens. The order comes from an asymmetry in what each failure costs. When recall fails, the agent reopens a ticket it already closed or breaks a constraint the user set an hour ago, and nothing in its context shows that anything went missing. When precision fails, you pay for extra tokens. The first failure is silent and does damage. The second is visible and cheap to fix later.
There is also a practical reason. You can only judge recall against a complete list of what has to survive. Precision can be judged locally, by looking at one sentence and asking whether it matters, so it can wait. If you prune first, you end up with a short summary and no way of telling which of the deleted facts mattered. Tuning both at once, weighted equally, has the same problem: every cut is a guess.
Checkpoint 1 of 6· Check yourself
A teammate wants to tune a new compaction prompt for recall and precision in one pass, with both weighted equally, so that the summaries come out short right away. What is the main problem with this plan?
Recall measures what fraction of everything relevant made it into the summary, so you need the full list of relevant facts to measure it. Precision can be judged one sentence at a time. If you prune before the recall baseline exists, you cannot tell which deleted facts mattered. The last option has it backwards: recall failures are the silent ones, and precision failures only cost tokens.
“Computing recall requires your ground-truth to contain all relevant items.”Source: docs.databricks.com
Checkpoint 2 of 6· Exam question
A context engineer is tuning a compaction prompt that summarizes a long-running Databricks agent trace whenever the context window nears its limit. This is the first draft of the prompt. What should the engineer optimize for first, before worrying about how concise the summary is?
Correct answer: A — Recall: make sure the summary captures every fact, decision, and tool result that could still be relevant later
Checkpoint 3 of 6· Exam question
When tuning a compaction prompt for an agent trace, what is the recommended order of the two tuning objectives?
Correct answer: A — Maximize recall first, then iterate afterward to improve precision
2.The recall pass: expected facts from real traces
Recall tuning starts from real traces, not invented conversations. MLflow Tracing records every LLM call, retriever lookup and tool invocation in an agent run, so a long production or staging trace shows exactly what history the compaction step would face. Choose several long traces that actually hit the context limit, and include ones where the agent changed direction, hit errors, or received new constraints partway through.
For each trace, write down the facts the summary must contain. These are expected facts, the same idea MLflow evaluation uses for the required content of a good response. Categories compaction must keep (goals and constraints, decisions with their rationale, open issues, identifiers and paths, errors that still matter) give you the skeleton. Your job here is to turn each category into concrete, checkable lines for this specific trace. A line like "keep decisions" can't be checked. A line like "chose to rebuild sales.orders_daily rather than patch it, because the source schema changed" can.
The loop is simple. Run the draft prompt on each trace, compare the summary with the expected-facts list, and for each missing fact, add or sharpen an instruction that asks for its category. Then run again. Stop when every expected fact appears in every summary. A scorer can do the comparison so that each prompt version gets a recall number instead of an impression.
Leave length limits out of the prompt during this pass. The summarization prompt below, registered as a new version, shows why. One line asks for every core fact, which is a recall instruction. Another forces the output into exactly two sentences, which is a hard precision limit. When the two conflict, the length limit usually wins and facts get dropped. A first-draft compaction prompt should contain the recall instruction only.
prompt_v2 = mlflow.genai.register_prompt(
name=PROMPT_NAME,
template="""You are an expert summarizer. Create a summary of the following content in *exactly* 2 sentences (no more, no less - be very careful about the number of sentences).
Guidelines:
- Include ALL core facts and key findings
- Use clear, concise language
- Maintain factual accuracy
- Cover all main points mentioned
- Write for a general audience
- Use exactly 2 sentences
Content: {{content}}
Summary:""",
commit_message="v2: Added comprehensive fact coverage with 2-sentence requirement"
)Checkpoint 4 of 6· Fill the gap
This registered prompt version mixes two kinds of guideline. Which word completes the guideline that works as the recall instruction, the only kind a first-draft compaction prompt should keep?
prompt_v2 = mlflow.genai.register_prompt(
name=PROMPT_NAME,
template="""You are an expert summarizer. Create a summary of the following content in *exactly* 2 sentences (no more, no less - be very careful about the number of sentences).
Guidelines:
- Include ? core facts and key findings
- Use clear, concise language
- Maintain factual accuracy
- Cover all main points mentioned
- Write for a general audience
- Use exactly 2 sentences
Content: {{content}}
Summary:""",
commit_message="v2: Added comprehensive fact coverage with 2-sentence requirement"
)"Include ALL core facts" asks for every fact, so it is the recall instruction. "Use exactly 2 sentences" is a hard precision limit that usually wins when the two conflict, which is why the recall pass leaves length caps out. "ONLY" or "KEY" would turn the line into a filter that trims content, and trimming belongs to the precision pass that comes after recall.
Source: docs.databricks.com3.The precision pass: cut what never matters, then re-check recall
Precision work starts only once the recall-tuned prompt keeps every expected fact. At that point, read the summaries for content that never changes what the agent does later. Typical examples are tool-call arguments repeated next to the result they produced, the same "job still running" status written five times, and raw output the agent could simply fetch again. Removing this kind of content safely is covered in safe content removal. In this pass you turn each of those classes into an omission instruction in the prompt.
Make one cut per prompt version, then re-run the same traces against the same expected-facts list. An instruction such as "omit tool arguments" can quietly remove a table path the agent needs later. Only the recall check catches that. If recall drops, roll back to the previous version and narrow the instruction, for example "omit tool arguments except identifiers and paths". Prompt versions are immutable, so the version that passed is always there to go back to.
| Pass | Question it answers | Signal to watch | What you change in the prompt |
|---|---|---|---|
| Recall (first) | Does the summary contain every expected fact from the trace? | Share of expected facts present in each summary | Add or sharpen instructions to keep missing categories; no length cap |
| Precision (second) | Does every part of the summary affect later agent behavior? | Summary size, e.g. total_token_count, with recall held at its passing level | Add omission instructions one class at a time; roll back any version that loses a fact |
Three tempting responses to a bloated summary each undo the method. Rewriting the prompt from scratch with a new strategy throws away the instructions that earned full recall, so you start over. Leaving the prompt alone because "more detail is always safer" pays for useless tokens on every compaction, and filler competes with real facts for the model's attention. Shrinking the context window so compaction runs less often doesn't touch the summary's content at all. The correct move is iterative: remove content confirmed as superfluous, and confirm recall after each removal.
Checkpoint 5 of 6· Check yourself
Your recall-tuned compaction prompt, v5, keeps every expected fact. You register v6, which adds "omit tool arguments". total_token_count drops by 30%, but on one trace the summary no longer contains a table path that the agent uses later. What should you do next?
In the precision pass, recall has to stay at its passing level. Any version that loses an expected fact is rolled back, and the cut is narrowed and re-checked against the same expected facts. Prompt versions are immutable, so v5 is always there to go back to. Rewriting from scratch throws away the instructions that earned full recall. Removing the fact from the list hides the failure instead of fixing it.
“To edit a prompt, you must create a new version. This Git-like versioning maintains complete history and enables rollbacks.”Source: docs.databricks.com
Checkpoint 6 of 6· Exam question
After the recall-first draft of a compaction prompt, an engineer reviews summarized agent traces and finds the summaries reliably retain all necessary facts, but they are bloated with restated tool-call arguments and duplicate status messages that never affect later agent behavior. What is the appropriate next tuning step?
Correct answer: A — Iterate on the prompt to omit content confirmed to be superfluous, then re-check that recall is still preserved
Sources
(8)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.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.”
↩︎ The compaction prompt decides what survives - 2.
“By treating prompts as first-class artifacts alongside your agent code, you can iterate confidently and ensure every prompt change is tracked and measurable.”
↩︎ The compaction prompt decides what survives - 3.https://docs.databricks.com/aws/en/agents/tutorials/ai-cookbook/evaluate-assess-performanceOfficial docs
“Computing precision does not require knowing all relevant items.”
↩︎ The compaction prompt decides what survives“Precision is the proportion of retrieved documents that are actually relevant”
↩︎ The precision pass: cut what never matters, then re-check recall“Recall is the proportion of the ground truth documents that are represented in the retrieved chunks.”
↩︎ Key concept“Computing recall requires your ground-truth to contain all relevant items.”
↩︎ Exam trap 1“Computing recall requires your ground-truth to contain all relevant items.”
↩︎ Checkpoint - 4.
“Tracing records the inputs, outputs, latency, token usage, and cost of every intermediate step”
↩︎ The recall pass: expected facts from real traces - 5.
“the required facts a response must contain”
↩︎ The recall pass: expected facts from real traces - 6.https://docs.databricks.com/aws/en/mlflow3/genai/prompt-version-mgmt/prompt-registry/evaluate-promptsOfficial docs
“build evaluation datasets with expected facts”
↩︎ The recall pass: expected facts from real traces“Start simple: Begin with basic prompts and iteratively improve based on evaluation results.”
↩︎ Exam trap 2“Use consistent datasets: Evaluate all versions against the same data for fair comparison.”
↩︎ Exam trap 3 - 7.https://docs.databricks.com/aws/en/mlflow3/genai/prompt-version-mgmt/prompt-registry/create-and-edit-promptsOfficial docs
“This Git-like versioning maintains complete history and enables rollbacks.”
↩︎ The precision pass: cut what never matters, then re-check recall“To edit a prompt, you must create a new version. This Git-like versioning maintains complete history and enables rollbacks.”
↩︎ Checkpoint
Also cited
“RAG agents: Missing key context leads to incorrect answers or hallucinations.”
↩︎ Prediction