Thread-Safe Iteration Budget (agent/iteration_budget.py)

affaan-m/hermes-agent · agent/iteration_budget.py · python · MIT
automation, ai, lang:python, tag:concurrency, tag:counter, tag:threading

Thread-safe consume and refund counter for managing agent execution limits. Reuse when tracking iteration budgets across parent and subagent tasks.

# Source: https://github.com/affaan-m/hermes-agent | License: MIT | Copyright 2025 Nous Research
# Provided via justclaw.it.com; keep this notice with the code.
"""Per-agent iteration budget — thread-safe consume/refund counter.

Extracted from ``run_agent.py``.  Each ``AIAgent`` instance (parent or
subagent) holds an :class:`IterationBudget`; the parent's cap comes from
``max_iterations`` (default 500), each subagent's cap comes from
``delegation.max_iterations`` (default 50).

``run_agent`` re-exports ``IterationBudget`` so existing
``from run_agent import IterationBudget`` imports keep working unchanged.
"""

from __future__ import annotations

import threading


class IterationBudget:
    """Thread-safe iteration counter for an agent.

    Each agent (parent or subagent) gets its own `

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key