Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Your AI Agent's Kill Switch Returns a Boolean. That's the Bug (Python Circuit Breaker)

Описание и применение

Бесконечный цикл в AI‑агенте, вызванный неверной обработкой булевого сигнала, приводил к длительному выполнению и расходу ресурсов. Внедрение CircuitBreaker остановило процесс при превышении лимитов.

Задача

A loop in an AI agent kept retrying a locked account, causing the bot to run for days and consume resources.

Результат

The circuit breaker prevented the agent from running indefinitely, saving resources and avoiding account lockout.

Рабочий процесс

  • Define a check_for_lockout function that returns True when account is locked.
  • Wrap the main loop to call check_for_lockout and continue if True.
  • Observe that the loop keeps running after lockout detection.
  • Implement a CircuitBreaker class with max_per_minute, max_total, max_runtime_s limits and a sentinel file.
  • Modify the loop to use CircuitBreaker.acquire before each action.
  • When limits are exceeded, CircuitBreaker.trips, writes a sentinel file, logs, and exits the process.
  • Verify that the agent stops immediately after lockout is detected and limits are hit.

Доказательства

My bot kept poking a locked platform for another three and a half days.

Источник

The detector worked. On 2026-07-21 the log line appeared, Telegram buzzed, and the selector matched exactly what it was supposed to match.

Источник

A detector that returns True hands the decision to whoever called it.

Источник

The same fix covers the bigger failure class.

Источник

  • Дата записи: 2026-10-10T19:40:56.117Z