Agent ArchitectureRuntime and effect recoveryStaff
How should an agent correlate parallel tool results when calls finish out of order or retry?
By Amit Kumar2 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
The model requests invoices 7 and 9 in one turn. Invoice 9 finishes first, both replies validate, and invoice 7 is shown with invoice 9’s amount. Design immutable call-to-RPC correlation and result admission, including duplicates, timeouts and a late first attempt after an accepted retry.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
Each result must be matched to the call that produced it. Completion order carries no such identity. If the bridge appends results to a list and zips that list with the model's original calls, the first completed result gets attached to the first requested call. Identical tool names and identical result schemas make this especially easy to miss. OpenAI's function-calling guide includes an ID on each tool call to submit the corresponding result. The MCP JSON-RPC request and response contract likewise uses request IDs for protocol-level correlation. An application with a separate model call ID and downstream RPC ID has to preserve their mapping explicitly.
I would retain an immutable record for each logical call: run, turn, model call ID, tool identity, validated arguments and accepted attempt. When a response arrives, look up that call ID and verify it is still pending for this run and attempt. Attach the result under that ID, regardless of arrival order. If invoice 7 times out and is retried, a late first attempt must not overwrite the accepted retry. A duplicate callback should be a no-op with an audit record, not a second result inserted into context.
In a hypothetical trace, model calls C7 and C9 map to downstream requests R17 and R19. R19 returns invoice 9 with amount 90 before R17 returns invoice 7 with amount 70. Resolve R19→C9 and R17→C7 before building the next model input. A list sorted by arrival cannot replace that mapping. Retain original observations in the operation history, but apply the run’s acceptance rule before admitting an older attempt into current context. A valid late observation must not overwrite the selected result simply because it arrived last.
The test is small: reverse completion order, add one error, duplicate a callback and let a timed-out first attempt arrive after the retry. The model must see the right invoice ID beside each amount, and a missing call must remain missing. If your application turns tool output into a natural-language observation, include the call's requested invoice ID from trusted runtime metadata, not only an invoice ID echoed by the external service.
The bridge loses the call-to-response mapping before the next model turn begins. Once the model has seen invoice 9's amount under invoice 7's call, a later citation check cannot reconstruct what it should have seen.
Related questions
Keep practising agent architecture
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux