Skip to content

Commit ea07983

Browse files
feat(api): add typed async function tools (#4264)
## Changes being requested This update has been adding optional `async` settings to function-tool request dictionaries for sessions and persisted agents. Response models have been exposing the field as `async_`. ## Additional context & links Callers that have been reading the undeclared response extra through `getattr(tool, 'async')` or `tool.model_extra['async']` have been needing to use `tool.async_`. Serialization with `model_dump(by_alias=True, exclude_unset=True)` has been preserving `true`, `false`, and omission. Plain `model_dump(by_alias=True)` has been including `async: None` for omitted values. Co-authored-by: markstuart-oai <[email protected]>
1 parent 13c000d commit ea07983

10 files changed

Lines changed: 66 additions & 14 deletions

File tree

‎.castiron.stats.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
schema_version: 1
2-
generation_id: a3bf0f9e-b174-47ac-a9b6-9e0470a93dad
3-
openapi_spec_hash: 7c533705ce2105493f542be5c5e6eab3
4-
openapi_transformed_spec_hash: a5880780f650c428cc4897bab03e6da1
2+
generation_id: a358570b-482e-447e-998d-4f5425c5d316
3+
openapi_spec_hash: 632d949bd61b801d58c87dcda5ddc605
4+
openapi_transformed_spec_hash: 9a761f59f8f8e5095ea94652ff2f91d6
55
config_hash: 01f2d28b82141ac460c9d9e8cc45ee74
6-
codegen_sha: fa7699eaec8e1f35bda13cf958ad67e7a2b8c168
7-
codegen_hash: 8c7ec3da81d1769c4ad4c0631e08e93bf5259a96ed6a727a19dd34ba7323880d
6+
codegen_sha: 3a7ad42a6b1bb5cac701b1d6621307e5fadd0b3f
7+
codegen_hash: 908930605be8cf176da37b24e4f5ab6d063001b3d7eb8467e5d1c6a0b2b2b208

‎api_reference/openapi.transformed.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87149,6 +87149,9 @@ components:
8714987149
defer_loading:
8715087150
type: boolean
8715187151
description: Whether the function is deferred and discovered through tool search.
87152+
async:
87153+
type: boolean
87154+
description: Whether the agent continues without waiting for the function result.
8715287155
required:
8715387156
- type
8715487157
- name
@@ -88565,6 +88568,10 @@ components:
8856588568
type: boolean
8856688569
default: false
8856788570
description: Whether this function is deferred and discovered through tool search. Defaults to `false`.
88571+
async:
88572+
type: boolean
88573+
default: false
88574+
description: Whether the agent continues without waiting for the function result. Defaults to `false`.
8856888575
required:
8856988576
- type
8857088577
- name
@@ -92106,6 +92113,9 @@ components:
9210692113
defer_loading:
9210792114
type: boolean
9210892115
description: Whether the function is deferred and discovered through tool search.
92116+
async:
92117+
type: boolean
92118+
description: Whether the agent continues without waiting for the function result.
9210992119
required:
9211092120
- type
9211192121
- name
@@ -92560,6 +92570,10 @@ components:
9256092570
type: boolean
9256192571
default: false
9256292572
description: Whether this function is deferred and discovered through tool search. Defaults to `false`.
92573+
async:
92574+
type: boolean
92575+
default: false
92576+
description: Whether the agent continues without waiting for the function result. Defaults to `false`.
9256392577
required:
9256492578
- type
9256592579
- name

‎scripts/castiron/generated-files.json‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,11 +1951,11 @@
19511951
},
19521952
"src/openai/types/beta/agent_tool.py": {
19531953
"mode": "100644",
1954-
"sha256": "ed568481e6de6956b9deccfbb7cce718bba3cfbab6270851602886141af5230c"
1954+
"sha256": "145a8f0a9e15d6aa46b116296c9cfbdfd3fc7f5530d99fdb070b3f43439a39b5"
19551955
},
19561956
"src/openai/types/beta/agent_tool_param.py": {
19571957
"mode": "100644",
1958-
"sha256": "50116fba12372f68fc831149fafc3896e5b0be3f8f12bc72cc539ead14be34b3"
1958+
"sha256": "44b83c04613add6637b8de7bb48cbf4b1220ddde3d1a2e50e1edfb9d6d4b8990"
19591959
},
19601960
"src/openai/types/beta/agent_update_params.py": {
19611961
"mode": "100644",
@@ -3479,11 +3479,11 @@
34793479
},
34803480
"src/openai/types/beta/persisted_agent_tool.py": {
34813481
"mode": "100644",
3482-
"sha256": "337c62e5505ccc43656dad66d619b0a0be532181c8f598e7ccf047b9e6ed8824"
3482+
"sha256": "b44af4c00085918e647a899f0d6f3efad4b70d59ec7d3034e6130c4128b9374c"
34833483
},
34843484
"src/openai/types/beta/persisted_agent_tool_param.py": {
34853485
"mode": "100644",
3486-
"sha256": "d9e83ab1f8347f4acc525746b1e2c0bc42cbcf64742976dea0983cc419e8fe74"
3486+
"sha256": "11cd9c21954b53b21883fb68c5f751811663ee653bfef429c53a81a24916b934"
34873487
},
34883488
"src/openai/types/beta/persisted_mcp_transport.py": {
34893489
"mode": "100644",
@@ -7799,15 +7799,15 @@
77997799
},
78007800
"tests/api_resources/beta/agents/test_automations.py": {
78017801
"mode": "100644",
7802-
"sha256": "34501f413c83a2ccd9aa494eb59f5c0ae1ba21fa14619dd2bc41571ad8a6422a"
7802+
"sha256": "2b10ce0346ce9ff87a52782763f6e544c6a7320a0075c7972624dcc4e8b9cf78"
78037803
},
78047804
"tests/api_resources/beta/agents/test_environments.py": {
78057805
"mode": "100644",
78067806
"sha256": "529f48933850ff09980fbd8a8ec6c9bef538efa5bffa71660e14421693df02fa"
78077807
},
78087808
"tests/api_resources/beta/agents/test_sessions.py": {
78097809
"mode": "100644",
7810-
"sha256": "fa6f36b530895301c9bb4fe928639dfa4c4f15826f9f5a2f652b0e89ff9a956f"
7810+
"sha256": "eda3b15034c7e46e8fe0c4428143b35abd4aed76db58ff0d374625369591ad66"
78117811
},
78127812
"tests/api_resources/beta/agents/test_vaults.py": {
78137813
"mode": "100644",
@@ -7847,7 +7847,7 @@
78477847
},
78487848
"tests/api_resources/beta/test_agents.py": {
78497849
"mode": "100644",
7850-
"sha256": "6216ae37c6ea996da62e4916570840ed549aeb86603b607d61078b4b30c87d15"
7850+
"sha256": "3147acf9a9f9628c4aaed1d51aee13cde66c88bea3e9324d3c157daa68070f68"
78517851
},
78527852
"tests/api_resources/beta/test_assistants.py": {
78537853
"mode": "100644",

‎src/openai/types/beta/agent_tool.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from typing import Dict, List, Union, Optional
44
from typing_extensions import Literal, Annotated, TypeAlias
55

6+
from pydantic import Field as FieldInfo
7+
68
from ..._utils import PropertyInfo
79
from ..._models import BaseModel
810
from .mcp_transport import McpTransport
@@ -37,6 +39,9 @@ class AgentToolResourceFunction(BaseModel):
3739
type: Literal["function"]
3840
"""The type of the object. Always `function`."""
3941

42+
async_: Optional[bool] = FieldInfo(alias="async", default=None)
43+
"""Whether the agent continues without waiting for the function result."""
44+
4045

4146
class AgentToolResourceProgrammaticToolCalling(BaseModel):
4247
"""Enables calling tools from model-generated code."""

‎src/openai/types/beta/agent_tool_param.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@
2020
"AgentToolConfigParamAutomations",
2121
]
2222

