Agent ArchitectureRuntime and effect recoveryPrincipal
How can an agent prove a paginated audit covered the complete authorized dataset?
By Amit Kumar2 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
An invoice tool returns 100 rows, nextToken and HTTP200 from a 3,500-invoice month. The agent reports no duplicates across all invoices. Design page/query completion state, persistent scan progress and snapshot/cursor handling. Explain a partial deadline result and why it cannot authorize a whole-population financial decision.
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
The tool call succeeded at returning one page. It did not certify completeness of the requested set. Many APIs paginate a query, and AWS's CLI pagination guide gives a concrete example where 3,500 objects require multiple underlying calls. nextToken means there is more work under this interface, not an optional decoration in a text blob. A model that sees a plausible list of 100 rows can still mistake a page for the population unless the tool and agent protocol preserve the completion state explicitly.
I would separate page_status from query_status. The query result should carry a stable query ID or snapshot token, rows scanned, pages fetched, continuation, errors and whether the scan completed. The agent's report may say “I checked the first 100 invoices” after one page. It may say “all matching invoices” only after the paginator reaches a verified terminal state under a consistent query. If the backend has a server-side duplicate aggregation, that may be safer and cheaper than pulling every invoice into model context, but inspect what fields it compares and whether it covers the whole authorized set.
Completing pages introduces another problem. The underlying dataset may change during the scan. If a new invoice arrives or ordering shifts between pages, an offset-based paginator can repeat or skip rows. A continuation token is not automatically a snapshot guarantee. Read the provider's consistency contract, use a snapshot or stable cursor when available, and bound the audit to a defined time window. Keep row IDs for deduplication and a count or reconciliation against the authoritative source. If a page fails, retries must not silently restart at page one and mark the job complete. Store progress outside the model context so a long scan survives compaction and restarts.
The interviewer might ask for an immediate answer before all 3,500 rows can be checked. Report a partial result and its exact scope. Do not infer a global negative from a prefix. For a financial action, a partially scanned “no duplicate” must not authorize payment. Test empty pages with continuation, duplicate rows across pages, expired tokens, permission changes, and a backend that caps results at 100 without a continuation. The invariant is that a claim about the whole set requires proof of whole-set coverage, not simply a successful tool response.
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