# Revision: Cheat Sheet and Self-Check — Agent Loops, Stop Conditions and Token Budgets

Source: https://www.geekswithgeeks.com/en/agent-loops/wrap-revision

> Review the loop, stop-condition and budgeting essentials from the whole course.

## Cheat sheet

**Turn** = call, inspect, act, append. **Stop reasons**: `end_turn`, `tool_use`, `max_tokens`, `stop_sequence`. **Cost** grows with the square of turns because history is resent. **Limits**: steps, time, tokens, money, plus repeat detection and cancellation. **Done** should be verifiable. **Tokens**: read `usage`, reserve output space, cache the stable prefix. **Context**: clip, summarise, offload. **Failures**: repeat, thrash, drift, bloat, overspend. **Ending**: wrap-up call, checkpoints, structured handover. **Quality**: metrics per run, tests with a scripted model.

## Questions interviewers ask

Be ready to explain: why agent cost grows faster than the number of steps, the difference between a hard limit and a no-progress check, why `max_tokens` handling matters, how prompt caching works, how you would stop a runaway loop safely, and how you would test a loop without calling a real model.

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

- [ ] Step limit
- [ ] Token limit
- [x] Wall-clock timeout
- [ ] Cost limit

*Answer:* Wall-clock timeout. Slow or hanging tools consume time, not steps or tokens.

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

- [ ] The API key
- [x] stop_reason "max_tokens"
- [ ] The operating system
- [ ] The tool names

*Answer:* stop_reason "max_tokens". A reply that hit the output cap is truncated, and the loop must treat that case explicitly.

**Quiz:** Which combination best prevents silent overspend?

- [ ] Only a step limit
- [x] A total token or cost budget checked every turn
- [ ] A longer system prompt
- [ ] Disabling logging

*Answer:* A total token or cost budget checked every turn. Only a cumulative budget notices cost that adds up across many small steps.
