Should the Agent Loop Continue
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
print(should_continue(False, 3, 100, 10, 1000))
True
- Inputs:
donesays whether the agent has already reached its goal;stepsis how many think-act steps it has taken so far andmax_stepsis the step budget;tokensis how many tokens it has spent so far andmax_tokensis the token budget. - Goal guard:
doneisFalse, so the task is unfinished and there is still a reason to keep going. - Step guard: holds, so the agent has used 3 of its 10 steps and has 7 left.
- Token guard: holds, so only 10% of the token budget is spent.
- Output: all three guards pass at once, so the answer is
Trueand the agent takes another step. If any one guard fails, the answer isFalse. - Notice: the budget comparisons are strict. With replaced by , the agent has used exactly its step budget, 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.