Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .castiron.stats.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
schema_version: 1
generation_id: e0db1179-fe12-4bb2-bd87-8631bb67d669
openapi_spec_hash: c09a996bda1329932cb3cdbc62ac2bc4
openapi_transformed_spec_hash: 877730e5c258cc3abc2cc03f2b864cbe
config_hash: 75d0b851f817c2f6384c562a88468286
codegen_sha: 4f825036970380029f250cf929e9cc688cf3f0ad
codegen_hash: 397c8644ff0580d3d2b9b974979b1679fa1fa52b0063bd2dfe2c2fe6254a88a7
generation_id: dee76378-e67c-4e39-b545-9f257df8b231
openapi_spec_hash: d28f1e5c39423153f8057ba11f157c2a
openapi_transformed_spec_hash: cab15e06e8c85cd4cb16654debd28726
config_hash: 00b2193b69f1fff70da44589b70736d0
codegen_sha: 09fa53f79de260a84b688f5f9740015a539c3c28
codegen_hash: 9d14309c72f055635e0c8ec84418f8da52a0b5205cb31d274c247d5416cc11bc
1 change: 0 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ from openai.types.beta import (
AgentSendSubagentInputCallItem,
AgentSession,
AgentSessionAssistantMessage,
AgentSessionBudgetReachedEvent,
AgentSessionCreatedEvent,
AgentSessionDeleted,
AgentSessionEnvironmentConnectedEvent,
Expand Down
84 changes: 0 additions & 84 deletions api_reference/openapi.transformed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91510,7 +91510,6 @@ components:
enum:
- context_length_exceeded
- max_output_tokens
- session_budget_exceeded
- usage_limit_exceeded
- project_spend_limit_exceeded
- organization_spend_limit_exceeded
Expand All @@ -91535,7 +91534,6 @@ components:
x-enumDescriptions:
- The request exceeds the model's context window.
- The model reached its output token limit before finishing the response.
- The session has reached its usage budget.
- The organization has reached a usage, plan, or billing limit.
- The project has reached its enforced spend limit.
- The organization has reached its enforced spend limit.
Expand Down Expand Up @@ -93042,13 +93040,11 @@ components:
- in_progress
- requires_action
- failed
- budget_reached
x-enumDescriptions:
- The session has no turn in progress and is ready for input. A hosted environment may still be provisioning.
- The session is processing a turn.
- The session is waiting for one or more required actions.
- The session failed.
- The session is paused because its spending limit was reached.
description: The current status of a session.
McpApprovalRequestResourceMcpToolCall:
type: object
Expand Down Expand Up @@ -93574,9 +93570,6 @@ components:
- $ref: '#/components/schemas/TokenUsageResource'
- type: 'null'
description: Best-effort token usage for the session, or null if unknown. Recorded usage may change.
spend_control:
$ref: '#/components/schemas/SessionBudgetControlResource'
description: Spending limit and best-effort consumption, in USD cents. Present when spending-control visibility is enabled; limit is null without a cap. Older server responses may omit this object.
required:
- metadata
- id
Expand Down Expand Up @@ -93735,11 +93728,6 @@ components:
stream_options:
$ref: '#/components/schemas/SessionStreamOptionsParam'
description: Options for the event stream. Only allowed when `stream` is `true`.
spend_control:
anyOf:
- $ref: '#/components/schemas/SessionBudgetControlParams'
- type: 'null'
description: Optional spending limit in USD cents. Omission or null creates an unlimited session.
required:
- environment
additionalProperties: false
Expand Down Expand Up @@ -95381,7 +95369,6 @@ components:
agent.session.turn.output_text.delta: '#/components/schemas/SessionEventAgentSessionTurnOutputTextDelta'
agent.session.turn.output_text.done: '#/components/schemas/SessionEventAgentSessionTurnOutputTextDone'
agent.session.turn.reasoning_summary_part.added: '#/components/schemas/SessionEventAgentSessionTurnReasoningSummaryPartAdded'
agent.session.budget_reached: '#/components/schemas/SessionEventAgentSessionBudgetReached'
x-oai-discriminator-values:
- error
- agent.session.environment.ready
Expand All @@ -95397,7 +95384,6 @@ components:
- agent.session.turn.cancelled
- agent.session.turn.item.added
- agent.session.idle
- agent.session.budget_reached
- agent.session.in_progress
- agent.session.requires_action
- agent.session.failed
Expand Down Expand Up @@ -95432,7 +95418,6 @@ components:
- $ref: '#/components/schemas/SessionEventAgentSessionTurnCancelled'
- $ref: '#/components/schemas/SessionEventAgentSessionTurnItemAdded'
- $ref: '#/components/schemas/SessionEventAgentSessionIdle'
- $ref: '#/components/schemas/SessionEventAgentSessionBudgetReached'
- $ref: '#/components/schemas/SessionEventAgentSessionInProgress'
- $ref: '#/components/schemas/SessionEventAgentSessionRequiresAction'
- $ref: '#/components/schemas/SessionEventAgentSessionFailed'
Expand Down Expand Up @@ -95520,11 +95505,6 @@ components:
minProperties: 0
maxProperties: 16
description: Replaces all metadata. Omit to leave unchanged, or pass null or {} to clear it. Up to 16 string key-value pairs, with keys up to 64 and values up to 512 characters.
spend_control:
anyOf:
- $ref: '#/components/schemas/SessionBudgetControlParams'
- type: 'null'
description: Omit to retain the limit; null or a null limit removes it without resetting spend.
additionalProperties: false
description: Fields to update on an existing session.
DeletedSessionResource:
Expand Down Expand Up @@ -113372,70 +113352,6 @@ components:
- soonest
- 2h
- 8h
SessionEventAgentSessionBudgetReached:
type: object
properties:
type:
type: string
enum:
- agent.session.budget_reached
default: agent.session.budget_reached
x-stainless-const: true
description: The type of the object. Always `agent.session.budget_reached`.
event_id:
type: string
minLength: 0
description: The unique ID of the event.
session:
$ref: '#/components/schemas/SessionResource'
description: The paused session.
obfuscation:
type: string
minLength: 0
description: Random alphanumeric padding. Present when stream obfuscation is enabled.
required:
- type
- event_id
- session
additionalProperties: false
description: Emitted when a session pauses because its spending limit was reached.
SessionBudgetControlParams:
type: object
properties:
limit:
type:
- integer
- 'null'
format: int64
minimum: 1
maximum: 4503599627370495
description: Positive USD cents, or null to remove the limit.
required:
- limit
additionalProperties: false
description: Sets the session-wide limit without changing recorded spend.
SessionBudgetControlResource:
type: object
properties:
limit:
type:
- integer
- 'null'
format: int64
minimum: 1
maximum: 4503599627370495
description: The configured positive limit in USD cents, or null when unlimited.
consumed:
type:
- integer
- 'null'
minimum: 0
description: Best-effort recorded spend floored to whole USD cents, or null when unavailable.
required:
- limit
- consumed
additionalProperties: false
description: Session-wide spending limit and best-effort consumption, including unlimited sessions.
LiveMCPToolFilterParam:
type: object
properties:
Expand Down
22 changes: 9 additions & 13 deletions scripts/castiron/generated-files.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": {
"api.md": {
"mode": "100644",
"sha256": "6474a963c5d360eb6e63a3e4c4b305a0d2508afcc85a730a552df8666fe658f3"
"sha256": "9b8076604c5fa4ab278804b9893edfed16206861f4f93e67e7a4dc503f132c5d"
},
"src/openai/__init__.py": {
"mode": "100644",
Expand Down Expand Up @@ -303,7 +303,7 @@
},
"src/openai/resources/beta/agents/sessions/sessions.py": {
"mode": "100644",
"sha256": "d7b1d7b3e97f28f73634ed36ab83a2fdc9bf3a2c1c7e85e4607cca49f841db5a"
"sha256": "7f4393866730e2d79a254c46559561e36674de90e102c4a3ff516fd89b8d6109"
},
"src/openai/resources/beta/agents/sessions/subagents/__init__.py": {
"mode": "100644",
Expand Down Expand Up @@ -1659,7 +1659,7 @@
},
"src/openai/types/beta/__init__.py": {
"mode": "100644",
"sha256": "5b71c93740ed29812ef583e270b14bcfa799b5634bd76c1f98fa31150de42ed4"
"sha256": "7db7f38a689e6256dae3ff5227510e053f915a5782454b3adde9095264afb499"
},
"src/openai/types/beta/agent.py": {
"mode": "100644",
Expand Down Expand Up @@ -1775,16 +1775,12 @@
},
"src/openai/types/beta/agent_session.py": {
"mode": "100644",
"sha256": "4871b70ba64d8ffc00a27a1fbebad8de1fa079525f2b06ba4309098dd889c83e"
"sha256": "d7112cb67c59fbb1c993d666ea4ca8bea709de9c4c3b2738cd16d395744bc072"
},
"src/openai/types/beta/agent_session_assistant_message.py": {
"mode": "100644",
"sha256": "cd658ea7c56193403b7188950c00702190c929a72fc3d0be0e7853d710c4f57a"
},
"src/openai/types/beta/agent_session_budget_reached_event.py": {
"mode": "100644",
"sha256": "d4a4be2e3366b97aa8d9256c53b2278a6cbebafb0004fc5f49951bc7d05d437a"
},
"src/openai/types/beta/agent_session_created_event.py": {
"mode": "100644",
"sha256": "ece7da18f956751a79a28098a8297f87c0adc9db4b8cf36b7528941a08fa5b1e"
Expand Down Expand Up @@ -1835,7 +1831,7 @@
},
"src/openai/types/beta/agent_session_event.py": {
"mode": "100644",
"sha256": "2b42487182e4ba75a2a865f66f646c8f02cfad3597ec4ab897917d6f8fc569f6"
"sha256": "96b07cffe33f0ec960eeb92b317018f05c5f0a633d0f4b01e741073c085fdb5e"
},
"src/openai/types/beta/agent_session_failed_event.py": {
"mode": "100644",
Expand Down Expand Up @@ -2095,15 +2091,15 @@
},
"src/openai/types/beta/agents/session_create_params.py": {
"mode": "100644",
"sha256": "44261a235f763e718d5c71de57cc87eb7c2e502ada26c350c62e7b1d2c73bdf6"
"sha256": "32b7560fe3a117d1cd50ea68affa615b4c35dd17cb845dc2ec4f5dc1cd3b7682"
},
"src/openai/types/beta/agents/session_list_params.py": {
"mode": "100644",
"sha256": "2de32d51ce2cfdbcf2224acfa8b04a28234717d6c373a3d68ee66bac90f75d2d"
},
"src/openai/types/beta/agents/session_update_params.py": {
"mode": "100644",
"sha256": "22f0f47d3b8158bb9aa9a588bec6944171432cddbb757aaeaf8c0602a2b232a6"
"sha256": "a3d82223cbaeff336175539efebf8998d6bc5193bcabcc82c1f11a724176f05d"
},
"src/openai/types/beta/agents/sessions/__init__.py": {
"mode": "100644",
Expand Down Expand Up @@ -3535,7 +3531,7 @@
},
"src/openai/types/beta/session_turn_error.py": {
"mode": "100644",
"sha256": "0509a933cb578c18a49dd1abf2d689bf4da1c6e8bb8b7e80d5d024c22b41042e"
"sha256": "5c001662a8a2ba24efe4d7d42a4c37ba70e9c45e095ebfd3c973fa32af48ad7e"
},
"src/openai/types/beta/setup_command_param.py": {
"mode": "100644",
Expand Down Expand Up @@ -7815,7 +7811,7 @@
},
"tests/api_resources/beta/agents/test_sessions.py": {
"mode": "100644",
"sha256": "8f3c9a080fa915a1febed855312d597184431105e4227c1f4acfd24a42dd8ee9"
"sha256": "1bda32e69765f37c574631637155008a86e4e66973581112e8a4aaa37ba21e44"
},
"tests/api_resources/beta/agents/test_vaults.py": {
"mode": "100644",
Expand Down
22 changes: 15 additions & 7 deletions src/openai/lib/beta/agents/_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,21 @@ def accept(self, event: AgentSessionEvent) -> None:
self.session_id = event.session.id
self.session_failed = True
self.boundary = True
elif event.type == "agent.session.budget_reached" and self.turn is None:
if self.session_id in (None, event.session.id):
self.session_id = event.session.id
self.boundary = True
elif event.type == "agent.session.idle" or (
event.type == "agent.session.budget_reached" and event.session.id == self.session_id
):
elif getattr(event, "type", None) == "agent.session.budget_reached":
snapshot = getattr(event, "session", None)
snapshot_id = snapshot.get("id") if isinstance(snapshot, dict) else getattr(snapshot, "id", None)
if isinstance(snapshot_id, str) and snapshot_id:
if self.turn is None and self.session_id in (None, snapshot_id):
self.session_id = snapshot_id
self.boundary = True
elif (
self.turn is not None
and snapshot_id == self.session_id
and self.turn.status in ("completed", "failed", "cancelled")
):
self.required_actions = []
self.boundary = True
elif event.type == "agent.session.idle":
if self.turn is not None and self.turn.status in ("completed", "failed", "cancelled"):
self.required_actions = []
self.boundary = True
Expand Down
16 changes: 9 additions & 7 deletions src/openai/lib/streaming/agents/_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,17 @@ def accept(self, event: AgentSessionEvent) -> bool:
return True

def terminal(self, event: AgentSessionEvent, session_id: str) -> bool:
return (
event.type == "agent.session.failed"
or (
event.type == "agent.session.budget_reached"
and event.session.id == session_id
# Private lifecycle frames can outlive their generated public union variant.
if getattr(event, "type", None) == "agent.session.budget_reached":
snapshot = getattr(event, "session", None)
snapshot_id = snapshot.get("id") if isinstance(snapshot, dict) else getattr(snapshot, "id", None)
return (
isinstance(snapshot_id, str)
and bool(snapshot_id)
and snapshot_id == session_id
and (self.turn_id is None or self.turn_ended)
)
or (event.type == "agent.session.idle" and self.turn_ended)
)
return event.type == "agent.session.failed" or (event.type == "agent.session.idle" and self.turn_ended)


class AgentSessionStream(Generic[OutputT]):
Expand Down
Loading
Loading