feat: warn the agent at 80% of a run budget before hard stop - #4179
salignatmoandal wants to merge 1 commit into
Conversation
|
👋 Some commits in this PR are not signed and verified by GitHub. Please sign your commits with a GPG or SSH key registered in your GitHub account, then force-push. Commits that are not verified: See GitHub's guide on signing commits for setup instructions. I've added |
Give the model one chance to cheapen or finish before the existing kill-switch fires, without changing the budget_exceeded contract.
8858c9a to
27b5686
Compare
aheritier
left a comment
There was a problem hiding this comment.
Prompt-cache concern: this persists the 80%-budget warning as a system message in session history (pkg/runtime/budget.go:506). That rewrites the cached system/instructions prefix for Anthropic, Bedrock, and ChatGPT/Codex; with num_history_items, trimming can also relocate it ahead of the conversation. The first call after warning may therefore require a full-context cache write at exactly the point this feature is meant to limit cost.
Please route this through the existing transient extraSystemMessages mechanism instead of persisting it, using stable wording to preserve cache reuse. This also avoids stale/accumulating warnings after session resume and loss of the warning after compaction.
Separate blocker: CI lint is currently red (budget_wiring_test.go:245, use assert.Len).
@dgageot @rumpl — requesting your eyes on the prompt-caching implications, as this is a nuanced provider-level behaviour.
Summary
The budget already existed. The agent never saw it until the run was killed.
max_cost/max_tokens/max_time, then keep going.budget_exceededJSON contract and kill-switch at 100% are unchanged.Why this is interesting
enforceBudgetwas a fuse, not a policy. The runtime already counted cost, tokens, and time (record/snapshot/ per-agent spend), but the model only learned the ceiling afteriterationStop. From the user's point of view that looks like a crash: Execution stopped after reaching budget.max_cost.That is the EcoAgent-Bench gap: completing under a budget is not the same as choosing economical actions. A kill-switch with no feedback trains the agent to spend until the wall.
This PR turns the counters into a signal inside the loop — a change in agency policy, not an extra log line.
What that buys docker-agent:
What it does not claim:
Behavior
At the existing turn-boundary check in
RunStream:budget_exceeded+ assistant stop message +iterationStop).[80%, 100%)and that tracker has not warned for that limit yet:Warningevent (TUI / JSON stream)GetMessagescallexceeded()).Warningremains).Test plan
go test ./pkg/runtime -count=1 -run 'TestBudget|TestNilBudget|TestEnforceBudget|TestRecordBudget'go test ./pkg/runtime -count=1 -run 'TestBudgetExceededEventJSONContract|TestEnforceBudgetWarnsOnceThenStillHardStops'task testtask lint