Record Class CostBudget

java.lang.Object
java.lang.Record
com.tnsai.quality.cost.CostBudget
Record Components:
tenantId - tenant the budget applies to; never null
agentId - optional agent-id narrowing; empty = all agents in the tenant
capabilityId - optional capability-id narrowing; empty = all capabilities
periodBudgetUSD - cap on cumulative spend over period
period - rolling window — typically hour / day / month
onExceed - what the enforcement layer should do when spend hits the cap

public record CostBudget(String tenantId, Optional<String> agentId, Optional<String> capabilityId, BigDecimal periodBudgetUSD, Duration period, BudgetPolicy onExceed) extends Record
Declarative budget — "this scope can spend at most X USD per period; here's what to do when exhausted" (issue #82).

Scope is hierarchical: tenant alone, tenant+agent, or tenant+agent+capability. The enforcement layer (Hook<PreAction> follow-up) finds the most-specific budget for an in-flight LLM call via CostBudgetStore.

Since:
0.5.0 (issue #82)
  • Constructor Details

  • Method Details

    • tenantWide

      public static CostBudget tenantWide(String tenantId, BigDecimal periodBudgetUSD, Duration period, BudgetPolicy onExceed)
      Convenience: tenant-wide budget, no agent / capability narrowing.
    • forAgent

      public static CostBudget forAgent(String tenantId, String agentId, BigDecimal periodBudgetUSD, Duration period, BudgetPolicy onExceed)
      Convenience: tenant + agent narrowing.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • tenantId

      public String tenantId()
      Returns the value of the tenantId record component.
      Returns:
      the value of the tenantId record component
    • agentId

      public Optional<String> agentId()
      Returns the value of the agentId record component.
      Returns:
      the value of the agentId record component
    • capabilityId

      public Optional<String> capabilityId()
      Returns the value of the capabilityId record component.
      Returns:
      the value of the capabilityId record component
    • periodBudgetUSD

      public BigDecimal periodBudgetUSD()
      Returns the value of the periodBudgetUSD record component.
      Returns:
      the value of the periodBudgetUSD record component
    • period

      public Duration period()
      Returns the value of the period record component.
      Returns:
      the value of the period record component
    • onExceed

      public BudgetPolicy onExceed()
      Returns the value of the onExceed record component.
      Returns:
      the value of the onExceed record component