Conversation History Is Input You Rebuild

Conversation History Is Input You Rebuild
The assistant explains that production releases need human approval. You ask, "What about staging?"
That question is almost empty outside the conversation. Which repository? Which policy? What distinction did the previous answer make?
A chat interface encourages us to treat the conversation as a shared place. For the application, it is stored state that must become usable input again. That difference shows up as soon as a follow-up stops making sense.
I would inspect the reconstructed history before asking the model to remember more carefully. Sometimes the application has forgotten on its behalf.
The transcript and the next request are different objects
A transcript is a record of what happened. Request history is the selected representation of prior events supplied for the next invocation. They can overlap without being identical.
The application might retain a transcript for an authorized purpose but send only recent turns and a summary. It might reload a current policy instead of resending an old search result. It might omit content the current user can no longer access.
Those are decisions, not implementation details to leave implicit. A transcript retained forever is not automatically a good input policy. A small prompt is not proof that the relevant decision survived.
Provider contracts also differ. Anthropic's Messages guide, checked November 26, documents sending conversation history and separately describes a managed-thread facility. A stateful interface does not mean every item in every previous interaction is guaranteed to remain available indefinitely.
For our fictional assistant, start with an application-owned history. This makes the mechanism visible without choosing a provider's storage lifetime as part of the lesson.
Tools leave relationships, not just text
A tool call is a request for the surrounding application to execute an operation. A tool result is the returned observation. An identifier connects the result to the call that requested it.
If the history contains "approval required" without its source or request, the model may still use the text. The application has made it harder to establish where that observation came from. Some APIs also reject malformed call/result sequences outright.
Our own small ledger represents the relationship explicitly. It is not a universal wire format, and the adapter must still satisfy the selected provider's grouping rules:
type HistoryItem = | { kind: 'user' | 'assistant'; text: string } | { kind: 'tool-call'; id: string; name: string; input: string } | { kind: 'tool-result'; callId: string; text: string }; function buildHistory(items: readonly HistoryItem[], question: string): HistoryItem[] { if (!question.trim()) throw new Error('A follow-up question is required'); const pending = new Set<string>(); const seen = new Set<string>(); for (const item of items) { if (item.kind === 'tool-call') { if (seen.has(item.id)) throw new Error('Duplicate tool-call identifier'); seen.add(item.id); pending.add(item.id); } else if (item.kind === 'tool-result') { if (!pending.delete(item.callId)) throw new Error('Result has no pending call'); } else if (pending.size > 0) { throw new Error('Incomplete tool exchange'); } } if (pending.size > 0) throw new Error('Missing tool result'); return [...items.map((item) => ({ ...item })), { kind: 'user', text: question.trim() }]; }
This example deliberately requires completed exchanges before adding a new user question. A production system may support interruption, tool cancellation or concurrent work. Those need explicit states and provider-compatible messages, not a missing result disguised as a completed operation.
The function also copies the records rather than adding the question to the array its caller still owns. Accidental mutation is a rather ordinary way to give the next request the wrong past.
Reconstruct one complete follow-up
Here is an offline conversation fixture, not a transcript from a deployed assistant:
const history: HistoryItem[] = [ { kind: 'user', text: 'Does production need approval?' }, { kind: 'tool-call', id: 'call-1', name: 'read-policy', input: 'release-policy-v3' }, { kind: 'tool-result', callId: 'call-1', text: 'Production requires human approval.' }, { kind: 'assistant', text: 'The supplied production policy requires approval.' }, ]; const followup = buildHistory(history, 'What about staging?');
The prior question, observation and answer survive. The new question is appended. That is enough to preserve the subject of the exchange, but not enough to answer the staging question correctly: the fixture contains no staging rule.
The appropriate next action could be retrieving a staging policy or asking for it. Continuity should preserve missing evidence as missing. It should not manufacture the unstated half of a comparison.
Our checks can also remove the tool-call record and confirm rejection of the orphan result. That establishes a history invariant in ordinary code. It does not show that a model will reason correctly over the accepted sequence.
An old observation does not become a current fact
Resending a policy result from yesterday can preserve the conversation and still provide stale evidence. Rebuilding history is an opportunity to distinguish the fact that a document was read from the claim that its contents remain current.
I would retain source identifiers and revisions where the task needs them, then reload authoritative material when freshness matters. A previous assistant answer is not an authoritative policy just because it has an assistant role.
Current application instructions should be reconstructed independently of the selected transcript. If a conversation tail happens to contain an old copy, that copy shouldn't silently override the current policy. Tool definitions also need to describe what can actually execute now. Preserving yesterday's tool name in a transcript does not make the tool available or authorized today.
Likewise, a summary of earlier work should identify itself as a summary. Promoting it to an application instruction changes its authority without adding evidence.
User and project isolation matter before all of this. The authenticated application must select the correct conversation namespace; a conversation ID proposed by a model is not permission to load another person's history. The tiny function above assumes the caller has already selected an authorized ledger.
Debug the selection, not an imagined memory
When a follow-up fails, I want to know which events were selected, which were replaced by summaries and which source versions were reloaded. Sanitized metadata may answer that without logging the entire private conversation.
This is also where context engineering becomes more specific than "include enough background." We need a policy for which history, instructions and evidence enter the next request together, under a finite budget.
The model may still need help resolving an ambiguous question. At least we can distinguish that from an application that sent "What about staging?" and hoped a conversation-shaped interface supplied the rest.
When you trim a conversation, which relationships must survive together? I would put those invariants in code before trying another summary prompt.
A note from the author
I’m Maksym Kuzmitskyi, a senior software developer working mainly with React and TypeScript. I build frontend applications and design workflows for working with AI in software delivery. If this article connects with something you’re working on, I’d love to hear from you.
More than a blog post
I share frontend news and the reasoning behind it throughout the day. Pick the language that feels natural to you.