agent-budget
Hard USD budgets for agents that delegate.
When an orchestrator hands work to several sub-agents at once, each one checks its spending against the same "remaining" figure, none of them sees the others, and together they spend a multiple of what was left. agent-budget fixes that at the delegation boundary: each sub-agent's slice is reserved from the parent before it starts, every amount it books is booked on the parent at the same moment, and the unused part goes back when it finishes.
pip install llm-agent-budget # no dependencies
pip install "llm-agent-budget[a2a]" # plus the a2a-python plugins
Child scopes
from agent_budget import Budget
orchestrator = Budget(1.00, name="orchestrator")
with orchestrator.child("researcher", usd=0.60) as research:
hold = research.reserve(0.06) # before the model call; refused if it does not fit
# ... call the model ...
hold.settle(0.052) # what it really cost
with research.child("fetcher", fraction=0.5) as fetch: # half of what research has left
fetch.reserve(0.01).settle(0.01)
print(orchestrator.spent_usd) # 0.062: every level, as it happens
print(orchestrator.remaining_usd) # 0.938: the unused slice came back on exit
- A slice that does not fit raises
BudgetExhaustedbefore the sub-agent spends anything. - A closed scope (and everything below it) raises
ScopeClosed; calls already in flight still settle. kill()stops a scope and its whole subtree.max_depth(default 8) raisesDepthExceeded.own_cost_usd+child_cost_usd==spent_usdon every scope.- Thread-safe (one lock per tree) and safe in asyncio tasks;
current_budget()is the innermost scope entered withwithin the current thread or task. One budget can be entered by many threads and tasks at once.
Across agents: A2A, W3C baggage, MCP
BudgetContext is the budget a caller hands down and the cost a callee
reports back, in the shape of the
A2A budget extension draft
(budget{cost, tokens, deadline}, incurred{cost, aggregatedChildCost, tokens, delegations}), plus a reservation{id, amount, currency, expires}
for the slice the caller reserved.
from agent_budget import Budget, outbound, to_a2a_metadata, from_a2a_metadata, to_baggage
with Budget(1.00).child("remote", usd=0.30) as slice_:
ctx = outbound(slice_)
metadata = to_a2a_metadata(ctx) # {"https://a2a-protocol.org/extensions/budget/v1": {...}}
header = to_baggage(ctx) # "llm.budget.cost.amount=0.3,llm.budget.cost.currency=USD,..."
- A2A: the whole context under the extension URI in request, message or task metadata.
- W3C baggage:
llm.budget.*members, so anything that already propagates OpenTelemetry baggage carries the budget. - MCP: MCP reserves
params._meta.baggagefor W3C baggage (SEP-414);inject_mcp_meta/extract_mcp_metaput the same members there.
Money is a decimal string on the wire, exact to the nano-dollar. Fields nobody measured are left out, never written as zero.
a2a-python plugins
from a2a import plugins
from agent_budget.a2a_plugin import BudgetClientPlugin, BudgetExecutionPlugin
# Caller: requests made inside a scope carry its budget; replies are booked on it.
plugins.set_global(plugins.sequential(BudgetClientPlugin()))
with orchestrator.child("remote-researcher", usd=0.30):
async for event in client.send_message(request):
...
# Callee: each execution runs inside a Budget of what the caller allowed,
# and every task update reports the cumulative cost back.
handler = DefaultRequestHandlerV2(..., plugins=plugins.sequential(BudgetExecutionPlugin(max_usd=5.00)))
# inside AgentExecutor.execute: current_budget().reserve(...).settle(...)
Strands Agents
from strands import Agent
from agent_budget.strands import Price, SpendCeiling
agent = Agent(tools=[researcher], plugins=[SpendCeiling(usd=0.50, price=Price(input=3.00, output=15.00))])
A Strands plugin (pip install "llm-agent-budget[strands]"): each invocation can
spend at most usd, every model call reserves its worst case before it is
sent, and an agent used as a tool gets its slice from the caller's budget.
See docs/strands.md.
Same format as the Rust crate
llm-budget 0.8 (Rust) has the same
scopes and the same contexts. Both test suites read one set of golden
fixtures (tests/fixtures/budget_context/), so a Rust orchestrator and a
Python agent agree to the last digit.
More: docs/guide.md. Adding it to another project (dependencies, typing, stability, the five-line integration): docs/integrating.md.
MIT license.
Metadata
Release files for llm-agent-budget 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llm_agent_budget-0.1.3.tar.gz | 53.2 kB | With provenance | Details for llm_agent_budget-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llm_agent_budget-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for llm_agent_budget-0.1.3-py3-none-any.whl |
Total release size: 82.2 kB
Release files / llm_agent_budget-0.1.3.tar.gz
| Download URL | llm_agent_budget-0.1.3.tar.gz |
|---|---|
| Size | 53.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1db517ea198327b3a08243ff78d521fc7fb2827309c5586e2c684c217360e837
|
|
BLAKE2b-256 checksum How to use checksums |
530087d590bf45ef841de32da9a39406b5c15d0095cadd7dac438e8fe63b558a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logRelease files / llm_agent_budget-0.1.3-py3-none-any.whl
| Download URL | llm_agent_budget-0.1.3-py3-none-any.whl |
|---|---|
| Size | 29.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37ab5beba3dc2263198c1b1ad2f1522b8d011da48f37c33f7b4bd28f3591e2ee
|
|
BLAKE2b-256 checksum How to use checksums |
3b025fd756acdd3c5e6e62700424f4a47a228541eed623f05b297eccc29a0e45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logSecurity for llm-agent-budget 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for llm_agent_budget-0.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.