AI-103 Practice Question 65: Chat Completions History Truncation
Microsoft Azure AI Apps and Agents Developer Associate (AI-103) · Test 7 · question 5 of 10
A developer builds a support chatbot by calling the Azure OpenAI chat completions API directly: each turn, the app appends the new user message to a list and resends the entire list as the messages array. After about 40 turns in one long session, requests start failing with an error about exceeding the model's maximum context length.
What is the most likely fix?
Show answer and explanation
Answer:
The chat completions API is stateless: the caller is responsible for what goes in messages on every request, and Microsoft's guidance is direct: "it's your responsibility to ensure that the prompt and completion fall within the token limit," with truncation strategies such as removing the oldest complete turns while preserving the system message. That is exactly the app's problem: it resends unbounded history instead of managing it.
- A is wrong because a deployment's SKU governs throughput and capacity (tokens per minute, concurrency), not the model's maximum context length, which is a property of the model itself. - C is wrong because prompt caching reduces latency and cost for a repeated prefix; it does not change how many tokens count toward the context window; the full prompt is still subject to the limit. - D is wrong because Foundry Agent Service threads have a large but still finite message limit (up to 100,000 messages) and the service manages truncation for *its own* context assembly; switching architectures is a bigger change than the problem calls for, and it doesn't describe what the chat completions caller itself must do.
Reference: Work with chat completion models