PIXELBANKv9.1.0
Menu

Reflexion Retry Decision

Problem Statement

In a Reflexion loop, the agent retries a task after reflecting on failures, but only while it has retries left and the evaluation score is improving. Decide whether to attempt another try.

Background

Given the current attempt number (1-indexed), a max_attempts cap, the list of scores observed so far (one per attempt, higher is better), and a target threshold: retry only if the latest score is below threshold, attempts remain, and the latest score strictly improved over the previous attempt (or it is the first attempt). No improvement means reflection isn't helping — stop.

Your Task

def should_retry(scores, attempt, max_attempts, threshold):

Return True to retry, else False.

Input Format

  • scores (list of floats, len == attempt), attempt (int), max_attempts (int), threshold (float).

Output Format

  • A boolean.

Sample

print(should_retry([0.4, 0.6], 2, 4, 0.9))

Output:

True

Example:

Input:
print(should_retry([0.4, 0.6], 2, 4, 0.9))
Output:
True
Reasoning:
  • Extract the most recent performance metric from the score history to evaluate current standing: latest=0.6latest = 0.6.
  • Verify if the agent has met the success criteria by comparing the latest score against the target: since 0.6<0.90.6 < 0.9, the performance is insufficient, so the retry process continues.
  • Check if the attempt limit has been reached to ensure resources remain: with attempt=2attempt = 2 and max_attempts=4max\_attempts = 4, the condition 2<42 < 4 holds, indicating retries are still permitted.
  • Determine if the reflection strategy is effective by checking for strict improvement over the previous attempt: comparing the latest score 0.60.6 to the prior score 0.40.4, we see 0.6>0.40.6 > 0.4, confirming positive progress.
  • Since the score is below the threshold, attempts remain, and performance is improving, the decision is made to proceed with another try.
  • The final output is True

Constraints:

  • Retry requires: latest score < threshold, attempt < max_attempts, and improvement over previous (first attempt counts as improving).
  • scores has one entry per attempt so far.
  • Return a bool.
🔒

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

0/0
Run code to see test results.