Skip to main content

SpendBudgetPolicyProtocol

Defined in the protocols module.
AI Agent Protocol for gateway cumulative-spend admission decisions. Pure, import-free decision contract symmetric with :class:RateLimitPolicyProtocol. The wrapper supplies typed facts — the caller identity, the scope (channel / tenant token), the amount already spent_usd for that identity+scope in the current window, the current now timestamp, and (optionally) the pending_usd estimated cost of the turn being admitted and the oldest_spend_ts of the spend in the window — and the policy decides whether the turn is allowed or rejected/throttled with a retry_after_seconds hint. Storage of the spend ledger lives in a :class:~praisonaiagents.telemetry.protocols.TokenUsageSinkProtocol; this contract keeps only the decision injectable and provable in isolation. A config-driven default (:class:WindowedSpendBudgetPolicy) is provided for the common “cap $X per identity per rolling window” case.

Methods

check()

Return a :class:RateLimitDecision for the supplied facts.

Source

View on GitHub

praisonaiagents/gateway/protocols.py at line 4336