Budget
Budget tracking for elicitation episodes.
Tracks per-episode consumption across five dimensions (turns, runtime, tokens, questions, unique items) and signals when any configured limit is exceeded.
BudgetTracker(budget_turns=None, budget_runtime=None, budget_tokens=None, budget_questions=None, budget_unique_items=None, policy_budget_weight=1.0, user_budget_weight=1.0)
Tracks multiple budget dimensions and signals when any limit is exhausted.
Each budget dimension is optional — pass None (the default) to impose no
limit on that dimension. Budgets are checked in is_exhausted(), which
returns a (bool, reason_str) pair.
Runtime and token costs are weighted before accumulation to allow asymmetric penalization of policy vs. user simulator costs:
weighted_runtime = policy_budget_weight * policy_runtime + user_budget_weight * user_runtimeweighted_tokens = policy_budget_weight * policy_tokens + user_budget_weight * user_tokens
Set a weight to 0.0 to ignore that component entirely (e.g. exclude user
simulator costs from the token budget).
Attributes:
| Name | Type | Description |
|---|---|---|
budget_turns |
Maximum number of conversation turns allowed. |
|
budget_runtime |
Maximum weighted wall-clock seconds allowed. |
|
budget_tokens |
Maximum weighted token count allowed. |
|
budget_questions |
Maximum clarifying questions the user simulator may ask. |
|
budget_unique_items |
Maximum distinct catalog items the agent may surface. |
|
policy_budget_weight |
Multiplier applied to policy-side runtime/token costs. |
|
user_budget_weight |
Multiplier applied to user-simulator runtime/token costs. |
|
current_turns |
Turns consumed so far. |
|
current_runtime |
Weighted seconds consumed so far. |
|
current_tokens |
Weighted tokens consumed so far (policy + user). |
|
current_policy_tokens |
Raw policy token count (unweighted). |
|
current_user_tokens |
Raw user-simulator token count (unweighted). |
|
current_questions |
Clarifying questions asked so far. |
|
current_unique_items |
Distinct catalog items surfaced so far. |
Initialize a BudgetTracker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_turns
|
Optional[int]
|
Maximum conversation turns before exhaustion. |
None
|
budget_runtime
|
Optional[float]
|
Maximum weighted wall-clock seconds before exhaustion.
|
None
|
budget_tokens
|
Optional[int]
|
Maximum weighted tokens before exhaustion. |
None
|
budget_questions
|
Optional[int]
|
Maximum clarifying questions the user simulator may
ask. Checked externally via |
None
|
budget_unique_items
|
Optional[int]
|
Maximum distinct catalog items the agent may
surface. Checked externally via |
None
|
policy_budget_weight
|
float
|
Multiplier for policy-side runtime/token costs.
Defaults to |
1.0
|
user_budget_weight
|
float
|
Multiplier for user-simulator runtime/token costs.
Defaults to |
1.0
|
add_questions(count)
Add to the clarifying-question counter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
Number of questions asked in the current turn. |
required |
add_runtime(policy_runtime, user_runtime)
Accumulate weighted wall-clock runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policy_runtime
|
float
|
Seconds spent in the policy (agent) this turn. |
required |
user_runtime
|
float
|
Seconds spent in the user simulator this turn. |
required |
add_tokens(policy_tokens, user_tokens)
Accumulate weighted token usage.
Internally tracks raw policy and user token counts separately, then
recomputes current_tokens as:
policy_budget_weight * total_policy_tokens + user_budget_weight * total_user_tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policy_tokens
|
int
|
Tokens used by the policy this turn. |
required |
user_tokens
|
int
|
Tokens used by the user simulator this turn. |
required |
add_turn()
Increment the turn counter by one.
add_unique_items(count)
Add to the unique-items-surfaced counter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
Number of new distinct catalog items shown in the current turn. |
required |
get_metrics()
Return a snapshot of current usage and remaining budget for all dimensions.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A dict with keys |
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
(remaining capacity or |
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
and |
Dict[str, Any]
|
reasoning splits, populated via |
get_remaining_questions()
Return the number of clarifying questions still permitted.
Returns:
| Type | Description |
|---|---|
Optional[int]
|
Remaining question budget (≥ 0), or |
get_remaining_unique_items()
Return the number of additional unique items that may still be surfaced.
Returns:
| Type | Description |
|---|---|
Optional[int]
|
Remaining unique-items budget (≥ 0), or |
is_exhausted()
Check whether any hard budget limit has been reached.
Checks turns, runtime, and tokens in that order. Questions and
unique-items budgets are soft limits surfaced via
get_remaining_questions() / get_remaining_unique_items() and
are not checked here.
Returns:
| Type | Description |
|---|---|
bool
|
A |
str
|
any limit is reached and |
Tuple[bool, str]
|
|
Tuple[bool, str]
|
|
set_policy_token_breakdown(breakdown)
Overwrite policy token breakdown with the agent's cumulative counts.
set_user_token_breakdown(breakdown)
Overwrite user token breakdown with the simulator's cumulative counts.