Skip to content

Commit c6872f0

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Add orderBy to ListMemories
PiperOrigin-RevId: 804536990
1 parent 74e3f25 commit c6872f0

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

tests/unit/vertexai/genai/replays/test_list_agent_engine_memories.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,37 @@
2121
def test_list_memories(client):
2222
agent_engine = client.agent_engines.create()
2323
assert not list(
24-
client.agent_engines.list_memories(
24+
client.agent_engines.memories.list(
2525
name=agent_engine.api_resource.name,
2626
)
2727
)
28-
client.agent_engines.create_memory(
28+
client.agent_engines.memories.create(
2929
name=agent_engine.api_resource.name,
3030
fact="memory_fact",
3131
scope={"user_id": "123"},
32+
config={
33+
"wait_for_completion": True,
34+
},
3235
)
33-
memory_list = client.agent_engines.list_memories(
36+
client.agent_engines.memories.create(
3437
name=agent_engine.api_resource.name,
38+
fact="memory_fact_2",
39+
scope={"user_id": "456"},
40+
config={
41+
"wait_for_completion": True,
42+
},
43+
)
44+
memory_list = client.agent_engines.memories.list(
45+
name=agent_engine.api_resource.name,
46+
config=types.ListAgentEngineMemoryConfig(
47+
page_size=1,
48+
order_by="create_time asc",
49+
),
3550
)
3651
assert len(memory_list) == 1
3752
assert isinstance(memory_list[0], types.Memory)
53+
assert memory_list[0].fact == "memory_fact"
54+
assert memory_list[0].scope["user_id"] == "123"
3855
# Clean up resources.
3956
agent_engine.delete(force=True)
4057

vertexai/_genai/memories.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ def _ListAgentEngineMemoryConfig_to_vertex(
249249
if getv(from_object, ["filter"]) is not None:
250250
setv(parent_object, ["_query", "filter"], getv(from_object, ["filter"]))
251251

252+
if getv(from_object, ["order_by"]) is not None:
253+
setv(parent_object, ["_query", "orderBy"], getv(from_object, ["order_by"]))
254+
252255
return to_object
253256

254257

vertexai/_genai/types.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5214,6 +5214,17 @@ class ListAgentEngineMemoryConfig(_common.BaseModel):
52145214
description="""An expression for filtering the results of the request.
52155215
For field names both snake_case and camelCase are supported.""",
52165216
)
5217+
order_by: Optional[str] = Field(
5218+
default=None,
5219+
description="""The standard list order by string. If not specified, the default
5220+
order is `create_time desc`. If specified, the default sorting order of
5221+
provided fields is ascending. More detail in
5222+
[AIP-132](https://google.aip.dev/132).
5223+
5224+
Supported fields:
5225+
* `create_time`
5226+
* `update_time`""",
5227+
)
52175228

52185229

52195230
class ListAgentEngineMemoryConfigDict(TypedDict, total=False):
@@ -5232,6 +5243,16 @@ class ListAgentEngineMemoryConfigDict(TypedDict, total=False):
52325243
"""An expression for filtering the results of the request.
52335244
For field names both snake_case and camelCase are supported."""
52345245

5246+
order_by: Optional[str]
5247+
"""The standard list order by string. If not specified, the default
5248+
order is `create_time desc`. If specified, the default sorting order of
5249+
provided fields is ascending. More detail in
5250+
[AIP-132](https://google.aip.dev/132).
5251+
5252+
Supported fields:
5253+
* `create_time`
5254+
* `update_time`"""
5255+
52355256

52365257
ListAgentEngineMemoryConfigOrDict = Union[
52375258
ListAgentEngineMemoryConfig, ListAgentEngineMemoryConfigDict

0 commit comments

Comments
 (0)