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.
- Trace one customer turn that uses a tool, model call by model call, and say what each request must carry.
- Spot a fact that 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 in a website chat asks where an order is; the assistant looks it up and gives a delivery date. Two questions later the customer asks what they paid, and the reply acts as if the order was never looked up. Yet the application still has the order.
For each reply, the application makes a model call: it sends the model a request, the text and data for one reply, and receives that reply.
Brightline is an invented home-internet provider. 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. It has three tools, programs the application runs when the model asks for one: lookup_order, issue_refund and search_help. Afterwards you can read the record of one call, tell which facts its request carried and which stayed in the application's records, and say what the next request needs.
Stateless calls
LLM API Requests and Responses took a request apart: a system prompt and a list of messages, each tagged with a role, joined with marker tokens into one sequence the model continues, and an application that resends the whole chat on every turn. The context window counts everything the request carries plus the reply. [1,2,8]
Why resend? A reply is computed from the request and the model's weights, the numbers that training set. As Pretraining and Post-Training showed, answering a request reads them and leaves them unchanged. So once the reply is out, nothing of the request remains in the model.
The window is a working space apart from what training stored. Anthropic's model API, the Messages API, is stateless: the application sends the full conversation history with every request. [1,2]
A request handled this way is a stateless call: nothing of it is kept for the next one. Anything that must last is stored outside the model, by the application or a provider service (one the model's provider runs), and counts on a later call only when its request carries it again. [1,6]
What the model can use on one call
Two places hold information about a chat: the request and the application's storage. Model-visible context is everything one request carries, and it is all the model can use about this chat on that call. Conversation state is what the application, or a provider service, keeps between calls: the messages so far, earlier tool results, and facts such as a customer's order number. [1,4,6,7]
State can hold more than any one request: the application chooses what to copy into each call and can leave a saved item out without deleting it. A fact in state but not in the request does not exist for the model on that call. [4,7]
Besides messages, a request can carry the items below, each model-visible only on a call whose request carries it:
- Tool definitions: a tool's name, a description and a schema for its input, sent with the request so the model knows the tool exists and how to ask for it, though never its code. [3,4]
- Tool results: the output of a tool the application ran, returned in the next request. [3]
- Retrieved evidence, as Instruction Hierarchy described it: text the application looks up in a set of documents, a search index or a database and places in the request, such as the help page that
search_helpreturns. - Few-shot examples: sample inputs paired with the output wanted, drawn from storage and placed in the prompt. [4]
- 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 how to ask for an order, and nothing about any particular order, such as 8841, until a tool result for it is in the request. [3]
Where an item sits and which role carries it are part of what the model sees too: a message in the system role carries a system instruction's authority. [1,8]
A tool result or a retrieved page is untrusted context, as Instruction Hierarchy showed: it supplies facts and, under the instruction hierarchy, gives no orders.
How an application decides where each item goes is the subject of Context Selection, Prioritization and Assembly.
One turn, several calls
Customer C-204 types "Where is my order 8841?". Call 1 carries the system prompt, the three tool definitions and that message. The model returns no words but a tool call: run lookup_order for order 8841. The model runs nothing itself, so the application runs the tool and stores the result, invented here: [3]
{"order_id": "8841", "customer": "C-204", "item": "Wi-Fi 7 router",
"price": "$129.00", "delivery": "12 Nov"}The turn, call by call:
| call | the request carries | the model returns |
|---|---|---|
| 1 | system prompt, 3 tool definitions, the customer's message | tool call: lookup_order, order 8841 |
| 2 | all of call 1, that tool call, the tool result | reply: "Your Wi-Fi 7 router arrives on 12 November." |
The reply repeats the item and the date; the price sits only in the tool result.
One customer turn took two calls, and can take more: after each tool call the application runs the tool, adds the result to its state and sends a new request, until a call returns a reply. Each call is stateless, so each request must carry what its step needs: without the result, call 2 would know nothing of the lookup. Such a loop, where the model chooses the next step, is commonly called an agent loop. [3,4]
The step between state and request is context assembly: the application picks from its state what the next request carries, and in what form. In pseudo-code, with invented names and no real library: [4]
def answer_turn(state, customer_text):
state.add_message("user", customer_text)
while True:
request = build_request(state) # system prompt, tool definitions,
# messages the application keeps,
# facts this step needs
response = call_model(request)
save_trace(request, response)
if response.kind == "tool_call":
result = run_tool(response.tool_name, response.arguments)
state.add_tool_step(response, result)
else:
state.add_message("assistant", response.text)
return response.textsave_trace writes a request trace for every call: the exact request that was sent, with every part the model received, and the response it returned. build_request makes the choices; the trace shows what they produced.
Writing tool definitions and handling their calls in detail is the subject of Function Calling from First Principles.
Sessions and threads kept for you
The application need not store the chat itself: a provider or an SDK layer can keep the history and put it into each call. An OpenAI Agents SDK session, for example, fetches the stored history before each run and places it in front of the new input, and a provider-side thread lets each request send only the new messages. [1,5]
That changes who assembles the request, not what the model can use: the model still reads only what that layer placed into the call, and nothing is kept in its weights. In the loop above, only the history store moves.
You then see less of the assembly, so use what the layer shows. Claude Code, for example, prints a live breakdown of its context window by category when you run /context. [7]
Worked example
The support assistant keeps its own state. To keep requests short, its context assembly follows a history policy, invented here: keep every message, and drop the tool calls and results of turns older than the previous turn. Its state still holds every result. In turn two the customer asks about changing the delivery address, answered from a search_help page. Turn three asks "How much did I pay for the router?". Here is the trace of its first call, then the stored state, both invented and simplified:
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 my order 8841?
assistant: Your Wi-Fi 7 router arrives on 12 November.
user: Can I change the delivery address?
assistant: [tool call] search_help: "change delivery address"
tool: [help page] An address can be changed until the order ships.
assistant: Yes, you can change it until the order ships.
user: How much did I pay for the router?conversation state: C-204
messages: every message of turns 1 to 3
tool results: turn 1 lookup_order 8841 -> Wi-Fi 7 router, $129.00, 12 Nov
turn 2 search_help -> address-change pageBefore reading on, predict: what can the model use about order 8841 on this call?
It has the tool lookup_order, the order number and its earlier reply: a Wi-Fi 7 router due on 12 November. It lacks the price: the policy dropped the result that held $129.00, and no message repeats it. The model can ask for lookup_order again, which costs another call, or reply without the price. The tool's definition gave it a way to ask, not the answer.
The state record holds $129.00 and the policy looks like a harmless trim, so neither shows that the price never reached the model. To know what the model saw, read the trace of the request that was sent.
The fix is a different assembly from the same state. For this call, build_request puts the turn-one lookup back in its place, the tool call followed by its result:
request trace: support-assistant, turn 3, call 1, after the fix
system: You are Brightline's support assistant. Signed-in customer: C-204.
tools: lookup_order, issue_refund, search_help (definitions)
user: Where is my order 8841?
assistant: [tool call] lookup_order: order_id 8841
tool: {"order_id": "8841", "item": "Wi-Fi 7 router", "price": "$129.00", "delivery": "12 Nov"}
assistant: Your Wi-Fi 7 router arrives on 12 November.
(turn two unchanged)
user: How much did I pay for the router?The reply can then state the price, for example (invented) "You paid $129.00 for the Wi-Fi 7 router." A shorter fix adds a labelled note from state: "From the turn-one lookup of order 8841: price $129.00". Either way, the stored state is the same before and after the fix: only the new request makes the price model-visible, and its trace shows the line that does it.
Deciding what each request carries, call after call, so that the model gets the facts and tools its task needs in a form it can use, is called context engineering, and it is the subject of Prompt Engineering and Context Engineering. [4]
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.
- Chat templates (Hugging Face Transformers docs). Hugging Face. 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.