Cost¶
Cost calculation and budget enforcement.
Calculator¶
agentprobe.cost.calculator
¶
Cost calculator for agent execution traces.
Loads pricing data from YAML files and computes per-call and per-trace costs based on token usage.
PricingEntry
¶
Bases: BaseModel
Pricing for a single model.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
str
|
Model identifier. |
input_cost_per_1k |
float
|
Cost per 1,000 input tokens in USD. |
output_cost_per_1k |
float
|
Cost per 1,000 output tokens in USD. |
Source code in src/agentprobe/cost/calculator.py
PricingConfig
¶
Bases: BaseModel
Collection of pricing entries.
Attributes:
| Name | Type | Description |
|---|---|---|
entries |
dict[str, PricingEntry]
|
Mapping of model name to pricing entry. |
Source code in src/agentprobe/cost/calculator.py
load_from_dir(pricing_dir=None)
classmethod
¶
Load pricing data from all YAML files in a directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pricing_dir
|
str | Path | None
|
Directory containing pricing YAML files. Defaults to the bundled pricing_data directory. |
None
|
Returns:
| Type | Description |
|---|---|
PricingConfig
|
A PricingConfig with all entries loaded. |
Source code in src/agentprobe/cost/calculator.py
CostCalculator
¶
Calculates costs for agent execution traces.
Uses pricing data to compute per-call costs, aggregates by model, and optionally enforces budget limits.
Attributes:
| Name | Type | Description |
|---|---|---|
pricing |
The pricing configuration. |
|
budget_limit_usd |
Optional maximum cost per trace. |
Source code in src/agentprobe/cost/calculator.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
__init__(pricing=None, budget_limit_usd=None)
¶
Initialize the cost calculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pricing
|
PricingConfig | None
|
Pricing configuration. Loads defaults if None. |
None
|
budget_limit_usd
|
float | None
|
Optional budget limit in USD. |
None
|
Source code in src/agentprobe/cost/calculator.py
calculate_llm_cost(call)
¶
Calculate the cost of a single LLM call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
call
|
LLMCall
|
The LLM call to price. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Cost in USD. |
Source code in src/agentprobe/cost/calculator.py
calculate_trace_cost(trace)
¶
Calculate the total cost for a trace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace
|
Trace
|
The execution trace to price. |
required |
Returns:
| Type | Description |
|---|---|
CostSummary
|
A CostSummary with per-model breakdown. |
Raises:
| Type | Description |
|---|---|
BudgetExceededError
|
If budget_limit_usd is set and exceeded. |
Source code in src/agentprobe/cost/calculator.py
Budget Enforcer¶
agentprobe.cost.budget
¶
Budget enforcement for test execution cost management.
Provides the BudgetEnforcer class for checking individual test and suite-level costs against configured budget limits.
BudgetEnforcer
¶
Enforces cost budgets for tests and suites.
Checks actual costs against configured limits and returns verdict objects indicating whether budgets were exceeded.
Attributes:
| Name | Type | Description |
|---|---|---|
test_budget_usd |
Maximum cost per individual test. |
|
suite_budget_usd |
Maximum cost per test suite run. |
Source code in src/agentprobe/cost/budget.py
__init__(*, test_budget_usd=None, suite_budget_usd=None)
¶
Initialize the budget enforcer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_budget_usd
|
float | None
|
Maximum cost per test in USD. |
None
|
suite_budget_usd
|
float | None
|
Maximum cost per suite in USD. |
None
|
Source code in src/agentprobe/cost/budget.py
check_test(cost_summary)
¶
Check a single test's cost against the test budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cost_summary
|
CostSummary
|
Cost summary for the test. |
required |
Returns:
| Type | Description |
|---|---|
BudgetCheckResult | None
|
A BudgetCheckResult if a test budget is configured, else None. |
Source code in src/agentprobe/cost/budget.py
check_suite(cost_summaries)
¶
Check a suite's total cost against the suite budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cost_summaries
|
list[CostSummary]
|
Cost summaries for all tests in the suite. |
required |
Returns:
| Type | Description |
|---|---|
BudgetCheckResult | None
|
A BudgetCheckResult if a suite budget is configured, else None. |