CertSafari
    Databricks Certified Context Engineer Associate· Lessons

    Domain 1 · Lesson 2/45

    Proactive context management: minimal tools, scoped results, just-in-time fetching

    Given a Databricks agent design, identify which proactive context management strategies (e.g., minimal tool sets, just-in-time retrieval, tool result scoping) would reduce context window pressure before compaction becomes necessary.

    16 min read
    2.29% of exam
    10 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    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.

    The agent loop: every iteration sends the whole message history and every tool definitionpython
    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))

    Sources1234

    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?

    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.

    A VectorSearchRetrieverTool with its result size, columns and filter set in the tool definitionpython
    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").
    Retriever parameters that bound what each call adds to context
    ParameterWhat it limitsEffect on the transcript
    num_resultsMax number of documents to returnCaps how many documents each retrieval appends
    columnsColumns to include in the searchLeaves out fields the next step never reads
    filtersFilters applied to the queryRemoves 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.

    Sources56

    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.

    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?

    Sources4526

    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.

    Installing Unity Catalog function tool support for common agent frameworks
    FrameworkInstallation 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.

    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?

    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?

    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?

    Sources784910

    Sources

    (10)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 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. 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. 3.
      “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. 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. 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. 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. 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. 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. 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. 10.
      “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

    Ready to test yourself?

    Practise Databricks Certified Context Engineer Associate in quiz mode.

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