Skip to main content

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 from usage_metadata replaces the hold when the reply comes back.
  • Shared budgets: one Budget across runs, threads and asyncio tasks; per-user or per-job slices with with 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.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-agent-budget 0.2.0
File Size Uploaded Provenance Actions
langchain_agent_budget-0.2.0.tar.gz 15.8 kB With provenance Details for langchain_agent_budget-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-agent-budget 0.2.0
File Interpreter ABI Platform Actions
langchain_agent_budget-0.2.0-py3-none-any.whl Python 3 none any Details for langchain_agent_budget-0.2.0-py3-none-any.whl

Total release size: 25.3 kB

Release files / langchain_agent_budget-0.2.0.tar.gz

Download URL langchain_agent_budget-0.2.0.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7a037db6b2b7e59fe68d0ca32fb0dba93482b5f017dcd4a02eaa7a2f4548b5da
BLAKE2b-256 checksum
How to use checksums
8ad69236ef16ca4dd456a84d3461de52cc6c6093fec558637e1327f73f752998
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 19, 2026.

Transparency log

Release files / langchain_agent_budget-0.2.0-py3-none-any.whl

Download URL langchain_agent_budget-0.2.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b99d9157c30bfab3db0b8de5a3315132270ad2b6a6c34b7c088ab41e5d10c47
BLAKE2b-256 checksum
How to use checksums
3452760a380ba1636a5b31c47e0fc27ea5a05e8533a191c7464738a2038f1cfb
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 19, 2026.

Transparency log

Security for langchain-agent-budget 0.2.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.

Select from 2 files

Attestation for langchain_agent_budget-0.2.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 19, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page