langchain-agent-budget
A dollar budget a LangChain agent cannot go past. SpendBudgetMiddleware reserves each model
call's worst-case cost before the call and books the real cost after it. A call that does not
fit is never made, and parallel runs or deepagents subagents sharing one budget cannot spend
more than it holds together.
pip install -U langchain-agent-budget
from agent_budget import Budget
from langchain.agents import create_agent
from langchain_anthropic import ChatAnthropic
from langchain_agent_budget import SpendBudgetMiddleware
budget = Budget(2.00, name="support-bot")
agent = create_agent(
ChatAnthropic(model="claude-sonnet-4-6", max_tokens=2048),
tools=[search],
middleware=[SpendBudgetMiddleware(budget)],
)
- Worst case first: input tokens (approximate, or your own counter) plus the call's
max_tokens, priced by llm-prices at the dearest input-side rate. The real cost fromusage_metadatareplaces the hold when the reply comes back. - Shared budgets: one
Budgetacross runs, threads and asyncio tasks; per-user or per-job slices withwith fleet.child("user-42", usd=0.50): agent.invoke(...). - deepagents: give subagents
SpendBudgetMiddleware()and they spend from the orchestrator's budget;subagent_usd=gives each subagent run its own slice.
ModelCallLimitMiddleware counts calls; a check after each call lets the call that crosses the
cap through. In examples/offline_demo.py (no API key needed) a $0.02 cap checked after each
call ends at $0.02268; the same agent with SpendBudgetMiddleware stops at $0.01512.
Docs: docs/index.md. Built on agent-budget (budgets and child scopes) and langchain-llm-prices.
MIT license. Maintained by Matthew Busel.
Metadata
Release files for langchain-agent-budget 0.1.0
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 |
|---|---|---|---|---|
| langchain_agent_budget-0.1.0.tar.gz | 14.9 kB | With provenance | Details for langchain_agent_budget-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_agent_budget-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for langchain_agent_budget-0.1.0-py3-none-any.whl |
Total release size: 24.0 kB
Release files / langchain_agent_budget-0.1.0.tar.gz
| Download URL | langchain_agent_budget-0.1.0.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
af451d3e4e9e9411d11f202794ebfa1130a2f7f34fa2a5d2834ccbda215d1988
|
|
BLAKE2b-256 checksum How to use checksums |
aecdb421d84883eebdba3ecad66af651e8ebc997ab91f24a6a4a5e6f22d456e1
|
| 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 / langchain_agent_budget-0.1.0-py3-none-any.whl
| Download URL | langchain_agent_budget-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cfc6433c651785b5766c60cfa5680a6bd42df8192f6317dcfe09fcadd8e68bb3
|
|
BLAKE2b-256 checksum How to use checksums |
1c6f104e3db9ca209c0380942ad7158d4202d58fd2a515204ae80ae503d64300
|
| 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 langchain-agent-budget 0.1.0
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 langchain_agent_budget-0.1.0.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.