Agent Loops, Stop Conditions and Token Budgets interview questions

27 questions from the Agent Loops, Stop Conditions and Token Budgets course, each with the correct answer and an explanation. Try to answer before you open the answer.

Anatomy of an Agent Loop

1. Which step of a turn runs the tools the model asked for?

  1. Call
  2. Act
  3. Append
  4. Inspect
Show answer

Answer: Act

Call asks the model, inspect reads its stop reason, act executes the tools, and append records results.

Lesson: The Structure of a Turn

2. What does stop_reason "max_tokens" tell you?

  1. The reply finished normally
  2. The reply may be cut off at your output limit
  3. The model refused the task
  4. The API key expired
Show answer

Answer: The reply may be cut off at your output limit

It means generation hit the output cap, so the content can be incomplete.

Lesson: Reading stop_reason

3. Each turn adds 1,000 tokens. About how many input tokens do 10 turns send in total?

  1. 10,000
  2. 100,000
  3. 55,000
  4. 1,000
Show answer

Answer: 55,000

Because history is resent, the total is 1,000 × (1 + … + 10) = 55,000.

Lesson: Why Cost Grows Faster Than Steps

4. Why centralise limits in one Budget object?

  1. Scattered checks are easy to forget or apply inconsistently
  2. Python requires classes
  3. It makes the model smarter
  4. It removes the need for tests
Show answer

Answer: Scattered checks are easy to forget or apply inconsistently

One owner of the limits keeps checks consistent and the stop reason easy to report.

Lesson: A Loop with Every Guard

Stop Conditions

5. Which is the strongest "done" condition?

  1. The model says it is finished
  2. The loop ran 10 times
  3. The test suite passes
  4. The reply was long
Show answer

Answer: The test suite passes

A passing test suite is evidence code can check; a claim is not.

Lesson: Defining "Done"

6. Which limit best catches a tool call that hangs for minutes?

  1. Step limit
  2. Wall-clock time limit
  3. Token limit
  4. Cost limit
Show answer

Answer: Wall-clock time limit

A hanging call uses few steps and tokens but a lot of real time.

Lesson: Hard Limits: Steps, Time, Tokens, Money

7. What does the RepeatGuard detect?

  1. Slow network speeds
  2. The same tool call with the same arguments repeating
  3. Spelling mistakes
  4. Missing API keys
Show answer

Answer: The same tool call with the same arguments repeating

It counts identical recent calls and flags a loop that is going nowhere.

Lesson: Detecting No Progress

8. Where is the safest place to check a cancel flag?

  1. In the middle of a file write
  2. Between turns, at a safe point
  3. Never
  4. Only after the process exits
Show answer

Answer: Between turns, at a safe point

Checking between turns avoids leaving half-finished side effects.

Lesson: External Stops and Cancellation

Token Budgets

9. Where do you find the exact tokens a call used?

  1. The usage object in the response
  2. The length of the prompt in characters
  3. The model name
  4. The HTTP status code
Show answer

Answer: The usage object in the response

The API reports exact input and output token counts for each response.

Lesson: Counting Tokens

10. Why reserve space for the model's reply?

  1. Replies are free
  2. If history fills the window there is no room left to answer
  3. It makes tools faster
  4. The API requires a reserve flag
Show answer

Answer: If history fills the window there is no room left to answer

Input and output share the window, so the reply needs guaranteed room.

Lesson: Allocating the Context Window

11. What does setting max_tokens higher do?

  1. Forces the model to write that many tokens
  2. Allows longer replies but does not force them
  3. Makes the model faster
  4. Increases the context window
Show answer

Answer: Allows longer replies but does not force them

It raises the ceiling on reply length; the model still stops when it is done.

Lesson: Setting max_tokens Wisely

12. Where should changing content go for caching to work well?

  1. At the very start of the prompt
  2. After the stable prefix
  3. In the API key
  4. Nowhere
Show answer

Answer: After the stable prefix

Only an identical prefix can be reused, so volatile parts must come after it.

Lesson: Prompt Caching

Controlling Context Growth

13. Why is one huge tool result so costly?

  1. It is resent on every later turn
  2. Large results are encrypted
  3. It slows the keyboard
  4. It is billed once only
Show answer

Answer: It is resent on every later turn

History is resent each turn, so a big result keeps costing tokens until removed.

Lesson: Clipping Tool Results

14. What should never be summarised away?

  1. The original task
  2. Greetings
  3. Old error logs
  4. Whitespace
Show answer

Answer: The original task

Losing the original goal makes the rest of the work aimless.