23+
_AgentToolConfigParamFunctionReservedKeywords = TypedDict(
24+
"_AgentToolConfigParamFunctionReservedKeywords",
25+
{
26+
"async": bool,
27+
},
28+
total=False,
29+
)
2330

24-
class AgentToolConfigParamFunction(TypedDict, total=False):
31+
32+
class AgentToolConfigParamFunction(_AgentToolConfigParamFunctionReservedKeywords, total=False):
2533
"""A function defined by the application."""
2634

2735
description: Required[str]

‎src/openai/types/beta/persisted_agent_tool.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from typing import Dict, List, Union, Optional
44
from typing_extensions import Literal, Annotated, TypeAlias
55

6+
from pydantic import Field as FieldInfo
7+
68
from ..._utils import PropertyInfo
79
from ..._models import BaseModel
810
from .persisted_mcp_transport import PersistedMcpTransport
@@ -38,6 +40,9 @@ class PersistedAgentToolResourceFunction(BaseModel):
3840
type: Literal["function"]
3941
"""The type of the object. Always `function`."""
4042

43+
async_: Optional[bool] = FieldInfo(alias="async", default=None)
44+
"""Whether the agent continues without waiting for the function result."""
45+
4146

4247
class PersistedAgentToolResourceToolSearch(BaseModel):
4348
"""Discovers deferred function tools and loads them into the model context."""

