NumPy allowed · plain Python earns 10 bonus points
Implement the real circuit-breaker state machine, protecting a production agent from repeatedly hammering a failing downstream dependency (a tool API, a model endpoint).
Implement circuit_breaker_state(current_state, consecutive_failures, failure_threshold, cooldown_elapsed). States are 'closed' (normal), 'open' (blocking calls), 'half_open' (testing recovery). From 'closed': go to 'open' if consecutive_failures >= failure_threshold, else stay 'closed'. From 'open': go to 'half_open' if cooldown_elapsed, else stay 'open'. From 'half_open': go to 'closed' if consecutive_failures == 0, else go back to 'open'.
circuit_breaker_state(current_state: str, consecutive_failures: int, failure_threshold: int, cooldown_elapsed: bool) -> str