Repository navigation
feat: make budget notices state what is left and what to do - #11485
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Credit notices misrepresent small budgets and fractional usage, and the new warning trigger can break the routed-steering smoke test even when the agent follows the notice.
3 open issues
What changed in this PR
This PR makes AWF’s API-proxy budget notices actionable while preserving the existing per-conversation delivery path.
Changes:
- Replaces percentage-only warnings with credit/request and time estimates plus one shared, role-aware directive.
- Adds “little left” triggers and rank-based notice ordering.
- Updates delivery records, reflection state, schema, documentation, and tests.
| File | Description |
|---|---|
schemas/token-usage.schema.json |
Validates notice triggers and nullable little-left thresholds. |
docs/awf-config-spec.md |
Documents notice formats, estimates, triggers, and ranking. |
docs/api-proxy-sidecar.md |
Explains steering behavior and delivery records. |
containers/api-proxy/token-tracker.schema.test.js |
Covers threshold and little-left record formats. |
containers/api-proxy/token-persistence.js |
Records triggers while preserving legacy threshold-only records. |
containers/api-proxy/token-budget-log.js |
Passes request purpose into credit accounting. |
containers/api-proxy/server.token-steering.test.js |
Updates end-to-end notice delivery and recording checks. |
containers/api-proxy/server.network.test.js |
Adds the little-left reflection flag expectation. |
containers/api-proxy/guards/timeout-steering.test.js |
Tests time-notice wording, triggers, and ranking. |
containers/api-proxy/guards/timeout-steering.js |
Builds factual time notices and adds the five-minute trigger. |
containers/api-proxy/guards/steering-thresholds.test.js |
Tests notice ranks and supersession. |
containers/api-proxy/guards/steering-thresholds.js |
Defines the shared directive and rank helpers. |
containers/api-proxy/guards/ai-credits-guard.test.js |
Tests credit estimates, triggers, and classifier exclusion. |
containers/api-proxy/guards/ai-credits-guard.js |
Tracks recent costs and builds factual credit notices. |
containers/api-proxy/body-handler.test.js |
Updates injection and delivery expectations. |
containers/api-proxy/body-handler.js |
Selects and claims notices by rank and includes trigger metadata. |
Review effort: Max
…11479) * fix: put budget notices at the end of the conversation on Messages, Chat Completions and Gemini (#11449) * Initial plan * fix(api-proxy): add budget notices at the end of the conversation on every API Co-authored-by: rabeckett <[email protected]> * docs(api-proxy): note extended-thinking cache limitation for Messages notices Co-authored-by: rabeckett <[email protected]> * docs(api-proxy): scope pending-warning skip rule to Messages, Chat Completions and Gemini Co-authored-by: rabeckett <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: rabeckett <[email protected]> * feat: send each budget notice once to every conversation in the run Co-authored-by: rabeckett <[email protected]> * fix: steer Claude on Vertex, default Responses roles, skip token counting Co-authored-by: rabeckett <[email protected]> * fix: steer Claude on Bedrock and give stored-response requests their own notice entry Co-authored-by: rabeckett <[email protected]> * perf: skip steering conversation inspection until a budget threshold is crossed Co-authored-by: rabeckett <[email protected]> * fix: never steer Responses compaction requests Co-authored-by: rabeckett <[email protected]> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix: key steering conversations with a per-process HMAC secret Co-authored-by: rabeckett <[email protected]> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * test: assert steering conversation key properties instead of exact derivation Co-authored-by: rabeckett <[email protected]> * fix: persist and log the opaque steering conversation prefix directly Co-authored-by: rabeckett <[email protected]> * docs: describe both cases where steering_delivery.conversation is null Co-authored-by: rabeckett <[email protected]> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: rabeckett <[email protected]> Co-authored-by: Landon Cox <[email protected]> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: rabeckett <[email protected]>
…edit notices conservatively Co-authored-by: rabeckett <[email protected]>
2ff4e44 to
03e7d49
Compare
|
✅ Copilot review passed with no inline comments. @copilot Add the |
Documentation PreviewDocumentation has been built for this PR. To view locally:
Built from commit b792f77 |
|
@copilot address review feedback |
All three review concerns are addressed in |

Credit and time notices gave only a percentage and an instruction that varied by threshold. That didn't tell an agent how much it could still do, and "submit now" is wrong for sub-agents now that #11479 delivers each notice to every conversation. Now every notice states the facts first, then one fixed line that each agent applies according to its own role. A new "little left" notice also fires when about five requests or five minutes remain.
This builds on #11479's per-conversation delivery (conversation keys, claim/acknowledge on a 2xx response,
steering_deliveryrecords). There is no second delivery path and no configuration change undersrc/.Notice text
STEERING_DIRECTIVE(guards/steering-thresholds.js). The per-threshold message tables are removed."Little left" trigger
Records and schema
steering_deliverygains a requiredtriggerfield:"threshold"or"little_left". Forlittle_left,thresholdisnull; the schema enforces this withif/then/else.steering {type, threshold}field is written only for threshold notices, so gh-aw's smoke test still sees only 80, 90, 95 and 99.little_left_triggered.thresholds_crossedandthresholds_pendinglist only integer thresholds.Docs
docs/api-proxy-sidecar.mdand §10.1 ofdocs/awf-config-spec.mdcover the message formats, the estimate rules, the trigger, the ranking and the record fields.Notes for review