Repository navigation
feat(cost): add per-run dollar budget sample (BudgetedModel) - #328
Open
karmendra8386 wants to merge 1 commit into
Open
karmendra8386 wants to merge 1 commit into
karmendra8386 wants to merge 1 commit into
Conversation
Implements the proposal in strands-agents#319: a BudgetedModel wrapper that enforces a hard dollar ceiling on a single agent run at the model boundary, pricing provider-reported usage from stream metadata events. Includes a demo with a flaky tool that would otherwise retry indefinitely. Verified locally with a stub model: the wrapper halts a runaway tool loop after the budget is crossed (2 calls / $0.09 against a $0.05 budget) and accounts spend exactly.
|
Latest scan for commit: ✅ Security Scan Report (PR Files Only)Scanned Files
Security Scan Results
Threshold: High No security issues detected in your changes. Great job! This scan only covers files changed in this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the proposal in #319 (thanks @domondi1 for the proposal and the Inferrail design discussion there — this is the complementary client-side approach I mentioned in the thread).
What it does
Adds
python/03-integrate/cost/budgeted-agent/: aBudgetedModelwrapper that enforces a hard dollar ceiling on a single agent run.BudgetExceededErroronce the ceiling is crossed, so a runaway tool loop cannot slip past: it always has to come back through the model.{"metadata": {"usage": ...}}event every Strands provider emits, so accounting is exact rather than estimated.The demo runs an agent told to retry an always-failing tool with a $0.05 budget and prints the halted run's call count and spend.
Verification
Verified locally with a stub model that always requests the failing tool: the wrapper halts the loop after exactly 2 model calls / $0.09 spent against a $0.05 budget, and accounts spend exactly. (The budget error reaches caller code wrapped in
EventLoopExceptionasoriginal_exception, like any model error — documented in the README.)Files
budgeted_model.py—BudgetedModel+BudgetExceededErroragent.py— demoREADME.md— problem, design, run instructions; points to tokenecon's StrandsCostTrackerfor per-task accounting across runsrequirements.txt