An agent that never looks back at its own last step will happily repeat a failing action forever, burning its step and time budgets on something that was never going to work. A minimal form of self-reflection is much cheaper than a full model-based critique: just watch for observations that look like failures, and give up once too many have happened in a row — a single isolated failure is normal and worth retrying past, but a run of consecutive failures is a strong signal something is fundamentally broken, not just unlucky.
You're given every step's observation text, in order, a list of failure_keywords, and a max_consecutive_failures threshold. Implement find_abandon_point(observations, failure_keywords, max_consecutive_failures). An observation "looks like a failure" if it contains any of failure_keywords as a substring. Track a running count of consecutive failure-looking observations — any success resets the count to zero. Return the 1-indexed step at which that running count first reaches max_consecutive_failures, or None if it never does.
One running counter, reset to zero on any success and incremented on any failure, is the entire piece of state you need — no need to look backward at a window of previous observations each time.
any(keyword in observation for keyword in failure_keywords) checks "does this specific observation look like a failure" in one line — don't build a combined regex or loop-within-a-loop by hand.
No results yet
Run your code to check it against the examples, or submit to run every test.