Concept guide · Agents, tools, and MCP
How do you prevent an agent from looping or overspending?
A slower explanation for when the short interview answer is not enough. Start with the intuition, then connect it to the technical idea and the way an interviewer expects you to reason about it.
ML area
Generative AI → Agent budgets and stopping
Interview format
Core · Concept
Question
GENAI-078
Start with the idea
In simple terms
An agent needs a budget and a clear finish line. Limit how many steps, tool calls, tokens, retries, time, and money it can spend, and detect when it is repeating itself.
Make it concrete
A research agent may get eight searches and three minutes. If it cannot find supporting evidence within that budget, it should return an incomplete result or ask for human help.
Build the answer
How to reason about it
- 1Set hard limits before running the first model call.
- 2Track progress and repeated actions in durable state.
- 3Define a useful fallback when the budget is exhausted.
Go one level deeper
The technical explanation
Stopping is an application responsibility. Store a step counter, elapsed time, estimated cost, tool history, and completion state. Use idempotency keys for external actions, detect repeated queries or unchanged state, and hand off when the agent is stuck. A prompt saying “be efficient” is not a budget enforcement mechanism.
Say this in the interview
Set limits on steps, time, retries, tokens, tool calls, and money; detect repeated actions; define completion conditions; persist progress; and hand over when the agent is stuck. Enforce budgets in application code rather than asking the model to police itself.
Keep preparing