v9.1.1
Menu

Should the Agent Loop Continue

easyPROAgent Loop Control & PlanningAI AgentsAI Agents 1

Problem Statement

Decide whether a ReAct-style agent loop should take another step, given step and budget guards.

Background

The loop continues only if all hold: the goal is not yet done, the step count is below max_steps, and tokens used are below max_tokens. Any single violation stops the loop.

Your Task

def should_continue(done, steps, tokens, max_steps, max_tokens):

Return True if the loop should continue, else False.

Input Format

  • done (bool), steps (int), tokens (int), max_steps (int), max_tokens (int).

Output Format

  • A boolean.

Sample

print(should_continue(False, 3, 100, 10, 1000))

Output:

True

Example

Input
print(should_continue(False, 3, 100, 10, 1000))
Output
True
Reasoning
  • Inputs: done says whether the agent has already reached its goal; steps is how many think-act steps it has taken so far and max_steps is the step budget; tokens is how many tokens it has spent so far and max_tokens is the token budget.
  • Goal guard: done is False, so the task is unfinished and there is still a reason to keep going.
  • Step guard: 3<103 < 10 holds, so the agent has used 3 of its 10 steps and has 7 left.
  • Token guard: 100<1000100 < 1000 holds, so only 10% of the token budget is spent.
  • Output: all three guards pass at once, so the answer is True and the agent takes another step. If any one guard fails, the answer is False.
  • Notice: the budget comparisons are strict. With 33 replaced by 1010, the agent has used exactly its step budget, 10<1010 < 10 is false, and the loop stops even though the goal is unfinished and plenty of tokens remain.

Constraints

  • Continue only if not done and steps < max_steps and tokens < max_tokens.
  • Any failed condition returns False.

Learn this in

More from AI Agents 1

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.