CH 02 · The Agent Loop Pattern · 03/15
Read as one pageWhy both the request and the result must be appended
A subtlety that trips up first implementations: when the model requests a tool, you must append both the model's tool-request turn and the tool-result turn before the next call. The providers require this pairing: the model needs to see "I asked for X, and X returned Y" to continue coherently. Most provider APIs also require that every tool call in a turn gets a corresponding result. Skipping a result, or mismatching ids, breaks the next call. A robust loop therefore guarantees a result for every call, synthesising an error result if a tool failed to produce one.
Field check
See it worked. Then try it.
Keep the request and the observation together, so the next model call can reconstruct what happened.
Worked examples
A calendar lookup returns three meetings.
Append the assistant’s lookup request and the matching tool result. The model can now connect those meetings to the requested date.
The lookup times out.
Keep the request and append a matching error result. A failure is still an observation the model needs.
Finished this idea?
Your learning progress stays in this browser.