📦 Moved to new directory. Last updated 12.2.2026. New location: claude-config/library/03-memory-state/deep-dives/state-04-token-budgets.html

Deep dive 4 of 27: Agentic Outcome: Token Budgets

Nov 19, 2026 · Michael Chang · Status in NurseOps Now: 🟡 partly 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 Context and State Management (Intro) · All 27 solutions · ← Three-Tier Memory: Episodic (Experience Log) · Agentic Outcome: Hybrid Memory Systems →

Read in this order

  1. In plain words: what it is, without jargon
  2. The problem it solves: the problem, and the standard approach in my words
  3. How to implement it (ServiceApps): scenario, steps, code and real output
  4. In NurseOps Now: built or not, and where
  5. Trade-offs and Interview answer

In plain words

A token (the unit the AI reads and is billed by, about three quarters of a word) budget decides, before each call, how much of the window each part may use: the rules, tool (a function the AI can call, such as policy search) results, history, and room for the answer. Without a plan, one big tool (a function the AI can call, such as policy search) result or a long chat silently crowds out everything else.

In plain terms: a monthly budget with a line for rent, food and savings, instead of spending until the money runs out.

The problem it solves

The context window: finite, expensive, volatile (the window is limited, paid per token, and gone after each call) and Flooding the context window (sending so much that the AI loses its instructions): everything competes for one fixed space, and the part that loses is usually the rules or the answer.

The standard approach (in my words): engineer the window like a budget, compressing and summarizing progressively as it fills.

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. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist has a long chat and three large KB (knowledge base: a library of help articles)/ticket results to include. Each zone gets a share of an 8,000-token window.

Steps.

  1. Pick the model's window size and reserve room for the answer first.
  2. Give each zone a share (rules, tool (a function the AI can call, such as policy search) results, history, answer).
  3. Fill each zone newest or most relevant first, stopping at its limit.
  4. Log what was dropped, so you can tune the shares.

The code (Python):

CONTEXT = 8000                                          # small on purpose for the example
SHARE = {"system": 0.10, "tools": 0.35, "history": 0.30, "answer": 0.25}
def tokens(text): return -(-len(text) // 4)             # rough: ~4 characters per token

def fit(items, limit):                                   # keep the newest items that fit
    kept, used = [], 0
    for it in reversed(items):
        t = tokens(it)
        if used + t > limit:
            break
        kept.insert(0, it); used += t
    return kept, used

limits = {k: int(CONTEXT * v) for k, v in SHARE.items()}
history = [f"turn {i:02d}: " + "x" * 600 for i in range(1, 21)]                     # 20 turns of ~150 tokens
tool_results = ["KB0010234 " + "y" * 3000, "INC0012345 " + "z" * 4000, "KB0020311 " + "w" * 9000]
h, hu = fit(history, limits["history"])
t, tu = fit(tool_results, limits["tools"])
print("limits:", limits)
print(f"history: kept {len(h)} of {len(history)} turns ({hu} tokens), oldest kept: {h[0][:8]}")
print(f"tools:   kept {len(t)} of {len(tool_results)} results ({tu} tokens): {[x.split()[0] for x in t]}")
print("answer room reserved:", limits["answer"], "tokens")

Output (from running the code above):

limits: {'system': 800, 'tools': 2800, 'history': 2400, 'answer': 2000}
history: kept 15 of 20 turns (2295 tokens), oldest kept: turn 06:
tools:   kept 1 of 3 results (2253 tokens): ['KB0020311']
answer room reserved: 2000 tokens

What to watch for.

In plain terms: each part of the prompt (the instructions and text given to the AI) gets its own envelope of money, and nothing can borrow from the rules or the answer.

In NurseOps Now

Partly built. NurseOps Now limits by count, not tokens (pieces of words the AI reads and writes; cost is per token): the last 10 turns, questions cut at 2,000 characters, each tool (a function the AI can call, such as policy search) result at 12,000 characters, at most 4 tool (a function the AI can call, such as policy search) rounds, and a fixed max_tokens for the answer. Token (the unit the AI reads and is billed by, about three quarters of a word) usage is recorded after each call, but there is no budget check before it (Plan 1).

Trade-offs

Interview answer

"I budget the window like money: reserve room for the answer, give rules, tools (a function the AI can call, such as policy search) and history fixed shares, and fill each zone by relevance up to its limit. It stops one huge tool (a function the AI can call, such as policy search) result from pushing out the rules, and the logs show what got dropped."

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.

flooding the context window
Sending so much that the AI loses its instructions.Used in: The problem it solves↩ 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
prompt
The instructions and text given to the AI.Used in: How to implement it (ServiceApps)↩ Back to where you were
provider
The doctor or clinic asking for the test.Used in: How to implement it (ServiceApps)↩ 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 context window: finite, expensive, volatile
The window is limited, paid per token, and gone after each call.Used in: The problem it solves↩ Back to where you were
token
The unit the AI reads and is billed by, about three quarters of a word.Used in: In plain words, How to implement it (ServiceApps), In NurseOps Now↩ Back to where you were
tokens
Pieces of words the AI reads and writes; cost is per token.Used in: In NurseOps Now↩ Back to where you were
tool
A function the AI can call, such as policy search.Used in: In plain words, How to implement it (ServiceApps), In NurseOps Now, Interview answer↩ Back to where you were