‎src/openai/types/beta/persisted_agent_tool_param.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@
2020
"PersistedAgentToolConfigParamAutomations",
2121
]
2222

23+
_PersistedAgentToolConfigParamFunctionReservedKeywords = TypedDict(
24+
"_PersistedAgentToolConfigParamFunctionReservedKeywords",
25+
{
26+
"async": bool,
27+
},
28+
total=False,
29+
)
2330

24-
class PersistedAgentToolConfigParamFunction(TypedDict, total=False):
31+
32+
class PersistedAgentToolConfigParamFunction(_PersistedAgentToolConfigParamFunctionReservedKeywords, total=False):
2533
"""A function defined by the application."""
2634

2735
description: Required[str]

‎tests/api_resources/beta/agents/test_automations.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ def test_method_update_with_all_params(self, client: OpenAI) -> None:
331331
"name": "name",
332332
"parameters": {"foo": "bar"},
333333
"type": "function",
334+
"async": True,
334335
"defer_loading": True,
335336
}
336337
],
@@ -839,6 +840,7 @@ async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) ->
839840
"name": "name",
840841
"parameters": {"foo": "bar"},
841842
"type": "function",
843+
"async": True,
842844
"defer_loading": True,
843845
}
844846
],

‎tests/api_resources/beta/agents/test_sessions.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def test_method_create_with_all_params_overload_1(self, client: OpenAI) -> None:
5353
"name": "name",
5454
"parameters": {"foo": "bar"},
5555
"type": "function",
56+
"async": True,
5657
"defer_loading": True,
5758
}
5859
],
@@ -129,6 +130,7 @@ def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None:
129130
"name": "name",
130131
"parameters": {"foo": "bar"},
131132
"type": "function",
133+
"async": True,
132134
"defer_loading": True,
133135
}
134136
],
@@ -229,6 +231,7 @@ def test_method_update_with_all_params(self, client: OpenAI) -> None:
229231
"name": "name",
230232
"parameters": {"foo": "bar"},
231233
"type": "function",
234+
"async": True,
232235
"defer_loading": True,
233236
}
234237
],
@@ -385,6 +388,7 @@ async def test_method_create_with_all_params_overload_1(self, async_client: Asyn
385388
"name": "name",
386389
"parameters": {"foo": "bar"},
387390
"type": "function",
391+
"async": True,
388392
"defer_loading": True,
389393
}
390394
],
@@ -461,6 +465,7 @@ async def test_method_create_with_all_params_overload_2(self, async_client: Asyn
461465
"name": "name",
462466
"parameters": {"foo": "bar"},
463467
"type": "function",
468+
"async": True,
464469
"defer_loading": True,
465470
}
466471
],
@@ -561,6 +566,7 @@ async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) ->
561566
"name": "name",
562567
"parameters": {"foo": "bar"},
563568
"type": "function",
569+
"async": True,
564570
"defer_loading": True,
565571
}
566572
],

‎tests/api_resources/beta/test_agents.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def test_method_create_with_all_params(self, client: OpenAI) -> None:
5656
"name": "name",
5757
"parameters": {"foo": "bar"},
5858
"type": "function",
59+
"async": True,
5960
"defer_loading": True,
6061
}
6162
],
@@ -160,6 +161,7 @@ def test_method_update_with_all_params(self, client: OpenAI) -> None:
160161
"name": "name",
161162
"parameters": {"foo": "bar"},
162163
"type": "function",
164+
"async": True,
163165
"defer_loading": True,
164166
}
165167
],
@@ -310,6 +312,7 @@ async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) ->
310312
"name": "name",
311313
"parameters": {"foo": "bar"},
312314
"type": "function",
315+
"async": True,
313316
"defer_loading": True,
314317
}
315318
],
@@ -414,6 +417,7 @@ async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) ->
414417
"name": "name",
415418
"parameters": {"foo": "bar"},
416419
"type": "function",
420+
"async": True,
417421
"defer_loading": True,
418422
}
419423
],

0 commit comments

Comments
 (0)