Package com.tnsai.quality.cost
Record Class CostBudget
java.lang.Object
java.lang.Record
com.tnsai.quality.cost.CostBudget
- Record Components:
tenantId- tenant the budget applies to; never nullagentId- optional agent-id narrowing; empty = all agents in the tenantcapabilityId- optional capability-id narrowing; empty = all capabilitiesperiodBudgetUSD- cap on cumulative spend overperiodperiod- rolling window — typically hour / day / monthonExceed- 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 Summary
ConstructorsConstructorDescriptionCostBudget(String tenantId, Optional<String> agentId, Optional<String> capabilityId, BigDecimal periodBudgetUSD, Duration period, BudgetPolicy onExceed) Creates an instance of aCostBudgetrecord class. -
Method Summary
Modifier and TypeMethodDescriptionagentId()Returns the value of theagentIdrecord component.Returns the value of thecapabilityIdrecord component.final booleanIndicates whether some other object is "equal to" this one.static CostBudgetforAgent(String tenantId, String agentId, BigDecimal periodBudgetUSD, Duration period, BudgetPolicy onExceed) Convenience: tenant + agent narrowing.final inthashCode()Returns a hash code value for this object.onExceed()Returns the value of theonExceedrecord component.period()Returns the value of theperiodrecord component.Returns the value of theperiodBudgetUSDrecord component.tenantId()Returns the value of thetenantIdrecord component.static CostBudgettenantWide(String tenantId, BigDecimal periodBudgetUSD, Duration period, BudgetPolicy onExceed) Convenience: tenant-wide budget, no agent / capability narrowing.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
CostBudget
public CostBudget(String tenantId, Optional<String> agentId, Optional<String> capabilityId, BigDecimal periodBudgetUSD, Duration period, BudgetPolicy onExceed) Creates an instance of aCostBudgetrecord class.- Parameters:
tenantId- the value for thetenantIdrecord componentagentId- the value for theagentIdrecord componentcapabilityId- the value for thecapabilityIdrecord componentperiodBudgetUSD- the value for theperiodBudgetUSDrecord componentperiod- the value for theperiodrecord componentonExceed- the value for theonExceedrecord component
-
-
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
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
tenantId
Returns the value of thetenantIdrecord component.- Returns:
- the value of the
tenantIdrecord component
-
agentId
Returns the value of theagentIdrecord component.- Returns:
- the value of the
agentIdrecord component
-
capabilityId
Returns the value of thecapabilityIdrecord component.- Returns:
- the value of the
capabilityIdrecord component
-
periodBudgetUSD
Returns the value of theperiodBudgetUSDrecord component.- Returns:
- the value of the
periodBudgetUSDrecord component
-
period
Returns the value of theperiodrecord component.- Returns:
- the value of the
periodrecord component
-
onExceed
Returns the value of theonExceedrecord component.- Returns:
- the value of the
onExceedrecord component
-