📦 Moved to new directory. Last updated 12.2.2026. New location: claude-config/library/03-memory-state/deep-dives/state-01-short-term-context-window.html

Deep dive 1 of 27: Three-Tier Memory: Short-Term (Context Window)

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 Context and State Management (Intro) · All 27 solutions · Three-Tier Memory: Long-Term (Vector Store) →

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

Short-term memory is simply what the AI can see in this one call: its rules, the recent conversation, and the question. Nothing else exists for the model. Building that window well, every single time, is the first job of any AI assistant.

In plain terms: the papers on your desk right now; anything in the drawer might as well not exist until you take it out.

The problem it solves

LLMs are stateless (language models remember nothing between calls): the model forgets everything between calls, so the app must rebuild what it should know on every call. If it rebuilds too little, the AI forgets; too much, and it gets slow, costly and distracted.

The standard approach (in my words): treat the context window (everything sent to the AI in one call; it has a size limit) as the short-term tier (the AI's suggestion: likely approve, needs review or likely deny) of memory: a small, deliberately assembled workspace, separate from long-term storage and the event log.

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. An employee chats with ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist about a VPN problem on ticket INC0012345. Each new question must be sent with the rules and only the recent turns.

Steps.

  1. Keep the rules (system prompt (the standing instructions that set the AI's rules and role)) as a separate fixed text, not as the first chat message.
  2. Store every turn, but send only the last N user + assistant pairs.
  3. Add a one-line note about what the user is looking at (the ticket), not the whole ticket.
  4. Put the new question last, so it gets the most attention.

The code (Python):

SYSTEM = "You are ServiceApps Assist. Answer IT and HR questions from KB articles and the user's tickets. Cite KB numbers."
history = [("user", "My VPN keeps dropping"), ("assistant", "Which error code do you see? (KB0010234)"),
           ("user", "Error 809"), ("assistant", "809 means the VPN can't reach the server. Are you on guest Wi-Fi?"),
           ("user", "Yes, at a hotel"), ("assistant", "Turn off guest Wi-Fi or use your phone hotspot, then restart the client.")]
MAX_TURNS = 2   # send the last 2 user+assistant pairs

def build_window(history, question, ticket=None):
    recent = history[-2 * MAX_TURNS:]
    note = f"(The user is looking at ticket {ticket}.) " if ticket else ""
    return {"system": SYSTEM,
            "messages": [{"role": r, "content": t} for r, t in recent] + [{"role": "user", "content": note + question}]}

w = build_window(history, "Still failing on my hotspot", ticket="INC0012345")
print("system:", w["system"][:44] + "...")
for m in w["messages"]:
    print(f'{m["role"]:9s} {m["content"]}')
print(f"sent {len(w['messages'])} of {len(history) + 1} messages")

Output (from running the code above):

system: You are ServiceApps Assist. Answer IT and HR...
user      Error 809
assistant 809 means the VPN can't reach the server. Are you on guest Wi-Fi?
user      Yes, at a hotel
assistant Turn off guest Wi-Fi or use your phone hotspot, then restart the client.
user      (The user is looking at ticket INC0012345.) Still failing on my hotspot
sent 5 of 7 messages

What to watch for.

In plain terms: the assistant only ever sees a clean desk: the rulebook, the last few messages and a sticky note saying which ticket you're on.

In NurseOps Now

Built. claude_answer() in backend/app/services/assist.py sends the rules in the API's system field, the last ASSIST_TURNS (10) turns, and a note like "(The user is looking at case 3.)". The demo in the parent post stored 12 turns and sent 10. See Step 2.

Trade-offs

Interview answer

"Short-term memory is just the context window (everything sent to the AI in one call; it has a size limit), so I rebuild it on every call on purpose: the rules in the system field, only the last few turns, a one-line pointer to what the user is looking at, and the question last. Everything else lives (using the real Claude API (costs money), not a fake stand-in) outside and is fetched when needed."

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.

context window
Everything sent to the AI in one call; it has a size limit.Used in: The problem it solves, Interview answer↩ 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
live
Using the real Claude API (costs money), not a fake stand-in.Used in: Interview answer↩ Back to where you were
llms are stateless
Language models remember nothing between calls.Used in: The problem it solves↩ 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
system prompt
The standing instructions that set the AI's rules and role.Used in: How to implement it (ServiceApps)↩ Back to where you were
system prompt pinning
Keeping the rules in a protected place that is sent on every call and never trimmed.Used in: How to implement it (ServiceApps)↩ Back to where you were
tier
The AI's suggestion: likely approve, needs review or likely deny.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: Trade-offs↩ Back to where you were
token counting middleware
Code that counts tokens before every AI call and acts when the window gets too full.Used in: How to implement it (ServiceApps)↩ Back to where you were
tokens
Pieces of words the AI reads and writes; cost is per token.Used in: How to implement it (ServiceApps)↩ Back to where you were