Skip to content

Commit 77fd116

Browse files
feat(api): filter agent sessions by metadata (#4200)
## Summary Adds optional metadata filters when listing agent sessions. ## Changes - Filter sessions by exact metadata key-value matches. - Combine metadata filters with existing pagination and agent filters.
1 parent 5b43cce commit 77fd116

6 files changed

Lines changed: 51 additions & 8 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: e164ac83-c112-4711-be50-ebb428fe3158
3-
openapi_spec_hash: 0fa065837f86231ded0decb63dbdf0b7
4-
openapi_transformed_spec_hash: 89a4e53d02ad69dde25fe7b073c64609
2+
generation_id: 45c2be6c-9b78-4bff-b88b-f437435ae397
3+
openapi_spec_hash: 7b8e0964b34b0cf993d2e2946e8eac7a
4+
openapi_transformed_spec_hash: 096782182a5f2b2d0d09fb4822e35e10
55
config_hash: 0e042fd083471fc089bcbfe7011a7d01
6-
codegen_sha: 3f4c502584c527f11658bdeb8c487e8cee0ed4da
7-
codegen_hash: a13510d3bcce387fb660ffbe32d7a3155e53c9b19fe9339d4ff1dd4e4211335c
6+
codegen_sha: 2d3d72e9eb4ebaca41912b7d0ce1bc8733a90569
7+
codegen_hash: fec5e33e84cf8605506e7b95a1dd30735e4cffe16ec560150a65b669d4975ebd

‎api_reference/openapi.transformed.yml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33173,6 +33173,24 @@ paths:
3317333173
minLength: 0
3317433174
maxLength: 1048576
3317533175
description: Only return sessions whose root agent has this ID. Omit to return sessions for all agents.
33176+
- name: metadata
33177+
in: query
33178+
required: false
33179+
schema:
33180+
type: object
33181+
additionalProperties:
33182+
type: string
33183+
minLength: 0
33184+
maxLength: 512
33185+
propertyNames:
33186+
type: string
33187+
minLength: 1
33188+
maxLength: 64
33189+
minProperties: 0
33190+
maxProperties: 16
33191+
description: Exact string matches supplied as `metadata[key]=value`. All supplied pairs must match. Up to 16 pairs, with keys from 1 to 64 characters and values up to 512 characters. New sessions and metadata updates may take time to appear in filtered results.
33192+
style: deepObject
33193+
explode: true
3317633194
responses:
3317733195
'200':
3317833196
description: A page of sessions.

‎scripts/castiron/generated-files.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
},
284284
"src/openai/resources/beta/agents/sessions/sessions.py": {
285285
"mode": "100644",
286-
"sha256": "65699418bb2e7b847de57b9c2d9c82acf0f94dfb99b46391ab61331580e7032c"
286+
"sha256": "d1719b767d0b16e9eba1c405a66e9c11874da30a6ba2fa873603d1e6a9f6f7e2"
287287
},
288288
"src/openai/resources/beta/agents/sessions/subagents/__init__.py": {
289289
"mode": "100644",
@@ -2003,7 +2003,7 @@
20032003
},
20042004
"src/openai/types/beta/agents/session_list_params.py": {
20052005
"mode": "100644",
2006-
"sha256": "4f0902a10fe694a0efa2f7073cca64a2aea6e4c346f71176e49aef4621ed049d"
2006+
"sha256": "2de32d51ce2cfdbcf2224acfa8b04a28234717d6c373a3d68ee66bac90f75d2d"
20072007
},
20082008
"src/openai/types/beta/agents/session_update_params.py": {
20092009
"mode": "100644",
@@ -7691,7 +7691,7 @@
76917691
},
76927692
"tests/api_resources/beta/agents/test_sessions.py": {
76937693
"mode": "100644",
7694-
"sha256": "6b8c1e42b3465b95d3c6ab5449ea8cb95c8b93427ccd59c0b96694e5e1a972bb"
7694+
"sha256": "10a9f8cbd1fda1b32b4bf7a0ac422073e82463b9dd1f9151d159951ea47005d8"
76957695
},
76967696
"tests/api_resources/beta/agents/test_vaults.py": {
76977697
"mode": "100644",

‎src/openai/resources/beta/agents/sessions/sessions.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ def list(
379379
after: str | Omit = omit,
380380
agent_id: str | Omit = omit,
381381
limit: int | Omit = omit,
382+
metadata: Dict[str, str] | Omit = omit,
382383
order: Literal["asc", "desc"] | Omit = omit,
383384
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
384385
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -400,6 +401,11 @@ def list(
400401
401402
limit: The maximum number of resources to return, between 1 and 100. Defaults to 20.
402403
404+
metadata: Exact string matches supplied as `metadata[key]=value`. All supplied pairs must
405+
match. Up to 16 pairs, with keys from 1 to 64 characters and values up to 512
406+
characters. New sessions and metadata updates may take time to appear in
407+
filtered results.
408+
403409
order: The order in which resources are returned. Defaults to `desc`.
404410
405411
- `asc` - Returns resources in ascending order.
@@ -427,6 +433,7 @@ def list(
427433
"after": after,
428434
"agent_id": agent_id,
429435
"limit": limit,
436+
"metadata": metadata,
430437
"order": order,
431438
},
432439
session_list_params.SessionListParams,
@@ -781,6 +788,7 @@ def list(
781788
after: str | Omit = omit,
782789
agent_id: str | Omit = omit,
783790
limit: int | Omit = omit,
791+
metadata: Dict[str, str] | Omit = omit,
784792
order: Literal["asc", "desc"] | Omit = omit,
785793
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
786794
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -802,6 +810,11 @@ def list(
802810
803811
limit: The maximum number of resources to return, between 1 and 100. Defaults to 20.
804812
813+
metadata: Exact string matches supplied as `metadata[key]=value`. All supplied pairs must
814+
match. Up to 16 pairs, with keys from 1 to 64 characters and values up to 512
815+
characters. New sessions and metadata updates may take time to appear in
816+
filtered results.
817+
805818
order: The order in which resources are returned. Defaults to `desc`.
806819
807820
- `asc` - Returns resources in ascending order.
@@ -829,6 +842,7 @@ def list(
829842
"after": after,
830843
"agent_id": agent_id,
831844
"limit": limit,
845+
"metadata": metadata,
832846
"order": order,
833847
},
834848
session_list_params.SessionListParams,

‎src/openai/types/beta/agents/session_list_params.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from typing import Dict
56
from typing_extensions import Literal, TypedDict
67

78
__all__ = ["SessionListParams"]
@@ -20,6 +21,14 @@ class SessionListParams(TypedDict, total=False):
2021
limit: int
2122
"""The maximum number of resources to return, between 1 and 100. Defaults to 20."""
2223

24+
metadata: Dict[str, str]
25+
"""Exact string matches supplied as `metadata[key]=value`.
26+
27+
All supplied pairs must match. Up to 16 pairs, with keys from 1 to 64 characters
28+
and values up to 512 characters. New sessions and metadata updates may take time
29+
to appear in filtered results.
30+
"""
31+
2332
order: Literal["asc", "desc"]
2433
"""The order in which resources are returned. Defaults to `desc`.
2534

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ def test_method_list_with_all_params(self, client: OpenAI) -> None:
261261
after="after",
262262
agent_id="agent_id",
263263
limit=1,
264+
metadata={"foo": "string"},
264265
order="asc",
265266
)
266267
assert_matches_type(SyncCursorPage[AgentSession], session, path=["response"])
@@ -572,6 +573,7 @@ async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> N
572573
after="after",
573574
agent_id="agent_id",
574575
limit=1,
576+
metadata={"foo": "string"},
575577
order="asc",
576578
)
577579
assert_matches_type(AsyncCursorPage[AgentSession], session, path=["response"])

0 commit comments

Comments
 (0)