What you will be able to do
- Explain context rot and why a long-running agent session degrades as its history grows
- Use session-level evaluation and per-turn trace metrics to find the context length at which retrieval accuracy or reasoning quality starts to drop
- Choose between trimming or compacting the session and distilling durable facts to memory before starting a fresh context
Key concept
Context rot — As an agent's interaction gets longer, the growing history steadily lowers its retrieval accuracy and reasoning quality. Quality falls as the session grows, not when the window runs out, so you find the problem by measuring quality against length.
1.Why long sessions degrade
Context rot means an agent gets worse at its job as the conversation gets longer. Retrieval accuracy falls, so the agent pulls in or uses the wrong supporting material, and reasoning quality falls, so it gives answers that are less correct or less grounded. Nothing has crashed and nothing has run out. The same model with the same prompt and tools does worse at turn thirty than it did at turn three, only because of everything that has built up in front of the current question. Databricks lists it among the most common failures of the harness, the system around the model that executes actions, manages memory and runs tools, and so controls what the model sees: without a strategy to trim or summarize older context, long-running tasks often break down.
The history only ever grows. A chat-style agent re-sends the whole conversation on every turn, so each new turn carries all the turns before it. On Genie, consumption grows with both the length of a chat and the amount of context it carries. The same growth that raises the cost of each turn also gives the model more stale material to read past before it reaches the current request.
The Genie warning shows why waiting for the limit is the wrong trigger. Before the limit, Genie keeps answering but applies context filtering to prioritise what it thinks is most relevant, and quality may fall if important context gets filtered out. Only when the limit is exceeded can you no longer send or receive messages. So the degraded stretch sits between "getting long" and "full", and the agent keeps answering with no error the whole time. The only reliable way to see it is to measure quality, which the next section covers.
Checkpoint 1 of 3· Check yourself
A Databricks support agent answers well in the first few turns of a session. By turn 30 its answers are less grounded and it uses the wrong supporting material. The model, prompt and tools have not changed, no errors have occurred, and no token-limit warning has appeared. What is the most likely cause?
Context rot lowers quality as the history grows, well before the window is full and without any error. With the model, prompt and tools unchanged and no limit warning showing, the growing history is what explains the decline.
“Context rot. As conversation history grows, the model’s reasoning quality degrades.”Source: www.databricks.com
2.Finding the turn where quality drops
Single-turn evaluation can't see context rot on its own. It scores each response independently, so a turn-30 answer and a turn-3 answer are judged as if they were unrelated, and nothing links a score to how much history sat in front of it. Per-turn scores become useful only once the traces are grouped by session ID and laid out in turn order next to each turn's input tokens. MLflow conversation evaluation does that grouping and scores the whole session. It catches qualities that only show up across many turns, such as user frustration patterns, conversation completeness, or overall dialogue coherence. You can run it offline during development or as continuous monitoring in production.
Session evaluation has two prerequisites. The agent must be instrumented to track session IDs on its traces, because that is how MLflow groups turns into a conversation. You also need MLflow 3.10 or later, and multi-turn evaluation is still experimental. You can evaluate conversations that were already traced, such as production sessions or a previous agent version, or you can simulate conversations to stress-test a new version with consistent scenarios.
pip install --upgrade 'mlflow[databricks]>=3.10'To find the point of degradation, put two series side by side for each turn of one session. One is a quality score. The other is context size. Context size comes from tracing, which records the inputs, outputs, latency, token usage, and cost of every intermediate step, so each turn's trace already holds its input token count. The session ID is what ties those per-turn traces and their assessments together, and the Sessions tab in the MLflow experiment lists a session's individual turns with their assessments. The quality score comes from the Agent Evaluation metrics, and which metric you use depends on which half of the objective you are checking.
| What you suspect is degrading | Metric | Needs ground truth? |
|---|---|---|
| Retrieval accuracy: are the retrieved chunks still relevant? | chunk_relevance/precision | No |
| Retrieval accuracy: are the right documents still reached? | document_recall | Yes |
| Reasoning quality: is the answer right? | correctness | Yes |
| Reasoning quality: is the answer supported by the context? | groundedness | No |
| Context length at that turn | total_input_token_count | No |
Track retrieval and response metrics together, because each can fail without the other. A RAG application can retrieve the correct context and still answer badly, or answer well from a faulty retrieval. Suppose a support agent's chunk_relevance holds steady across a forty-turn session while groundedness falls once input tokens pass a certain size. Retrieval is fine. The model is losing its grip on what it retrieved under the weight of the history. If precision falls in step with length, the growing history is distorting retrieval itself, for example because the queries the agent issues pick up stale details from earlier turns.
A gradual decline that tracks length is what Context distraction looks like in numbers: the history crowds out the task. The per-turn series turns that diagnosis into a threshold you can act on. Look for the turn, and the input token count at that turn, where the quality metric stops holding level. That number becomes the trigger point for the interventions below.
Checkpoint 2 of 3· Check yourself
You plot per-turn metrics for a long agent session. As total_input_token_count rises, chunk_relevance/precision falls step by step, but groundedness stays level. What does this pattern tell you?
Retrieval and response metrics can fail independently. Precision falling in step with length points to the history distorting retrieval itself. Groundedness only checks that answers are supported by the retrieved context, not that they are correct, so a steady groundedness score does not mean the session is healthy.
“A RAG application can respond poorly despite retrieving the correct context; it can also provide good responses based on faulty retrievals.”Source: docs.databricks.com
3.Choosing the intervention once you know the threshold
Once you know where quality starts to drop, there are two kinds of fix. Both stop the agent from reasoning over the full degraded history, but they differ in what carries forward.
Trim or compact inside the session. As conversations grow longer, the harness decides what stays active and what gets summarized. In practice that means trimming older parts of the conversation so the model is not overwhelmed. The measured threshold tells you when to fire: compact or trim before the session reaches the token count where your metrics started to fall, not after users notice. Which variant to use, fixed trimming rules or summarizing compaction, depends on how the task's relevant information is spread across the history. That choice is covered in Trimming heuristics vs summarizing compaction. Choose this option when the task still depends on recent working state that a new context would lose.
Distill to memory, then start fresh. When only a few facts from the session still matter, carrying even a summary of the degraded history forward is unnecessary. On Databricks, a memory pipeline reads conversation history from a session store and distills long-term memories, such as facts, preferences, and procedures, into a memory store. The agent then recalls those memories in later conversations the same way it recalls memories it saved itself. The new session starts from a short context made of recalled facts, with none of the noise that caused the decline.
Session and memory are kept independent, and that is what makes the fresh-start option safe. A session store keeps a conversation's items, and its clients can pop the last item, clear a session's items, or fork the conversation into an independent copy. A memory store holds what persists across conversations. You can clear or drop the degraded thread without losing the facts already distilled from it. Genie's own troubleshooting advice is the simplest form of this pattern: start a new chat if Genie begins to generate slow or failing responses. A new chat gives a blank starting point.
The test for which option wins is what the task needs next. A multi-step analysis that is halfway through, with intermediate results the next step depends on, needs compaction so the working state survives. A long advisory conversation where the user has settled a handful of preferences and constraints, and where everything else is old back-and-forth, is better served by distilling those few facts and restarting. That restores the short, clean context the agent performed well with in its early turns.
The failure is caused by how much history the model must reason over, not by running out of room. A bigger window lets the history grow even further past the point where quality was already falling. The fix is to shrink what the model sees: compact or trim before the measured threshold, or distil the durable facts to memory and start a fresh session.
Checkpoint 3 of 3· Check yourself
Forty turns into an advisory conversation, an agent's groundedness has dropped past the measured threshold. The user has settled a few preferences and constraints. Everything else in the history is old back-and-forth, and no multi-step work is in progress. The team worries that leaving the session will lose those preferences. Which intervention restores performance without losing them?
Only a few durable facts still matter and no working state needs to survive, so you distill them to memory and restart. The new session recalls those facts from a short, clean context. A fork copies the degraded history, and a bigger window lets the history grow even further past the point where quality fell.
“To build long-term memory from the sessions in a store, create a memory pipeline.”Source: docs.databricks.com
Sources
(9)
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
“Without a strategy to trim or summarize older context, performance often breaks down on long-running tasks.”
↩︎ Why long sessions degrade“Executes actions, manages memory, runs tools and enforces rules”
↩︎ Why long sessions degrade“As conversations grow longer, the harness decides what stays active and what gets summarized, a process known as context compaction.”
↩︎ Choosing the intervention once you know the threshold“Without a strategy to trim or summarize older context, performance often breaks down on long-running tasks.”
↩︎ Key concept“Context rot. As conversation history grows, the model’s reasoning quality degrades.”
↩︎ Checkpoint - 2.
“Consumption grows with both the length of a chat and the amount of context it carries”
↩︎ Why long sessions degrade - 3.
“When the token limit is exceeded, you can no longer send or receive messages in the Genie Agent.”
↩︎ Why long sessions degrade“Start a new chat if Genie starts to generate slow or failing responses.”
↩︎ Choosing the intervention once you know the threshold“While responses should still be generated when a warning appears, quality may be reduced if important context is filtered out.”
↩︎ Exam trap 1“While responses should still be generated when a warning appears, quality may be reduced if important context is filtered out.”
↩︎ Prediction - 4.
“Your agent must be instrumented to track session IDs on traces.”
↩︎ Finding the turn where quality drops“such as user frustration patterns, conversation completeness, or overall dialogue coherence.”
↩︎ Finding the turn where quality drops“Traditional single-turn evaluation assesses each agent response independently.”
↩︎ Finding the turn where quality drops“Conversation evaluation enables you to assess entire conversation sessions rather than individual turns.”
↩︎ Exam trap 2 - 5.
“Select a session to see individual turns and their assessments.”
↩︎ Finding the turn where quality drops - 6.
“Tracing records the inputs, outputs, latency, token usage, and cost of every intermediate step”
↩︎ Finding the turn where quality drops - 7.https://docs.databricks.com/aws/en/agents/tutorials/ai-cookbook/evaluate-assess-performanceOfficial docs
“A RAG application can respond poorly despite retrieving the correct context; it can also provide good responses based on faulty retrievals.”
↩︎ Finding the turn where quality drops - 8.
“Your agent then recalls those memories in later conversations the same way it recalls memories it saved itself.”
↩︎ Choosing the intervention once you know the threshold“It reads conversation history from a session store, and distills long-term memories, such as facts, preferences, and procedures, into a memory store.”
↩︎ Exam trap 3 - 9.
“To build long-term memory from the sessions in a store, create a memory pipeline.”
↩︎ Choosing the intervention once you know the threshold“Deleting a session or session store does not delete memory retained in a memory store.”
↩︎ Prediction