What you will be able to do
- Explain why context pressure builds on every turn of an agent loop, well before compaction is needed
- Identify tools in a Databricks agent design that add definition cost and selection noise without serving the task
- Scope a retriever or memory tool's output with num_results, columns, filters and limit so each call adds only what the next step needs
- Recognise when knowledge or memory should be fetched by a tool call instead of being loaded into standing context
- Place durable state, governed logic and before/after verification in Lakebase, Unity Catalog functions and MLflow 3 evaluation
Key concept
Per-turn context accumulation — An agent loop sends a model call on every turn. Each call carries the standing context (system prompt and every tool definition) plus the growing history of messages and tool results, so pressure builds by design. The cheapest place to stop it is in the agent's design, before any compaction runs.
1.Why context fills up on every turn
A tool-calling agent re-sends nearly everything on every turn. The loop below comes from the Databricks retriever example. Each pass calls the model with the full messages list and the full tools list, then appends the model's reply to messages. When the model calls a tool, the loop also appends the tool's output as a tool message whose content is json.dumps(documents), which is every document the retriever returned. On the next pass all of it is sent again.
for _ in range(10):
response = client.chat.completions.create(
model="databricks-claude-sonnet-4-5",
messages=messages,
tools=[dbvs_tool.tool],
)
message = response.choices[0].message
messages.append(message.model_dump(exclude_none=True))Two kinds of context come out of that loop, and they grow differently. Standing context is the system prompt plus the tool definitions. It costs the same on every call, whatever the agent does. Accumulated context is the history: user turns, assistant turns and tool results. It grows with every step, and Databricks session stores model it as a transcript the agent reads at the start of a turn and appends to as the interaction runs. Frameworks also keep the two apart. LangGraph, for example, adds the system prompt to each model call without saving it to graph state.
The accumulation is built into the loop, so pressure arrives on schedule. It isn't the result of something going wrong. Compaction is the late answer: as conversations grow, a harness decides what stays active and what gets summarized, which means trimming older parts of the conversation. Proactive strategies act earlier, on the two inputs the designer controls. They shrink the standing context that every call pays for, and they shrink what each step adds to the history. Each of the three strategies below targets one of those inputs.
Checkpoint 1 of 8· Fill the gap
In this Databricks retriever agent loop, each pass sends the full message history to the model. Which method makes that history grow from turn to turn, so context builds up by design?
for _ in range(10):
response = client.chat.completions.create(
model="databricks-claude-sonnet-4-5",
messages=messages,
tools=[dbvs_tool.tool],
)
message = response.choices[0].message
messages. ? (message.model_dump(exclude_none=True))The loop appends each model reply, and later each tool result, to messages. Because the whole list goes out again on the next call, accumulated context grows every turn even when nothing goes wrong. The pre-compaction strategies that follow work by shrinking what the agent adds to this list.
2.Minimal tool sets
Every tool you register is standing context. Its name, description and parameter schema go out with every call, on every turn of every conversation. An unused tool still has a cost. It also gives the model one more option to weigh at each step, so an unneeded tool both consumes budget and adds selection noise. Databricks' design guidance makes the same pairing for prompts and tools: keep prompts minimal to avoid distracting information, and register only the tools the agent requires.
Take a support agent that handles returns and shipping. Suppose it was also given SQL tools for the finance warehouse, a marketing-campaign API and a code-execution tool "in case". None of those serve a returns conversation, yet every turn pays for their schemas, and every tool choice has to rule them out. To audit a design, list each tool and name the task step that needs it. A tool with no step is a candidate for removal.
Sometimes the honest tool list for the whole application really is long, because the application spans unrelated domains. In that case, pruning one agent's list is not enough, and the fix is structural. When an application spans radically different sub-domains, Databricks warns that a single agent can become overloaded with functionality requirements. Under-split agent boundaries covers that diagnosis. The angle here is narrower: split the tool set across specialized agents so that no single agent carries every definition. Databricks lists having so many tools that they don't fit one agent's schema as a reason to go multi-agent.
Checkpoint 2 of 8· Check yourself
A support agent for returns and shipping is registered with its order-lookup and label tools. It also has a finance-warehouse SQL tool, a marketing-campaign API and a code-execution tool. Which design change most reduces the context that every model call carries?
Tool definitions are standing context that goes out with every model call, so removing tools no task step needs makes every turn smaller. Compaction trims history, but the tool definitions are sent again after it. The iteration limit guards against loops and does not shrink what each call carries.
“Provide only the tools and context your agent requires, rather than an unbounded set of APIs or large irrelevant context.”Source: docs.databricks.com
Sources4
3.Tool result scoping
Tool results are the fastest-growing part of the history, because each call can add a large payload that stays in the transcript. Scoping narrows what a tool returns: fewer results, fewer columns, a filtered set. Then each call adds only what the next step needs. On Databricks, many of these limits are set once in the tool's configuration, so the model doesn't have to remember to ask for less.
vs_tool = VectorSearchRetrieverTool(
index_name="catalog.schema.index_name", # Index name in the format 'catalog.schema.index'
num_results=5, # Max number of documents to return
columns=["primary_key", "text_column"], # List of columns to include in the search
filters={"text_column LIKE": "Databricks"}, # Filters to apply to the query
query_type="ANN", # Query type ("ANN" or "HYBRID").| Parameter | What it limits | Effect on the transcript |
|---|---|---|
| num_results | Max number of documents to return | Caps how many documents each retrieval appends |
| columns | Columns to include in the search | Leaves out fields the next step never reads |
| filters | Filters applied to the query | Removes out-of-scope rows before they reach the model |
The same setting appears wherever a tool returns a list. In the Databricks memory examples, a search_memory tool calls memory_store.search(..., limit=10), and the recall-before-run helper uses limit=5. That limit is a scoping decision. Each recalled entry becomes text in the agent's context, so the right value is the smallest one that still surfaces the fact the next step needs.
Scoping has a cost when it goes too far. A num_results set too low, or a filter that drops the authoritative rows, leaves the agent without the evidence it needs. It may then call the tool again, which adds more history than one well-sized call would have. Set the bound from what the next step consumes, then check the setting against the evaluation described in the last section.
Checkpoint 3 of 8· Match them up
A retrieval-heavy Databricks agent is filling its context window with tool results. Match each scoping setting to how it shrinks what a call appends to the message history.
Tap a term, then the definition that fits it.
Each setting bounds a different part of the payload the loop appends as a tool message: how many documents (num_results), which fields (columns), which rows (filters), and how many memory entries (limit). Because they are set in the tool's configuration, every call stays scoped even if the model doesn't ask for less.
“num_results=5, # Max number of documents to return”Source: docs.databricks.com
4.Fetching knowledge and memory only when a step needs it
Retrieval timing decides whether knowledge becomes standing context or appears only on the turns that use it. Pre-inference retrieval vs just-in-time agentic retrieval explains the full distinction: retrieval that runs before every model call versus retrieval the agent chooses to do through a tool. Here, the point is pressure. A deterministic RAG chain always retrieves top-k results and adds them to the prompt, even when the question doesn't need them. Exposing the same index as a tool, with a description that tells the agent when to search, keeps those documents out of context until a step calls for them.
Memory follows the same pattern. Fixed session replay vs agent-driven memory recall covers the trade-offs between the two. For context pressure, what matters is where recalled memory sits. Recall-before-each-run searches memory for every incoming message and adds the results to the agent's context, so they behave like standing context on every request. With memory tools, the model decides when to recall. A list-then-fetch design goes further: listing entries is meant for browsing an index of what the agent knows, so the agent can see what exists and then fetch only the entries the current step needs.
No. The recalled facts are now standing context, sent with every model call in that run. The change keeps the persisted transcript clean, but it does not shrink the prompt. To cut per-turn cost, recall only when a step needs it (memory tools) and keep the search limit small.
Checkpoint 4 of 8· Check yourself
Most requests to a Databricks support agent never need the user's stored preferences. Even so, the application searches memory for every incoming message and adds five results to the agent's context. Which change keeps those entries out of context on the turns that don't use them?
Recall-before-run adds memory to the context on every request, so it acts like standing context. With memory tools, the model recalls only when a step calls for it. Moving the facts into the system prompt keeps them out of the stored transcript, but they are still sent with every call. A larger limit, or a chain that retrieves on every call, adds even more context.
“Memory tools: The model decides when to recall memory and when to save a new fact.”Source: docs.databricks.com
5.Where state, logic and verification belong in the Databricks stack
A proactive design also keeps things out of the window entirely by putting them in the service built to hold them. Three placements come up repeatedly.
Durable state goes in Lakebase. Lakebase provides a fully managed Postgres backend for agent state and memory. Agent sessions persist a conversation history so it survives restarts and can be resumed later. Agent memory keeps facts that must outlive one conversation, such as a customer's preferences recalled days later. The agent reads that state at inference time when it needs it, instead of carrying it in the prompt. MLflow Tracing does a different job: it logs each user request, agent plan and tool call for observability. It isn't a state store that an agent reads at the start of a turn.
Governed business logic goes in a Unity Catalog function. A discount calculation or a parameterized SQL query is predefined logic. The agent supplies the parameters, the function runs, and only the result enters context, not the raw rows behind it. That makes the function a form of result scoping. It is also governed like other Unity Catalog objects: calling a function requires the EXECUTE privilege. Unity Catalog AI packages expose these functions to agent frameworks.
| Framework | Installation command |
|---|---|
| LangGraph | %pip install --upgrade unitycatalog-langchain[databricks] databricks-langchain langgraph |
| OpenAI | %pip install --upgrade unitycatalog-openai[databricks] |
| Anthropic | %pip install --upgrade unitycatalog-anthropic[databricks] |
Before/after evidence comes from MLflow 3 evaluation. Each strategy on this page is a change to the agent: a shorter tool list, a smaller num_results, a moved recall step. Any of them can quietly cost accuracy. MLflow evaluation runs the old and new configurations against the same questions and scores the responses with LLM judges. You can build a custom judge with make_judge and load prompt versions from the Prompt Registry. A boolean judge gives a pass rate for each version, so you can compare the slimmer configuration with the original on numbers rather than impressions. Lakebase branching, Unity Catalog access controls and MCP don't score responses.
Checkpoint 5 of 8· Match them up
A team is slimming the prompt of its Databricks support agent by moving each concern into the service built for it. Match each service to the job it should take over.
Tap a term, then the definition that fits it.
Durable state that the agent reads at inference time belongs in Lakebase. Predefined, governed logic belongs in a Unity Catalog function, which returns only its result. Judge-based comparison of configurations is MLflow 3 evaluation. Tracing logs what the agent did for observability, so it cannot act as the agent's memory.
“Implement detailed logging for each user request, agent plan, and tool call using MLflow Tracing.”Source: docs.databricks.com
Checkpoint 6 of 8· Exam question
A team is building a customer-support agent that must remember details from a user's earlier conversation even after the user closes the chat and returns days later. The team wants this memory to survive process restarts and be queryable with low latency at inference time. Which tool should they use to store this cross-session agent state?
Correct answer: A — Lakebase, as a Postgres-backed state store the agent reads and writes at inference time
- A. Correct. Lakebase is a fully managed Postgres database designed to serve as a low-latency, durable state store for AI agents, exactly the persistent, cross-session memory need described.
- B. Incorrect. MLflow 3 tracing is an observability tool for logging and inspecting what an agent did; traces are not designed to be queried as a live application state store.
- C. Incorrect. MCP servers expose tools and resources to an agent, but they are not themselves a persistence layer for agent-owned conversational memory.
- D. Incorrect. Unity Catalog functions execute governed logic as agent tools; they don't provide durable, queryable storage for session state.
Checkpoint 7 of 8· Exam question
A context engineer wants to compare two versions of a RAG agent's system prompt by running both against a held-out set of questions and scoring the responses with an LLM judge for correctness and relevance, then reviewing the results in a dashboard. Which tool is purpose-built for this?
Correct answer: A — MLflow 3 GenAI evaluation, using built-in LLM judges and scorers to compare the prompt versions
- A. Correct. MLflow 3 for GenAI provides built-in LLM judges and custom scorers specifically for evaluating and comparing GenAI application configurations, including system prompt changes, with results viewable through the MLflow UI.
- B. Incorrect. Lakebase branching creates isolated copies of a Postgres database for development and testing; it does not run automated evaluation or scoring of agent responses.
- C. Incorrect. Unity Catalog governs access to data and assets; it has no built-in mechanism for scoring or comparing LLM outputs.
- D. Incorrect. MCP is a protocol for connecting agents to tools and resources, not an evaluation or scoring framework.
Checkpoint 8 of 8· Exam question
A developer wants an agent to execute governed, reusable business logic (such as a discount calculation) as a callable tool, with the logic managed under the same access controls as the organization's tables, and made available through frameworks like LangChain and OpenAI. Which tool should host this logic?
Correct answer: A — A Unity Catalog function with a documented docstring
- A. Correct. Unity Catalog functions let teams register governed, reusable logic as agent tools with clear docstrings, and Unity Catalog's access controls extend to these functions, with support across multiple agent frameworks.
- B. Incorrect. MLflow 3 scorers evaluate agent output quality; they are not a mechanism for defining callable business logic as a tool.
- C. Incorrect. Lakebase branches are isolated copies of a Postgres database used for development/testing workflows, not a place to define callable business logic.
- D. Incorrect. An MCP resource exposing raw rows provides data access, not a governed, callable computation like a discount calculation.
Sources
(10)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“The agent reads it at the start of a turn and appends to it as the interaction runs.”
↩︎ Why context fills up on every turn - 2.
“LangGraph adds the system prompt to each model call without saving it to graph state, so the checkpointer doesn't store the recalled facts.”
↩︎ Why context fills up on every turn“Memory tools: The model decides when to recall memory and when to save a new fact.”
↩︎ Fetching knowledge and memory only when a step needs it“Search memory for the incoming message before each run, and pass the results to the agent as context.”
↩︎ Exam trap 3 - 3.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.”
↩︎ Why context fills up on every turn - 4.
“Each additional LLM or tool call increases token usage and response time.”
↩︎ Why context fills up on every turn“Keep prompts clear and minimal to avoid contradictory instructions, distracting information and reduce hallucinations.”
↩︎ Minimal tool sets“You have so many tools that fitting them all into one agent's schema is impractical; each agent can own a subset.”
↩︎ Minimal tool sets“a single agent can become unwieldy or overloaded with functionality requirements.”
↩︎ Minimal tool sets“Retrieve top-k results from a vector index to find context relevant to a user request.”
↩︎ Fetching knowledge and memory only when a step needs it“Implement detailed logging for each user request, agent plan, and tool call using MLflow Tracing.”
↩︎ Where state, logic and verification belong in the Databricks stack“Use MLflow Evaluation and production monitoring to define evaluation metrics for development and production.”
↩︎ Where state, logic and verification belong in the Databricks stack“Each additional LLM or tool call increases token usage and response time.”
↩︎ Key concept“Provide only the tools and context your agent requires, rather than an unbounded set of APIs or large irrelevant context.”
↩︎ Exam trap 1“Provide only the tools and context your agent requires, rather than an unbounded set of APIs or large irrelevant context.”
↩︎ Prediction - 5.
“num_results=5, # Max number of documents to return”
↩︎ Tool result scoping“Create a retriever tool and give it a description that tells the agent when to search.”
↩︎ Fetching knowledge and memory only when a step needs it“num_results=5, # Max number of documents to return”
↩︎ Exam trap 2 - 6.
“wrap the client operations as tools and instruct the agent on when to use them in its system prompt”
↩︎ Tool result scoping“Use this to browse or render an index of what an agent knows.”
↩︎ Fetching knowledge and memory only when a step needs it - 7.
“Lakebase provides a fully managed Postgres backend for storing agent state and memory”
↩︎ Where state, logic and verification belong in the Databricks stack“Lakebase provides a fully managed Postgres backend for storing agent state and memory”
↩︎ Exam trap 4 - 8.
“Persist an agent's conversation history so it survives restarts and can be resumed later.”
↩︎ Where state, logic and verification belong in the Databricks stack - 9.
“Use Unity Catalog functions when your agent needs to run predefined logic, such as a SQL query whose parameters the agent supplies.”
↩︎ Where state, logic and verification belong in the Databricks stack“calling an existing function requires EXECUTE on it”
↩︎ Where state, logic and verification belong in the Databricks stack - 10.https://docs.databricks.com/aws/en/mlflow3/genai/prompt-version-mgmt/prompt-registry/evaluate-promptsOfficial docs
“Create a judge with a custom prompt to evaluate specific criteria using make_judge”
↩︎ Where state, logic and verification belong in the Databricks stack“MLflow aggregates boolean feedback into an average, so you get a pass rate to compare”
↩︎ Where state, logic and verification belong in the Databricks stack