Model Context and Conversation State
In this article
- Explain why a model call keeps nothing for the next one, and where continuity between calls comes from.
- Tell, from the trace of one call and the application's stored state, which facts the model could use and which the application only held.
- Follow one customer turn through a tool loop, call by call, and say what each request must carry.
- Find a fact the next request dropped and name the smallest change that makes it usable again.
- Terms defined here: stateless call, model-visible context, conversation state, context assembly, trace.
Overview
A customer asks a support chat where their order is. The assistant looks it up and gives a delivery date. Two messages later the customer asks what they paid, and the reply acts as if the order was never looked up, though the application's database still holds the full lookup. Where did the order go?
The chat belongs to Brightline, an invented home-internet provider (its orders and numbers are made up). Its support assistant, a chat assistant on its website, answers customers, can look up an order and can issue a refund up to an approved limit, through three tools: lookup_order, issue_refund and search_help.
The answer is a boundary: the model can use only what the current request carries, however close by the rest is stored.
Why the model forgets
LLM API Requests and Responses took a request apart: a system prompt and messages tagged with a role, joined with marker tokens into one sequence, with the application resending the whole chat on every turn. The context window counts everything the request carries plus the reply. [1,2]
Why resend? The model computes a reply from the request and its weights, and, as Pretraining and Post-Training showed, reading a request leaves the weights unchanged, so nothing of the request stays in the model. Anthropic's Messages API says so plainly: it is stateless, and the caller sends the full conversation history every time. [1]
So every request is a stateless call. Anything that must last between calls is stored outside the model, by the application or by a service the model's provider runs. [1,5]
What the model sees and what the application holds
Two places now hold information about one chat. Model-visible context is everything one request carries; on that call, it is all the model can use. Conversation state is what the application, or a provider service, keeps between calls: messages, tool results, facts such as an order number. LangChain draws the same line: a model call's input lasts for that call, state is saved across turns, and one can change without the other. [4,6]
State usually holds more than any one request. A fact the application holds but did not put into the request, and the provider did not add, does not exist for the model on that call.
Besides messages, a request can carry these, each model-visible only on a call whose request carries it:
- Tool definitions: a tool's name, description and input schema, sent so the model knows the tool exists and how to ask for it. The model never gets the tool's code. [3]
- Tool results: what a tool returned when the application ran it, sent back in the next request. [3]
- Retrieved evidence: text the application looks up in a document set, a search index or a database and places in the request, such as a help page from
search_help. - Few-shot examples placed in the prompt.
- A summary the application wrote of earlier turns, which later calls see in place of those turns. [4]
A tool definition carries no data. A model that sees lookup_order among its tools knows it may ask for an order, and knows nothing about order 8841 until a tool result for it is in the request.
Where an item sits and which role carries it are part of what the model sees too. A tool result or a retrieved page is untrusted context: under the instruction hierarchy it supplies facts, not orders. How to order the items is a choice made at assembly time.
One turn, several calls
Customer C-204 writes "Where is order 8841?".
Call 1 carries the system prompt, the three tool definitions and that message. The reply is a tool call: run lookup_order with order id 8841. The model runs nothing itself, so the application queries Brightline's order system and stores the tool result: [3]
{"order_id": "8841", "status": "shipped", "delivery": "2025-12-03",
"router": "BL-2 Mesh", "price": "$129.00", "carrier": "Northway Freight"}Call 2 carries everything call 1 did, plus the tool call and its result. Now the model writes text: "Order 8841 has shipped and arrives on 3 December." The price is in the tool result, not in the reply.
| call | the request carries | the model returns |
|---|---|---|
| 1 | system prompt, 3 tool definitions, customer message | tool call: lookup_order, order 8841 |
| 2 | all of call 1, the tool call, the tool result | reply with the delivery date |
One customer message took two model calls; a harder question takes more. The application builds a request and calls the model; on a tool call it runs the tool, adds the result to its state and builds the next request, until a reply comes back. When the model picks each next step like this, the loop is commonly called an agent loop. [3]
Each call in the loop is stateless: call 2 knows about the lookup only because its request carries the result.
The step that turns state into the next request is context assembly: the application picks from its state what the next request carries and in what form. [4]
Here is assembly dropping a fact. The script applies an invented policy (keep every message, drop tool results from turns before the last one) to a small Brightline state and checks where the price ends up, without and with a note from state:
import json
lookup = {"order_id": "8841", "status": "shipped", "delivery": "2025-12-03",
"router": "BL-2 Mesh", "price": "$129.00"}
state = [
(1, "user", "Where is order 8841?"),
(1, "tool", json.dumps(lookup)),
(1, "assistant", "Order 8841 has shipped and arrives on 3 December."),
(2, "user", "Can I move my installation visit?"),
(2, "assistant", "Yes, from your account page."),
(3, "user", "How much did I pay for that order?"),
]
def build_request(state, turn, note=None):
keep = [m for m in state if m[1] != "tool" or m[0] >= turn - 1]
request = [f"{role}: {text}" for _, role, text in keep]
if note:
request.insert(-1, f"note: {note}")
return request
for note in (None, "Order 8841 (from lookup_order): price $129.00"):
request = build_request(state, turn=3, note=note)
in_state = any("$129.00" in m[2] for m in state)
in_request = any("$129.00" in line for line in request)
print(f"lines={len(request)} price_in_state={in_state} "
f"price_in_request={in_request}")lines=5 price_in_state=True price_in_request=False
lines=6 price_in_state=True price_in_request=TrueSame state, two different requests, and only the second lets the model answer.
Sessions and threads kept for you
A provider or SDK layer can store the history and put it into each call for you: an OpenAI Agents SDK session fetches the stored history before each run and places it in front of the new input. [5]
That moves the assembly, not the boundary. The model still reads only what that layer put into the call, and a layer that trims history can drop a fact as quietly as your own code.
Worked example
The support assistant assembles requests with the policy above, which also drops the tool calls that asked for the dropped results. In turn two the customer asks about moving an installation visit. In turn three: "How much did I pay for that order?"
Below is that call's request trace, the record of one model call: the exact request sent, with every part the model received, and the response that came back. Under it is the stored state at the same moment.
request trace: support-assistant, turn 3, call 1
system: You are Brightline's support assistant. Signed-in customer: C-204.
tools: lookup_order, issue_refund, search_help (definitions)
user: Where is order 8841?
assistant: Order 8841 has shipped and arrives on 3 December.
user: Can I move my installation visit?
assistant: Yes, from your account page.
user: How much did I pay for that order?conversation state: C-204
messages: every message of turns 1 to 3
tool results: turn 1 lookup_order 8841 -> shipped, 3 Dec, BL-2 Mesh, $129.00Before reading on, decide what the model can use about order 8841 on this call.
It has the order number, its own earlier reply with the delivery date, and the definition of lookup_order. It lacks the price: the policy dropped the result that held $129.00, and the turn-one reply gave only the date. It can call lookup_order again, at the cost of another call, or answer without the price. The tool definition gave it a way to ask, not the answer.
The state shows $129.00 and the policy looks like a harmless trim, so neither reveals that the price never reached the model. To know what the model saw, read the trace of the request that was sent, not the state or the code meant to build it.
The fix is a different assembly from the same state: put the fact back, as the original tool call and result or as a short labelled note placed before the question:
note: Order 8841 (from lookup_order): price $129.00
user: How much did I pay for that order?The reply can then state the price, for example "You paid $129.00 for order 8841." The stored state is the same for both requests; only the second request makes the price model-visible, and its trace shows the line that does it.
:::note In practice When a reply ignores something the application "already knew", first check whether the fact was in the request. Log the full request of every call. In Claude Code, /context gives a live breakdown of what fills the context window. [7] :::
Choosing what each request carries, call after call, is what people call context engineering. [4]
Common mistakes
- Debugging from the database. State is where a fact lives; the request trace shows whether it reached the model.
- Treating a tool definition as data. It tells the model it may ask; only a tool result gives an order's details.
- Checking only the first call of a turn. Every call is assembled separately, so a fact can vanish between call 2 and call 3.
Sources
- Using the Messages API. Anthropic. Checked 8 Nov 2026.
- Context windows. Anthropic. Checked 24 Oct 2026.
- How tool use works. Anthropic. Checked 24 Oct 2026.
- Context engineering in agents (LangChain docs). LangChain. Checked 24 Oct 2026.
- Sessions (OpenAI Agents SDK docs). OpenAI. Checked 25 Oct 2026.
- Agent context (Google ADK docs). Google. Checked 24 Oct 2026.
- Explore the context window. Anthropic. Checked 24 Oct 2026.
Check yourself
Check yourself
Question 1 of 5
A team stops resending its assistant's chat history and moves it to a provider-side thread. Each request now sends only the new message, yet replies still use earlier turns. How do those turns reach the model?
Your first check counts towards your result.