Appending Tool Results for Coherent Replies
Explore how to maintain multi-turn conversation state by appending tool call results in the correct order. Learn to keep the model-facing history clean of transient UI data and ensure error handling flows properly. This lesson helps you build reliable, coherent AI assistant replies by managing state persistence and linkage between tool calls and their results.
We'll cover the following...
A common failure looks like this. The assistant asks to run get_invoice_status with an invoice id, your system runs the tool, and logs show a valid result came back. The next assistant message still says it cannot find the invoice, because the tool output never made it into the model-facing conversation history.
This lesson stays on the boundary between tool execution and the next model call. The point is to make the next-turn input include the right tool record, in the right place, so the assistant’s final message can reference it without guessing.
What the next model call must see
With the failure mode visible, the fix is to persist a minimum set of ...