Agent loop
Python Agent Loop Interview Questions
An agent is a loop around a model call, not a cleverer model. The model answers or it asks for a tool; the code reads which of the two happened, runs the tool, sends the result back, and goes round again until there is an answer or the budget is gone. Every interview question here is about that loop, because that is the part you write. You write it against the OpenAI client, the call and the response you unwrap being the ones you would write in a project, and it is the loop around them that is marked.
What agent loop questions ask you to do
Across the questions here, these are the shapes that come up:
- Call a model until it answers instead of asking for a tool
- Dispatch a tool call and feed the result back in
- Stop after a number of steps rather than when the model decides
- Handle a tool the model asked for that does not exist
- Keep the conversation under a token budget as it grows
Common mistakes with agent loop
A loop with no ceiling, which a model that keeps asking for tools turns into a bill. The other is calling once more than needed: reading the answer after the loop rather than inside it costs an extra call on every question, and in an interview it is the thing the interviewer is watching for.
Questions to practice
Questions last reviewed 19 October 2026.
Roles this comes up in
Companies these come from
Other topics
- Filtering7
- Logical operators4
- Calculations11
- Conditional logic12
- NULL handling9
- Dates16
- Joins15
- Aggregations14
- Subqueries5
- Window functions32
- Reshaping15
- Arrays6
- Strings11
- Hashing8
- Two pointers4
- Sliding window1
- Binary search4
- Sorting1
- Math3
- Lists5
- Tuples3
- Dictionaries3
- Ranking16
- Running totals10
- Deduplication2
- Chunking1
- Similarity1
- Token budget2
- Parsing4
- Backoff3
- Cost1