Class TokenBudget
java.lang.Object
com.tnsai.coordination.production.TokenBudget
Per-agent token budget management for multi-agent orchestration.
Tracks token usage and enforces budgets to prevent runaway costs.
Example usage:
TokenBudget budget = new TokenBudget(100_000); // Global budget
budget.allocate("agent-a", 30_000);
budget.allocate("agent-b", 70_000);
budget.consume("agent-a", 5_000);
if (budget.canConsume("agent-a", 10_000)) { ... }
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a snapshot of all agent budgets.voidAllocates a token budget for a specific agent.booleancanConsume(String agentId, long tokens) Checks if an agent can consume the specified tokens without exceeding their budget.voidRecords token consumption for an agent.longReturns the global budget limit.longReturns total tokens consumed globally.longReturns global remaining tokens.doubleReturns global usage percentage (0-100).longReturns remaining tokens for an agent.doubleusagePercent(String agentId) Returns usage percentage for an agent (0-100).
-
Constructor Details
-
TokenBudget
public TokenBudget(long globalBudget)
-
-
Method Details
-
allocate
Allocates a token budget for a specific agent. -
consume
Records token consumption for an agent. -
canConsume
Checks if an agent can consume the specified tokens without exceeding their budget. -
remaining
Returns remaining tokens for an agent. -
globalRemaining
public long globalRemaining()Returns global remaining tokens. -
usagePercent
Returns usage percentage for an agent (0-100). -
globalUsagePercent
public double globalUsagePercent()Returns global usage percentage (0-100). -
allAllocations
Returns a snapshot of all agent budgets. -
globalBudget
public long globalBudget()Returns the global budget limit. -
globalConsumed
public long globalConsumed()Returns total tokens consumed globally.
-