EnforceCore EnforceCore

Resource Guard

The Resource Guard prevents resource exhaustion and infinite loops in agent execution.

Classes

ResourceGuard

Monitors resource usage against defined limits.

check_budget(cost: float) -> bool

Checks if the operation cost is within the remaining budget.

  • cost: Estimated cost of the operation.
  • Returns: True if allowed, raises BudgetExceededError otherwise.

check_depth(current_depth: int) -> bool

Checks if the recursion depth is within limits to prevent infinite loops.

  • current_depth: Current call stack depth.
  • Returns: True if allowed, raises RecursionLimitError otherwise.

CostTracker

Tracks cumulative token usage and estimated costs.

add_usage(tokens: int, model: str)

Updates the usage counters.