Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-266

Agent Loop Iteration Cap

Problem

Count agent loop iterations before stopping. Execute steps in order; stop after executing a 'finish' step or when max_iterations iterations have run, whichever comes first.

Return the number of executed steps, and 0 when max_iterations is not positive.

Hint

Increment the counter before testing the stop conditions.

Test cases

case 1
in: [["think","search","finish"],5]
expected: 3
case 2
in: [["think","search","finish"],2]
expected: 2
case 3
in: [[],3]
expected: 0
case 4
in: [["think","think"],0]
expected: 0
case 5
in: [["finish","search"],10]
expected: 1
Starter codePython
def agent_iteration_cap(steps, max_iterations):
    # Your code here
    pass

5 test cases · run your code against them in the editor