Deep dive 8 of 27: Dynamic Context Loading
Nov 19, 2026 · Michael Chang · Status in NurseOps Now: ✅ built
Show definitions in ( ) · hover a highlighted word for its meaning, click it for details · open with ?defs=1 to show definitions
Part of: Remembering the right things: state management in NurseOps Now, section Implementing Short-Term Memory: Token Budgets and Window Management (7.1) · All 27 solutions · ← Token Counting Middleware · System Prompt Pinning →
Read in this order
- In plain words: what it is, without jargon
- The problem it solves: the problem, and the standard approach in my words
- How to implement it (ServiceApps): scenario, steps, code and real output
- In NurseOps Now: built or not, and where
- Trade-offs and Interview answer
In plain words
Dynamic context loading (giving the AI tools to fetch data only when it needs it, instead of putting everything in the prompt) means you don't paste everything the AI might need into the prompt (the instructions and text given to the AI). You give it a short note saying what's available and tools (a function the AI can call, such as policy search) to fetch it, and it loads only what the current question needs.
In plain terms: a library card instead of carrying the whole library in your backpack.
The problem it solves
The token window is a hard limit (everything sent to the AI shares one fixed size budget) and Loss of instructional integrity (the AI losing its rules because they were pushed out of the window): pasting a whole knowledge base (a library of help articles; in ServiceApps, a named group of KB articles) or ticket history crowds out the rules and the question.
The standard approach (in my words): lazy-load: put a stub like "documentation available via the search tool (a function the AI can call, such as policy search)" in the prompt (the instructions and text given to the AI) and let the agent (an AI that chooses which tools to use to answer) request specific sections.
How to implement it (ServiceApps)
Illustrative example: no ServiceApps (a company platform for IT tickets, HR requests and help-center articles) instance is connected, so the scenario and data are made up. The code is a self-contained sketch; it was run on that made-up data on Nov 19, 2026, and the output below is from that run.
The setting. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist, an AI helper inside a company's ServiceApps (a company platform for IT tickets, HR requests and help-center articles) portal. Employees ask it IT and HR questions; it answers from knowledge-base (KB (knowledge base: a library of help articles)) articles, looks up the employee's own tickets (incidents (a ServiceApps ticket for something broken) like INC0012345) and requests, and keeps one conversation per employee and ticket.
The scenario. The company has 50 KB articles (one help-center article in a knowledge base, with a number like KB0010234). An employee asks about VPN error 809 on a Mac.
Steps.
- Replace pasted documents with a one-line stub naming the tools (a function the AI can call, such as policy search).
- Give the model tools (a function the AI can call, such as policy search) such as search_kb(question) and get_ticket(number).
- Cap each tool (a function the AI can call, such as policy search) result's size.
- Let the model call tools (a function the AI can call, such as policy search) as needed, up to a limit of rounds.
The code (Python):
KB = {f"KB00{n}": f"Article {n} " + "text " * 400 for n in range(10000, 10050)} # 50 articles
KB["KB0010234"] = "Connect to VPN on macOS. Error 809: the client can't reach the server; avoid guest Wi-Fi."
MAX_RESULT = 300
def search_kb(question, k=1):
words = set(question.lower().split())
ranked = sorted(KB.items(), key=lambda kv: -len(words & set(kv[1].lower().split())))
return [(kid, text[:MAX_RESULT]) for kid, text in ranked[:k]]
STUB = "Knowledge base: available through the search_kb tool. Fetch only what you need."
all_chars = sum(len(t) for t in KB.values())
kid, text = search_kb("vpn error 809 on mac")[0] # a real model decides to call the tool
print("whole KB if pasted:", all_chars, "chars")
print("stub in the prompt:", len(STUB), "chars")
print("fetched :", kid, len(text), "chars ->", text)
Output (from running the code above):
whole KB if pasted: 100789 chars stub in the prompt: 79 chars fetched : KB0010234 89 chars -> Connect to VPN on macOS. Error 809: the client can't reach the server; avoid guest Wi-Fi.
What to watch for.
- Cap tool (a function the AI can call, such as policy search) results; one huge result can flood the window by itself.
- Limit tool (a function the AI can call, such as policy search) rounds, so the agent (an AI that chooses which tools to use to answer) can't loop forever.
- Treat fetched text as data, never as instructions.
In plain terms: the assistant knows where every article is and fetches one page when you ask, instead of reading you the whole manual.
In NurseOps Now
Built. AI Assist (the app's chat helper for staff questions) has read-only tools (a function the AI can call, such as policy search) (get_case, list_cases, stuck_cases, metrics, search_policy, search_guide), each result capped at 12,000 characters, with at most 4 tool (a function the AI can call, such as policy search) rounds (assist.py). See Step 3.
Trade-offs
- Tool (a function the AI can call, such as policy search) calls add round trips and latency (how long it takes to respond).
- The model may not fetch something it needed; good tool (a function the AI can call, such as policy search) descriptions matter.
Interview answer
"Instead of stuffing documents into the prompt (the instructions and text given to the AI), I give the model a short stub and tools (a function the AI can call, such as policy search) to fetch what it needs, with size caps and a round limit. The window stays small and current, and every fact used has a source."
All data in this post is made up. No real people, tickets or patient data.
← Back to all 27 solutions in the state management blog
Key terms
Every highlighted word in this post links here. Click ↩ Back to return to the spot you came from.
- agent
- An AI that chooses which tools to use to answer.Used in: The problem it solves, How to implement it (ServiceApps)↩ Back to where you were
- AI Assist
- The app's chat helper for staff questions.Used in: In NurseOps Now↩ Back to where you were
- dynamic context loading
- Giving the AI tools to fetch data only when it needs it, instead of putting everything in the prompt.Used in: In plain words↩ Back to where you were
- incident
- A ServiceApps ticket for something broken.Used in: How to implement it (ServiceApps)↩ Back to where you were
- KB
- Knowledge base: a library of help articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
- KB article
- One help-center article in a knowledge base, with a number like KB0010234.Used in: How to implement it (ServiceApps)↩ Back to where you were
- knowledge base
- A library of help articles; in ServiceApps, a named group of KB articles.Used in: The problem it solves↩ Back to where you were
- latency
- How long it takes to respond.Used in: Trade-offs↩ Back to where you were
- loss of instructional integrity
- The AI losing its rules because they were pushed out of the window.Used in: The problem it solves↩ Back to where you were
- prompt
- The instructions and text given to the AI.Used in: In plain words, The problem it solves, Interview answer↩ Back to where you were
- ServiceApps
- A company platform for IT tickets, HR requests and help-center articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
- the token window is a hard limit
- Everything sent to the AI shares one fixed size budget.Used in: The problem it solves↩ Back to where you were
- tool
- A function the AI can call, such as policy search.Used in: In plain words, The problem it solves, How to implement it (ServiceApps), In NurseOps Now, Trade-offs, Interview answer↩ Back to where you were