Repository navigation
Commit fc36aef
authored
feat(api): set and read agent session spending limits (#4315)
## Summary
Support for `spend_control` in synchronous and asynchronous beta agent
sessions, including streaming creation.
## Changes
- Set a best-effort limit in USD cents. On update, omit `spend_control`
to keep the limit or clear it with a null limit.
- Read `limit` and `consumed` on every session. Both keys are required
in response fixtures. A null limit means unlimited spending. Null
consumption means the amount is unavailable.
- The `budget_reached` status, `session_budget_exceeded` turn error and
typed `AgentSessionBudgetReachedEvent`.
## Validation
Local checks have been passing: 581 focused agent tests with Pydantic
v2, 493 with Pydantic v1, whole-tree Ruff, and whole-tree type checking.
Coverage has been exercising exact nullable spending values, omitted and
null updates, and typed budget events through synchronous and
asynchronous clients.
Co-authored-by: markstuart-oai <323302876+markstuart-oai@users.noreply.github.com>1 parent f63f14b commit fc36aef
15 files changed
Lines changed: 357 additions & 18 deletions
File tree
- api_reference
- scripts/castiron
- src/openai
- resources/beta/agents/sessions
- types/beta
- agents
- tests
- api_resources/beta/agents
- lib/streaming/agents
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
550 | 550 | | |
551 | 551 | | |
552 | 552 | | |
| 553 | + | |
553 | 554 | | |
554 | 555 | | |
555 | 556 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91517 | 91517 | | |
91518 | 91518 | | |
91519 | 91519 | | |
| 91520 | + | |
91520 | 91521 | | |
91521 | 91522 | | |
91522 | 91523 | | |
| |||
91541 | 91542 | | |
91542 | 91543 | | |
91543 | 91544 | | |
| 91545 | + | |
91544 | 91546 | | |
91545 | 91547 | | |
91546 | 91548 | | |
| |||
93047 | 93049 | | |
93048 | 93050 | | |
93049 | 93051 | | |
| 93052 | + | |
93050 | 93053 | | |
93051 | 93054 | | |
93052 | 93055 | | |
93053 | 93056 | | |
93054 | 93057 | | |
| 93058 | + | |
93055 | 93059 | | |
93056 | 93060 | | |
93057 | 93061 | | |
| |||
93502 | 93506 | | |
93503 | 93507 | | |
93504 | 93508 | | |
| 93509 | + | |
| 93510 | + | |
| 93511 | + | |
| 93512 | + | |
| 93513 | + | |
| 93514 | + | |
| 93515 | + | |
| 93516 | + | |
| 93517 | + | |
| 93518 | + | |
| 93519 | + | |
| 93520 | + | |
| 93521 | + | |
| 93522 | + | |
| 93523 | + | |
| 93524 | + | |
| 93525 | + | |
| 93526 | + | |
| 93527 | + | |
| 93528 | + | |
| 93529 | + | |
| 93530 | + | |
| 93531 | + | |
| 93532 | + | |
| 93533 | + | |
| 93534 | + | |
| 93535 | + | |
| 93536 | + | |
| 93537 | + | |
| 93538 | + | |
| 93539 | + | |
| 93540 | + | |
| 93541 | + | |
| 93542 | + | |
| 93543 | + | |
| 93544 | + | |
| 93545 | + | |
| 93546 | + | |
| 93547 | + | |
| 93548 | + | |
| 93549 | + | |
| 93550 | + | |
| 93551 | + | |
| 93552 | + | |
| 93553 | + | |
| 93554 | + | |
| 93555 | + | |
| 93556 | + | |
| 93557 | + | |
| 93558 | + | |
| 93559 | + | |
| 93560 | + | |
| 93561 | + | |
| 93562 | + | |
| 93563 | + | |
| 93564 | + | |
| 93565 | + | |
| 93566 | + | |
| 93567 | + | |
| 93568 | + | |
| 93569 | + | |
| 93570 | + | |
| 93571 | + | |
| 93572 | + | |
93505 | 93573 | | |
93506 | 93574 | | |
93507 | 93575 | | |
| |||
93513 | 93581 | | |
93514 | 93582 | | |
93515 | 93583 | | |
| 93584 | + | |
| 93585 | + | |
| 93586 | + | |
93516 | 93587 | | |
93517 | 93588 | | |
93518 | 93589 | | |
| |||
93578 | 93649 | | |
93579 | 93650 | | |
93580 | 93651 | | |
| 93652 | + | |
93581 | 93653 | | |
93582 | 93654 | | |
93583 | 93655 | | |
| |||
93684 | 93756 | | |
93685 | 93757 | | |
93686 | 93758 | | |
| 93759 | + | |
| 93760 | + | |
| 93761 | + | |
| 93762 | + | |
| 93763 | + | |
93687 | 93764 | | |
93688 | 93765 | | |
93689 | 93766 | | |
| |||
95360 | 95437 | | |
95361 | 95438 | | |
95362 | 95439 | | |
| 95440 | + | |
95363 | 95441 | | |
95364 | 95442 | | |
95365 | 95443 | | |
| |||
95391 | 95469 | | |
95392 | 95470 | | |
95393 | 95471 | | |
| 95472 | + | |
95394 | 95473 | | |
95395 | 95474 | | |
95396 | 95475 | | |
| |||
95425 | 95504 | | |
95426 | 95505 | | |
95427 | 95506 | | |
| 95507 | + | |
95428 | 95508 | | |
95429 | 95509 | | |
95430 | 95510 | | |
| |||
95494 | 95574 | | |
95495 | 95575 | | |
95496 | 95576 | | |
| 95577 | + | |
| 95578 | + | |
| 95579 | + | |
| 95580 | + | |
| 95581 | + | |
95497 | 95582 | | |
95498 | 95583 | | |
95499 | 95584 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
306 | | - | |
| 306 | + | |
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| |||
1659 | 1659 | | |
1660 | 1660 | | |
1661 | 1661 | | |
1662 | | - | |
| 1662 | + | |
1663 | 1663 | | |
1664 | 1664 | | |
1665 | 1665 | | |
| |||
1775 | 1775 | | |
1776 | 1776 | | |
1777 | 1777 | | |
1778 | | - | |
| 1778 | + | |
1779 | 1779 | | |
1780 | 1780 | | |
1781 | 1781 | | |
1782 | 1782 | | |
1783 | 1783 | | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
1784 | 1788 | | |
1785 | 1789 | | |
1786 | 1790 | | |
| |||
1831 | 1835 | | |
1832 | 1836 | | |
1833 | 1837 | | |
1834 | | - | |
| 1838 | + | |
1835 | 1839 | | |
1836 | 1840 | | |
1837 | 1841 | | |
| |||
2091 | 2095 | | |
2092 | 2096 | | |
2093 | 2097 | | |
2094 | | - | |
| 2098 | + | |
2095 | 2099 | | |
2096 | 2100 | | |
2097 | 2101 | | |
2098 | 2102 | | |
2099 | 2103 | | |
2100 | 2104 | | |
2101 | 2105 | | |
2102 | | - | |
| 2106 | + | |
2103 | 2107 | | |
2104 | 2108 | | |
2105 | 2109 | | |
| |||
3531 | 3535 | | |
3532 | 3536 | | |
3533 | 3537 | | |
3534 | | - | |
| 3538 | + | |
3535 | 3539 | | |
3536 | 3540 | | |
3537 | 3541 | | |
| |||
7811 | 7815 | | |
7812 | 7816 | | |
7813 | 7817 | | |
7814 | | - | |
| 7818 | + | |
7815 | 7819 | | |
7816 | 7820 | | |
7817 | 7821 | | |
| |||
0 commit comments