Lesson: Summarising Old Turns

15. What stays in context when you offload a large document to a file?

  1. The whole document
  2. Only a short reference such as the path and description
  3. Nothing at all
  4. A copy for every turn
Show answer

Answer: Only a short reference such as the path and description

A small handle keeps context lean while the data stays available on demand.

Lesson: Offloading to Files and Memory

Failure Modes

16. Every step is cheap but the run costs a lot overall. Which failure is this?

  1. Repetition
  2. Silent overspend
  3. Drift
  4. Syntax error
Show answer

Answer: Silent overspend

Only a total budget notices cost that accumulates across many individually fine steps.

Lesson: A Catalogue of Loop Failures

17. Which error is usually worth retrying after a wait?

  1. 400 Bad Request
  2. 403 Forbidden
  3. 429 Too Many Requests
  4. 404 Not Found for a wrong ID
Show answer

Answer: 429 Too Many Requests

Rate limits are temporary; the others will fail the same way until the request changes.

Lesson: Retries and Exponential Backoff

18. Why count consecutive tool failures?

  1. To detect a model that is thrashing and not recovering
  2. To make tools slower
  3. Because errors are good
  4. To hide failures
Show answer

Answer: To detect a model that is thrashing and not recovering

A run of failures without a success means more retries are unlikely to help.

Lesson: Tool Errors and Thrashing

Ending Gracefully

19. Why disable tools in the wrap-up call?

  1. So the model writes a summary instead of starting more work
  2. Tools cannot be used twice
  3. It makes the call free
  4. Tools break summaries
Show answer

Answer: So the model writes a summary instead of starting more work

Without tools the only possible output is the final text.

Lesson: Forcing a Final Answer

20. Why make tool actions idempotent when resuming is possible?

  1. Resuming may repeat the last step
  2. Idempotent tools are faster
  3. The API requires it
  4. It avoids all errors
Show answer

Answer: Resuming may repeat the last step

If the last step ran but was not recorded, a second run must not cause duplicate effects.

Lesson: Checkpoints and Resume

21. What makes a handover note most useful?

  1. Only the words "please help"
  2. Goal, what was tried, last error, state and a suggested next step
  3. The complete raw transcript
  4. A random log line
Show answer

Answer: Goal, what was tried, last error, state and a suggested next step

A structured summary lets a person act without reconstructing the history.

Lesson: Escalating to a Human

Observability and Testing

22. Why log the stop reason for every run?

  1. To see how runs end and which limits are being hit
  2. It makes runs faster
  3. Logs are required by law
  4. It saves tokens
Show answer

Answer: To see how runs end and which limits are being hit

Stop reasons reveal patterns such as frequent token-budget stops that point to a context problem.

Lesson: Metrics That Matter

23. Why use a fake model in unit tests of the loop?

  1. It makes tests fast, free and repeatable
  2. Real models cannot be called from tests
  3. Fake models are smarter
  4. It tests the model's quality
Show answer

Answer: It makes tests fast, free and repeatable

Scripted replies make the loop's logic deterministic and cheap to verify.

Lesson: Testing Loops with a Scripted Model

Putting It Together

24. Why clip each fetched page in the research agent?

  1. Pages are never useful
  2. Large page text is resent every turn and inflates cost
  3. The API forbids pages
  4. Clipping speeds up the network
Show answer

Answer: Large page text is resent every turn and inflates cost

Big tool results are resent on every later turn, so bounding them controls total cost.

Lesson: Case Study: Budgeting a Research Agent

25. A run uses 4 steps and few tokens each, yet takes 10 minutes. Which limit would have caught it?

  1. Step limit
  2. Token limit
  3. Wall-clock timeout
  4. Cost limit
Show answer

Answer: Wall-clock timeout

Slow or hanging tools consume time, not steps or tokens.

Lesson: Revision: Cheat Sheet and Self-Check

26. The loop returns half a sentence as the answer. What did it most likely skip checking?

  1. The API key
  2. stop_reason "max_tokens"
  3. The operating system
  4. The tool names
Show answer

Answer: stop_reason "max_tokens"

A reply that hit the output cap is truncated, and the loop must treat that case explicitly.

Lesson: Revision: Cheat Sheet and Self-Check

27. Which combination best prevents silent overspend?

  1. Only a step limit
  2. A total token or cost budget checked every turn
  3. A longer system prompt
  4. Disabling logging
Show answer

Answer: A total token or cost budget checked every turn

Only a cumulative budget notices cost that adds up across many small steps.

Lesson: Revision: Cheat Sheet and Self-Check

← Back to the course