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:
Trueif allowed, raisesBudgetExceededErrorotherwise.
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:
Trueif allowed, raisesRecursionLimitErrorotherwise.
CostTracker
Tracks cumulative token usage and estimated costs.
add_usage(tokens: int, model: str)
Updates the usage counters.