google-cloud-agentplatform 1.165.1.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentplatform/__init__.py +72 -0
- agentplatform/_genai/__init__.py +43 -0
- agentplatform/_genai/_agent_engines_utils.py +2341 -0
- agentplatform/_genai/_bigquery_utils.py +49 -0
- agentplatform/_genai/_datasets_utils.py +344 -0
- agentplatform/_genai/_evals_builtin_tools.py +209 -0
- agentplatform/_genai/_evals_common.py +4268 -0
- agentplatform/_genai/_evals_constant.py +122 -0
- agentplatform/_genai/_evals_data_converters.py +926 -0
- agentplatform/_genai/_evals_metric_handlers.py +1783 -0
- agentplatform/_genai/_evals_metric_loaders.py +401 -0
- agentplatform/_genai/_evals_utils.py +1043 -0
- agentplatform/_genai/_evals_visualization.py +2070 -0
- agentplatform/_genai/_gcs_utils.py +262 -0
- agentplatform/_genai/_logging_utils.py +47 -0
- agentplatform/_genai/_memory_bank_utils.py +206 -0
- agentplatform/_genai/_observability_data_converter.py +186 -0
- agentplatform/_genai/_operations_utils.py +94 -0
- agentplatform/_genai/_prompt_management_utils.py +147 -0
- agentplatform/_genai/_prompt_optimizer_utils.py +215 -0
- agentplatform/_genai/_skills_utils.py +69 -0
- agentplatform/_genai/_transformers.py +628 -0
- agentplatform/_genai/a2a_task_events.py +509 -0
- agentplatform/_genai/a2a_tasks.py +861 -0
- agentplatform/_genai/agent_engines.py +3931 -0
- agentplatform/_genai/client.py +519 -0
- agentplatform/_genai/datasets.py +3045 -0
- agentplatform/_genai/endpoints.py +1149 -0
- agentplatform/_genai/evals.py +6883 -0
- agentplatform/_genai/example_stores.py +1445 -0
- agentplatform/_genai/feedback_contexts.py +700 -0
- agentplatform/_genai/feedback_entries.py +1644 -0
- agentplatform/_genai/live.py +64 -0
- agentplatform/_genai/live_agent_engines.py +179 -0
- agentplatform/_genai/memories.py +2962 -0
- agentplatform/_genai/memory_banks.py +1927 -0
- agentplatform/_genai/memory_revisions.py +465 -0
- agentplatform/_genai/model_garden.py +2638 -0
- agentplatform/_genai/prompt_optimizer.py +995 -0
- agentplatform/_genai/prompts.py +4515 -0
- agentplatform/_genai/rag.py +4961 -0
- agentplatform/_genai/runtime_revisions.py +1257 -0
- agentplatform/_genai/runtimes.py +78 -0
- agentplatform/_genai/sandbox_snapshots.py +1015 -0
- agentplatform/_genai/sandbox_templates.py +1088 -0
- agentplatform/_genai/sandboxes.py +1604 -0
- agentplatform/_genai/session_events.py +543 -0
- agentplatform/_genai/sessions.py +1449 -0
- agentplatform/_genai/skill_revisions.py +377 -0
- agentplatform/_genai/skills.py +1708 -0
- agentplatform/_genai/types/__init__.py +4695 -0
- agentplatform/_genai/types/agent_engines.py +16 -0
- agentplatform/_genai/types/common.py +32784 -0
- agentplatform/_genai/types/evals.py +1031 -0
- agentplatform/_genai/types/prompt_optimizer.py +107 -0
- agentplatform/_genai/types/prompts.py +107 -0
- agentplatform/version.py +17 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/METADATA +79 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/RECORD +62 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/WHEEL +5 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/licenses/LICENSE +202 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,2962 @@
|
|
|
1
|
+
# Copyright 2025 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
#
|
|
15
|
+
|
|
16
|
+
# Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
17
|
+
|
|
18
|
+
import builtins
|
|
19
|
+
import functools
|
|
20
|
+
import importlib
|
|
21
|
+
import json
|
|
22
|
+
import logging
|
|
23
|
+
import typing
|
|
24
|
+
from typing import Any, Iterator, List, Optional, Union
|
|
25
|
+
from urllib.parse import urlencode
|
|
26
|
+
|
|
27
|
+
from google.genai import _api_module
|
|
28
|
+
from google.genai import _common
|
|
29
|
+
from google.genai._common import get_value_by_path as getv
|
|
30
|
+
from google.genai._common import set_value_by_path as setv
|
|
31
|
+
from google.genai.pagers import AsyncPager, Pager
|
|
32
|
+
|
|
33
|
+
from . import _memory_bank_utils
|
|
34
|
+
from . import types
|
|
35
|
+
|
|
36
|
+
if typing.TYPE_CHECKING:
|
|
37
|
+
from . import memory_revisions as memory_revisions_module
|
|
38
|
+
|
|
39
|
+
_ = memory_revisions_module
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
logger = logging.getLogger("agentplatform_genai.memories")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _CreateMemoryRequestParameters_to_vertex(
|
|
46
|
+
from_object: Union[dict[str, Any], object],
|
|
47
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
48
|
+
) -> dict[str, Any]:
|
|
49
|
+
to_object: dict[str, Any] = {}
|
|
50
|
+
if getv(from_object, ["name"]) is not None:
|
|
51
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
52
|
+
|
|
53
|
+
if getv(from_object, ["fact"]) is not None:
|
|
54
|
+
setv(to_object, ["fact"], getv(from_object, ["fact"]))
|
|
55
|
+
|
|
56
|
+
if getv(from_object, ["scope"]) is not None:
|
|
57
|
+
setv(to_object, ["scope"], getv(from_object, ["scope"]))
|
|
58
|
+
|
|
59
|
+
if getv(from_object, ["config"]) is not None:
|
|
60
|
+
_MemoryConfig_to_vertex(getv(from_object, ["config"]), to_object)
|
|
61
|
+
|
|
62
|
+
return to_object
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _DeleteMemoryRequestParameters_to_vertex(
|
|
66
|
+
from_object: Union[dict[str, Any], object],
|
|
67
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
68
|
+
) -> dict[str, Any]:
|
|
69
|
+
to_object: dict[str, Any] = {}
|
|
70
|
+
if getv(from_object, ["name"]) is not None:
|
|
71
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
72
|
+
|
|
73
|
+
return to_object
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _GenerateMemoriesConfig_to_vertex(
|
|
77
|
+
from_object: Union[dict[str, Any], object],
|
|
78
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
79
|
+
) -> dict[str, Any]:
|
|
80
|
+
to_object: dict[str, Any] = {}
|
|
81
|
+
|
|
82
|
+
if getv(from_object, ["disable_consolidation"]) is not None:
|
|
83
|
+
setv(
|
|
84
|
+
parent_object,
|
|
85
|
+
["disableConsolidation"],
|
|
86
|
+
getv(from_object, ["disable_consolidation"]),
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
if getv(from_object, ["revision_labels"]) is not None:
|
|
90
|
+
setv(parent_object, ["revisionLabels"], getv(from_object, ["revision_labels"]))
|
|
91
|
+
|
|
92
|
+
if getv(from_object, ["revision_expire_time"]) is not None:
|
|
93
|
+
setv(
|
|
94
|
+
parent_object,
|
|
95
|
+
["revisionExpireTime"],
|
|
96
|
+
getv(from_object, ["revision_expire_time"]),
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
if getv(from_object, ["revision_ttl"]) is not None:
|
|
100
|
+
setv(parent_object, ["revisionTtl"], getv(from_object, ["revision_ttl"]))
|
|
101
|
+
|
|
102
|
+
if getv(from_object, ["disable_memory_revisions"]) is not None:
|
|
103
|
+
setv(
|
|
104
|
+
parent_object,
|
|
105
|
+
["disableMemoryRevisions"],
|
|
106
|
+
getv(from_object, ["disable_memory_revisions"]),
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
if getv(from_object, ["metadata"]) is not None:
|
|
110
|
+
setv(
|
|
111
|
+
parent_object,
|
|
112
|
+
["metadata"],
|
|
113
|
+
{k: v for k, v in getv(from_object, ["metadata"]).items()},
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
if getv(from_object, ["metadata_merge_strategy"]) is not None:
|
|
117
|
+
setv(
|
|
118
|
+
parent_object,
|
|
119
|
+
["metadataMergeStrategy"],
|
|
120
|
+
getv(from_object, ["metadata_merge_strategy"]),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
if getv(from_object, ["allowed_topics"]) is not None:
|
|
124
|
+
setv(
|
|
125
|
+
parent_object,
|
|
126
|
+
["allowedTopics"],
|
|
127
|
+
[item for item in getv(from_object, ["allowed_topics"])],
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
return to_object
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _GenerateMemoriesRequestParameters_to_vertex(
|
|
134
|
+
from_object: Union[dict[str, Any], object],
|
|
135
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
136
|
+
) -> dict[str, Any]:
|
|
137
|
+
to_object: dict[str, Any] = {}
|
|
138
|
+
if getv(from_object, ["name"]) is not None:
|
|
139
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
140
|
+
|
|
141
|
+
if getv(from_object, ["vertex_session_source"]) is not None:
|
|
142
|
+
setv(
|
|
143
|
+
to_object,
|
|
144
|
+
["vertexSessionSource"],
|
|
145
|
+
getv(from_object, ["vertex_session_source"]),
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
if getv(from_object, ["direct_contents_source"]) is not None:
|
|
149
|
+
setv(
|
|
150
|
+
to_object,
|
|
151
|
+
["directContentsSource"],
|
|
152
|
+
getv(from_object, ["direct_contents_source"]),
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
if getv(from_object, ["direct_memories_source"]) is not None:
|
|
156
|
+
setv(
|
|
157
|
+
to_object,
|
|
158
|
+
["directMemoriesSource"],
|
|
159
|
+
getv(from_object, ["direct_memories_source"]),
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
if getv(from_object, ["scope"]) is not None:
|
|
163
|
+
setv(to_object, ["scope"], getv(from_object, ["scope"]))
|
|
164
|
+
|
|
165
|
+
if getv(from_object, ["config"]) is not None:
|
|
166
|
+
_GenerateMemoriesConfig_to_vertex(getv(from_object, ["config"]), to_object)
|
|
167
|
+
|
|
168
|
+
return to_object
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _GetGenerateMemoriesOperationParameters_to_vertex(
|
|
172
|
+
from_object: Union[dict[str, Any], object],
|
|
173
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
174
|
+
) -> dict[str, Any]:
|
|
175
|
+
to_object: dict[str, Any] = {}
|
|
176
|
+
if getv(from_object, ["operation_name"]) is not None:
|
|
177
|
+
setv(
|
|
178
|
+
to_object, ["_url", "operationName"], getv(from_object, ["operation_name"])
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
return to_object
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _GetMemoryOperationParameters_to_vertex(
|
|
185
|
+
from_object: Union[dict[str, Any], object],
|
|
186
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
187
|
+
) -> dict[str, Any]:
|
|
188
|
+
to_object: dict[str, Any] = {}
|
|
189
|
+
if getv(from_object, ["operation_name"]) is not None:
|
|
190
|
+
setv(
|
|
191
|
+
to_object, ["_url", "operationName"], getv(from_object, ["operation_name"])
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
return to_object
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _GetMemoryRequestParameters_to_vertex(
|
|
198
|
+
from_object: Union[dict[str, Any], object],
|
|
199
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
200
|
+
) -> dict[str, Any]:
|
|
201
|
+
to_object: dict[str, Any] = {}
|
|
202
|
+
if getv(from_object, ["name"]) is not None:
|
|
203
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
204
|
+
|
|
205
|
+
return to_object
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def _ListMemoriesConfig_to_vertex(
|
|
209
|
+
from_object: Union[dict[str, Any], object],
|
|
210
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
211
|
+
) -> dict[str, Any]:
|
|
212
|
+
to_object: dict[str, Any] = {}
|
|
213
|
+
|
|
214
|
+
if getv(from_object, ["page_size"]) is not None:
|
|
215
|
+
setv(parent_object, ["_query", "pageSize"], getv(from_object, ["page_size"]))
|
|
216
|
+
|
|
217
|
+
if getv(from_object, ["page_token"]) is not None:
|
|
218
|
+
setv(parent_object, ["_query", "pageToken"], getv(from_object, ["page_token"]))
|
|
219
|
+
|
|
220
|
+
if getv(from_object, ["filter"]) is not None:
|
|
221
|
+
setv(parent_object, ["_query", "filter"], getv(from_object, ["filter"]))
|
|
222
|
+
|
|
223
|
+
if getv(from_object, ["order_by"]) is not None:
|
|
224
|
+
setv(parent_object, ["_query", "orderBy"], getv(from_object, ["order_by"]))
|
|
225
|
+
|
|
226
|
+
return to_object
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _ListMemoriesRequestParameters_to_vertex(
|
|
230
|
+
from_object: Union[dict[str, Any], object],
|
|
231
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
232
|
+
) -> dict[str, Any]:
|
|
233
|
+
to_object: dict[str, Any] = {}
|
|
234
|
+
if getv(from_object, ["name"]) is not None:
|
|
235
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
236
|
+
|
|
237
|
+
if getv(from_object, ["config"]) is not None:
|
|
238
|
+
_ListMemoriesConfig_to_vertex(getv(from_object, ["config"]), to_object)
|
|
239
|
+
|
|
240
|
+
return to_object
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _MemoryConfig_to_vertex(
|
|
244
|
+
from_object: Union[dict[str, Any], object],
|
|
245
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
246
|
+
) -> dict[str, Any]:
|
|
247
|
+
to_object: dict[str, Any] = {}
|
|
248
|
+
|
|
249
|
+
if getv(from_object, ["display_name"]) is not None:
|
|
250
|
+
setv(parent_object, ["displayName"], getv(from_object, ["display_name"]))
|
|
251
|
+
|
|
252
|
+
if getv(from_object, ["description"]) is not None:
|
|
253
|
+
setv(parent_object, ["description"], getv(from_object, ["description"]))
|
|
254
|
+
|
|
255
|
+
if getv(from_object, ["ttl"]) is not None:
|
|
256
|
+
setv(parent_object, ["ttl"], getv(from_object, ["ttl"]))
|
|
257
|
+
|
|
258
|
+
if getv(from_object, ["expire_time"]) is not None:
|
|
259
|
+
setv(parent_object, ["expireTime"], getv(from_object, ["expire_time"]))
|
|
260
|
+
|
|
261
|
+
if getv(from_object, ["revision_expire_time"]) is not None:
|
|
262
|
+
setv(
|
|
263
|
+
parent_object,
|
|
264
|
+
["revisionExpireTime"],
|
|
265
|
+
getv(from_object, ["revision_expire_time"]),
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
if getv(from_object, ["revision_ttl"]) is not None:
|
|
269
|
+
setv(parent_object, ["revisionTtl"], getv(from_object, ["revision_ttl"]))
|
|
270
|
+
|
|
271
|
+
if getv(from_object, ["disable_memory_revisions"]) is not None:
|
|
272
|
+
setv(
|
|
273
|
+
parent_object,
|
|
274
|
+
["disableMemoryRevisions"],
|
|
275
|
+
getv(from_object, ["disable_memory_revisions"]),
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
if getv(from_object, ["topics"]) is not None:
|
|
279
|
+
setv(
|
|
280
|
+
parent_object, ["topics"], [item for item in getv(from_object, ["topics"])]
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
if getv(from_object, ["metadata"]) is not None:
|
|
284
|
+
setv(
|
|
285
|
+
parent_object,
|
|
286
|
+
["metadata"],
|
|
287
|
+
{k: v for k, v in getv(from_object, ["metadata"]).items()},
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
if getv(from_object, ["memory_id"]) is not None:
|
|
291
|
+
setv(parent_object, ["_query", "memoryId"], getv(from_object, ["memory_id"]))
|
|
292
|
+
|
|
293
|
+
return to_object
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def _PurgeMemoriesRequestParameters_to_vertex(
|
|
297
|
+
from_object: Union[dict[str, Any], object],
|
|
298
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
299
|
+
) -> dict[str, Any]:
|
|
300
|
+
to_object: dict[str, Any] = {}
|
|
301
|
+
if getv(from_object, ["name"]) is not None:
|
|
302
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
303
|
+
|
|
304
|
+
if getv(from_object, ["filter"]) is not None:
|
|
305
|
+
setv(to_object, ["filter"], getv(from_object, ["filter"]))
|
|
306
|
+
|
|
307
|
+
if getv(from_object, ["filter_groups"]) is not None:
|
|
308
|
+
setv(
|
|
309
|
+
to_object,
|
|
310
|
+
["filterGroups"],
|
|
311
|
+
[item for item in getv(from_object, ["filter_groups"])],
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
if getv(from_object, ["force"]) is not None:
|
|
315
|
+
setv(to_object, ["force"], getv(from_object, ["force"]))
|
|
316
|
+
|
|
317
|
+
return to_object
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def _RetrieveMemoriesConfig_to_vertex(
|
|
321
|
+
from_object: Union[dict[str, Any], object],
|
|
322
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
323
|
+
) -> dict[str, Any]:
|
|
324
|
+
to_object: dict[str, Any] = {}
|
|
325
|
+
|
|
326
|
+
if getv(from_object, ["filter"]) is not None:
|
|
327
|
+
setv(parent_object, ["filter"], getv(from_object, ["filter"]))
|
|
328
|
+
|
|
329
|
+
if getv(from_object, ["filter_groups"]) is not None:
|
|
330
|
+
setv(
|
|
331
|
+
parent_object,
|
|
332
|
+
["filterGroups"],
|
|
333
|
+
[item for item in getv(from_object, ["filter_groups"])],
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
if getv(from_object, ["memory_types"]) is not None:
|
|
337
|
+
setv(parent_object, ["memoryTypes"], getv(from_object, ["memory_types"]))
|
|
338
|
+
|
|
339
|
+
return to_object
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def _RetrieveMemoriesRequestParameters_to_vertex(
|
|
343
|
+
from_object: Union[dict[str, Any], object],
|
|
344
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
345
|
+
) -> dict[str, Any]:
|
|
346
|
+
to_object: dict[str, Any] = {}
|
|
347
|
+
if getv(from_object, ["name"]) is not None:
|
|
348
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
349
|
+
|
|
350
|
+
if getv(from_object, ["scope"]) is not None:
|
|
351
|
+
setv(to_object, ["scope"], getv(from_object, ["scope"]))
|
|
352
|
+
|
|
353
|
+
if getv(from_object, ["similarity_search_params"]) is not None:
|
|
354
|
+
setv(
|
|
355
|
+
to_object,
|
|
356
|
+
["similaritySearchParams"],
|
|
357
|
+
getv(from_object, ["similarity_search_params"]),
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
if getv(from_object, ["simple_retrieval_params"]) is not None:
|
|
361
|
+
setv(
|
|
362
|
+
to_object,
|
|
363
|
+
["simpleRetrievalParams"],
|
|
364
|
+
getv(from_object, ["simple_retrieval_params"]),
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
if getv(from_object, ["config"]) is not None:
|
|
368
|
+
_RetrieveMemoriesConfig_to_vertex(getv(from_object, ["config"]), to_object)
|
|
369
|
+
|
|
370
|
+
return to_object
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def _RetrieveMemoryProfilesRequestParameters_to_vertex(
|
|
374
|
+
from_object: Union[dict[str, Any], object],
|
|
375
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
376
|
+
) -> dict[str, Any]:
|
|
377
|
+
to_object: dict[str, Any] = {}
|
|
378
|
+
if getv(from_object, ["name"]) is not None:
|
|
379
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
380
|
+
|
|
381
|
+
if getv(from_object, ["scope"]) is not None:
|
|
382
|
+
setv(to_object, ["scope"], getv(from_object, ["scope"]))
|
|
383
|
+
|
|
384
|
+
return to_object
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def _RollbackMemoryRequestParameters_to_vertex(
|
|
388
|
+
from_object: Union[dict[str, Any], object],
|
|
389
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
390
|
+
) -> dict[str, Any]:
|
|
391
|
+
to_object: dict[str, Any] = {}
|
|
392
|
+
if getv(from_object, ["name"]) is not None:
|
|
393
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
394
|
+
|
|
395
|
+
if getv(from_object, ["target_revision_id"]) is not None:
|
|
396
|
+
setv(to_object, ["targetRevisionId"], getv(from_object, ["target_revision_id"]))
|
|
397
|
+
|
|
398
|
+
return to_object
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def _UpdateMemoryConfig_to_vertex(
|
|
402
|
+
from_object: Union[dict[str, Any], object],
|
|
403
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
404
|
+
) -> dict[str, Any]:
|
|
405
|
+
to_object: dict[str, Any] = {}
|
|
406
|
+
|
|
407
|
+
if getv(from_object, ["display_name"]) is not None:
|
|
408
|
+
setv(parent_object, ["displayName"], getv(from_object, ["display_name"]))
|
|
409
|
+
|
|
410
|
+
if getv(from_object, ["description"]) is not None:
|
|
411
|
+
setv(parent_object, ["description"], getv(from_object, ["description"]))
|
|
412
|
+
|
|
413
|
+
if getv(from_object, ["ttl"]) is not None:
|
|
414
|
+
setv(parent_object, ["ttl"], getv(from_object, ["ttl"]))
|
|
415
|
+
|
|
416
|
+
if getv(from_object, ["expire_time"]) is not None:
|
|
417
|
+
setv(parent_object, ["expireTime"], getv(from_object, ["expire_time"]))
|
|
418
|
+
|
|
419
|
+
if getv(from_object, ["revision_expire_time"]) is not None:
|
|
420
|
+
setv(
|
|
421
|
+
parent_object,
|
|
422
|
+
["revisionExpireTime"],
|
|
423
|
+
getv(from_object, ["revision_expire_time"]),
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
if getv(from_object, ["revision_ttl"]) is not None:
|
|
427
|
+
setv(parent_object, ["revisionTtl"], getv(from_object, ["revision_ttl"]))
|
|
428
|
+
|
|
429
|
+
if getv(from_object, ["disable_memory_revisions"]) is not None:
|
|
430
|
+
setv(
|
|
431
|
+
parent_object,
|
|
432
|
+
["disableMemoryRevisions"],
|
|
433
|
+
getv(from_object, ["disable_memory_revisions"]),
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
if getv(from_object, ["topics"]) is not None:
|
|
437
|
+
setv(
|
|
438
|
+
parent_object, ["topics"], [item for item in getv(from_object, ["topics"])]
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
if getv(from_object, ["metadata"]) is not None:
|
|
442
|
+
setv(
|
|
443
|
+
parent_object,
|
|
444
|
+
["metadata"],
|
|
445
|
+
{k: v for k, v in getv(from_object, ["metadata"]).items()},
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
if getv(from_object, ["memory_id"]) is not None:
|
|
449
|
+
setv(parent_object, ["_query", "memoryId"], getv(from_object, ["memory_id"]))
|
|
450
|
+
|
|
451
|
+
if getv(from_object, ["update_mask"]) is not None:
|
|
452
|
+
setv(
|
|
453
|
+
parent_object, ["_query", "updateMask"], getv(from_object, ["update_mask"])
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
return to_object
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def _UpdateMemoryRequestParameters_to_vertex(
|
|
460
|
+
from_object: Union[dict[str, Any], object],
|
|
461
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
462
|
+
) -> dict[str, Any]:
|
|
463
|
+
to_object: dict[str, Any] = {}
|
|
464
|
+
if getv(from_object, ["name"]) is not None:
|
|
465
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
466
|
+
|
|
467
|
+
if getv(from_object, ["fact"]) is not None:
|
|
468
|
+
setv(to_object, ["fact"], getv(from_object, ["fact"]))
|
|
469
|
+
|
|
470
|
+
if getv(from_object, ["scope"]) is not None:
|
|
471
|
+
setv(to_object, ["scope"], getv(from_object, ["scope"]))
|
|
472
|
+
|
|
473
|
+
if getv(from_object, ["config"]) is not None:
|
|
474
|
+
_UpdateMemoryConfig_to_vertex(getv(from_object, ["config"]), to_object)
|
|
475
|
+
|
|
476
|
+
return to_object
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
class Memories(_api_module.BaseModule):
|
|
480
|
+
|
|
481
|
+
def _create(
|
|
482
|
+
self,
|
|
483
|
+
*,
|
|
484
|
+
name: str,
|
|
485
|
+
fact: str,
|
|
486
|
+
scope: dict[str, str],
|
|
487
|
+
config: Optional[types.MemoryConfigOrDict] = None,
|
|
488
|
+
) -> types.MemoryOperation:
|
|
489
|
+
"""
|
|
490
|
+
Creates a new memory in the Memory Bank.
|
|
491
|
+
"""
|
|
492
|
+
|
|
493
|
+
parameter_model = types._CreateMemoryRequestParameters(
|
|
494
|
+
name=name,
|
|
495
|
+
fact=fact,
|
|
496
|
+
scope=scope,
|
|
497
|
+
config=config,
|
|
498
|
+
)
|
|
499
|
+
|
|
500
|
+
request_url_dict: Optional[dict[str, str]]
|
|
501
|
+
if not self._api_client.vertexai:
|
|
502
|
+
raise ValueError(
|
|
503
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
504
|
+
)
|
|
505
|
+
else:
|
|
506
|
+
request_dict = _CreateMemoryRequestParameters_to_vertex(parameter_model)
|
|
507
|
+
request_url_dict = request_dict.get("_url")
|
|
508
|
+
if request_url_dict:
|
|
509
|
+
path = "{name}/memories".format_map(request_url_dict)
|
|
510
|
+
else:
|
|
511
|
+
path = "{name}/memories"
|
|
512
|
+
|
|
513
|
+
query_params = request_dict.get("_query")
|
|
514
|
+
if query_params:
|
|
515
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
516
|
+
# TODO: remove the hack that pops config.
|
|
517
|
+
request_dict.pop("config", None)
|
|
518
|
+
|
|
519
|
+
http_options: Optional[types.HttpOptions] = None
|
|
520
|
+
if (
|
|
521
|
+
parameter_model.config is not None
|
|
522
|
+
and parameter_model.config.http_options is not None
|
|
523
|
+
):
|
|
524
|
+
http_options = parameter_model.config.http_options
|
|
525
|
+
|
|
526
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
527
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
528
|
+
|
|
529
|
+
response = self._api_client.request("post", path, request_dict, http_options)
|
|
530
|
+
|
|
531
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
532
|
+
|
|
533
|
+
return_value = types.MemoryOperation._from_response(
|
|
534
|
+
response=response_dict,
|
|
535
|
+
kwargs=(
|
|
536
|
+
{
|
|
537
|
+
"config": {
|
|
538
|
+
"response_schema": getattr(
|
|
539
|
+
parameter_model.config, "response_schema", None
|
|
540
|
+
),
|
|
541
|
+
"response_json_schema": getattr(
|
|
542
|
+
parameter_model.config, "response_json_schema", None
|
|
543
|
+
),
|
|
544
|
+
"include_all_fields": getattr(
|
|
545
|
+
parameter_model.config, "include_all_fields", None
|
|
546
|
+
),
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if getattr(parameter_model, "config", None)
|
|
550
|
+
else {}
|
|
551
|
+
),
|
|
552
|
+
)
|
|
553
|
+
|
|
554
|
+
self._api_client._verify_response(return_value)
|
|
555
|
+
return return_value
|
|
556
|
+
|
|
557
|
+
def delete(
|
|
558
|
+
self, *, name: str, config: Optional[types.DeleteMemoryConfigOrDict] = None
|
|
559
|
+
) -> types.DeleteMemoryOperation:
|
|
560
|
+
"""
|
|
561
|
+
Delete a memory.
|
|
562
|
+
|
|
563
|
+
Args:
|
|
564
|
+
name (str):
|
|
565
|
+
Required. The name of the memory to delete. Format:
|
|
566
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/memories/{memory}`.
|
|
567
|
+
config (DeleteRuntimeMemoryConfig):
|
|
568
|
+
Optional. Additional configurations for deleting the Agent Runtime.
|
|
569
|
+
|
|
570
|
+
"""
|
|
571
|
+
|
|
572
|
+
parameter_model = types._DeleteMemoryRequestParameters(
|
|
573
|
+
name=name,
|
|
574
|
+
config=config,
|
|
575
|
+
)
|
|
576
|
+
|
|
577
|
+
request_url_dict: Optional[dict[str, str]]
|
|
578
|
+
if not self._api_client.vertexai:
|
|
579
|
+
raise ValueError(
|
|
580
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
581
|
+
)
|
|
582
|
+
else:
|
|
583
|
+
request_dict = _DeleteMemoryRequestParameters_to_vertex(parameter_model)
|
|
584
|
+
request_url_dict = request_dict.get("_url")
|
|
585
|
+
if request_url_dict:
|
|
586
|
+
path = "{name}".format_map(request_url_dict)
|
|
587
|
+
else:
|
|
588
|
+
path = "{name}"
|
|
589
|
+
|
|
590
|
+
query_params = request_dict.get("_query")
|
|
591
|
+
if query_params:
|
|
592
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
593
|
+
# TODO: remove the hack that pops config.
|
|
594
|
+
request_dict.pop("config", None)
|
|
595
|
+
|
|
596
|
+
http_options: Optional[types.HttpOptions] = None
|
|
597
|
+
if (
|
|
598
|
+
parameter_model.config is not None
|
|
599
|
+
and parameter_model.config.http_options is not None
|
|
600
|
+
):
|
|
601
|
+
http_options = parameter_model.config.http_options
|
|
602
|
+
|
|
603
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
604
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
605
|
+
|
|
606
|
+
response = self._api_client.request("delete", path, request_dict, http_options)
|
|
607
|
+
|
|
608
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
609
|
+
|
|
610
|
+
return_value = types.DeleteMemoryOperation._from_response(
|
|
611
|
+
response=response_dict,
|
|
612
|
+
kwargs=(
|
|
613
|
+
{
|
|
614
|
+
"config": {
|
|
615
|
+
"response_schema": getattr(
|
|
616
|
+
parameter_model.config, "response_schema", None
|
|
617
|
+
),
|
|
618
|
+
"response_json_schema": getattr(
|
|
619
|
+
parameter_model.config, "response_json_schema", None
|
|
620
|
+
),
|
|
621
|
+
"include_all_fields": getattr(
|
|
622
|
+
parameter_model.config, "include_all_fields", None
|
|
623
|
+
),
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if getattr(parameter_model, "config", None)
|
|
627
|
+
else {}
|
|
628
|
+
),
|
|
629
|
+
)
|
|
630
|
+
|
|
631
|
+
self._api_client._verify_response(return_value)
|
|
632
|
+
return return_value
|
|
633
|
+
|
|
634
|
+
def _generate(
|
|
635
|
+
self,
|
|
636
|
+
*,
|
|
637
|
+
name: str,
|
|
638
|
+
vertex_session_source: Optional[
|
|
639
|
+
types.GenerateMemoriesRequestVertexSessionSourceOrDict
|
|
640
|
+
] = None,
|
|
641
|
+
direct_contents_source: Optional[
|
|
642
|
+
types.GenerateMemoriesRequestDirectContentsSourceOrDict
|
|
643
|
+
] = None,
|
|
644
|
+
direct_memories_source: Optional[
|
|
645
|
+
types.GenerateMemoriesRequestDirectMemoriesSourceOrDict
|
|
646
|
+
] = None,
|
|
647
|
+
scope: Optional[dict[str, str]] = None,
|
|
648
|
+
config: Optional[types.GenerateMemoriesConfigOrDict] = None,
|
|
649
|
+
) -> types.GenerateMemoriesOperation:
|
|
650
|
+
"""
|
|
651
|
+
Generates memories for a Memory Bank.
|
|
652
|
+
"""
|
|
653
|
+
|
|
654
|
+
parameter_model = types._GenerateMemoriesRequestParameters(
|
|
655
|
+
name=name,
|
|
656
|
+
vertex_session_source=vertex_session_source,
|
|
657
|
+
direct_contents_source=direct_contents_source,
|
|
658
|
+
direct_memories_source=direct_memories_source,
|
|
659
|
+
scope=scope,
|
|
660
|
+
config=config,
|
|
661
|
+
)
|
|
662
|
+
|
|
663
|
+
request_url_dict: Optional[dict[str, str]]
|
|
664
|
+
if not self._api_client.vertexai:
|
|
665
|
+
raise ValueError(
|
|
666
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
667
|
+
)
|
|
668
|
+
else:
|
|
669
|
+
request_dict = _GenerateMemoriesRequestParameters_to_vertex(parameter_model)
|
|
670
|
+
request_url_dict = request_dict.get("_url")
|
|
671
|
+
if request_url_dict:
|
|
672
|
+
path = "{name}/memories:generate".format_map(request_url_dict)
|
|
673
|
+
else:
|
|
674
|
+
path = "{name}/memories:generate"
|
|
675
|
+
|
|
676
|
+
query_params = request_dict.get("_query")
|
|
677
|
+
if query_params:
|
|
678
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
679
|
+
# TODO: remove the hack that pops config.
|
|
680
|
+
request_dict.pop("config", None)
|
|
681
|
+
|
|
682
|
+
http_options: Optional[types.HttpOptions] = None
|
|
683
|
+
if (
|
|
684
|
+
parameter_model.config is not None
|
|
685
|
+
and parameter_model.config.http_options is not None
|
|
686
|
+
):
|
|
687
|
+
http_options = parameter_model.config.http_options
|
|
688
|
+
|
|
689
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
690
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
691
|
+
|
|
692
|
+
response = self._api_client.request("post", path, request_dict, http_options)
|
|
693
|
+
|
|
694
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
695
|
+
|
|
696
|
+
return_value = types.GenerateMemoriesOperation._from_response(
|
|
697
|
+
response=response_dict,
|
|
698
|
+
kwargs=(
|
|
699
|
+
{
|
|
700
|
+
"config": {
|
|
701
|
+
"response_schema": getattr(
|
|
702
|
+
parameter_model.config, "response_schema", None
|
|
703
|
+
),
|
|
704
|
+
"response_json_schema": getattr(
|
|
705
|
+
parameter_model.config, "response_json_schema", None
|
|
706
|
+
),
|
|
707
|
+
"include_all_fields": getattr(
|
|
708
|
+
parameter_model.config, "include_all_fields", None
|
|
709
|
+
),
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
if getattr(parameter_model, "config", None)
|
|
713
|
+
else {}
|
|
714
|
+
),
|
|
715
|
+
)
|
|
716
|
+
|
|
717
|
+
self._api_client._verify_response(return_value)
|
|
718
|
+
return return_value
|
|
719
|
+
|
|
720
|
+
def get(
|
|
721
|
+
self, *, name: str, config: Optional[types.GetMemoryConfigOrDict] = None
|
|
722
|
+
) -> types.Memory:
|
|
723
|
+
"""
|
|
724
|
+
Gets a memory.
|
|
725
|
+
|
|
726
|
+
Args:
|
|
727
|
+
name (str): Required. A fully-qualified resource name or ID such as
|
|
728
|
+
"projects/123/locations/us-central1/reasoningEngines/456/memories/789"
|
|
729
|
+
or a shortened name such as "reasoningEngines/456/memories/789".
|
|
730
|
+
|
|
731
|
+
"""
|
|
732
|
+
|
|
733
|
+
parameter_model = types._GetMemoryRequestParameters(
|
|
734
|
+
name=name,
|
|
735
|
+
config=config,
|
|
736
|
+
)
|
|
737
|
+
|
|
738
|
+
request_url_dict: Optional[dict[str, str]]
|
|
739
|
+
if not self._api_client.vertexai:
|
|
740
|
+
raise ValueError(
|
|
741
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
742
|
+
)
|
|
743
|
+
else:
|
|
744
|
+
request_dict = _GetMemoryRequestParameters_to_vertex(parameter_model)
|
|
745
|
+
request_url_dict = request_dict.get("_url")
|
|
746
|
+
if request_url_dict:
|
|
747
|
+
path = "{name}".format_map(request_url_dict)
|
|
748
|
+
else:
|
|
749
|
+
path = "{name}"
|
|
750
|
+
|
|
751
|
+
query_params = request_dict.get("_query")
|
|
752
|
+
if query_params:
|
|
753
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
754
|
+
# TODO: remove the hack that pops config.
|
|
755
|
+
request_dict.pop("config", None)
|
|
756
|
+
|
|
757
|
+
http_options: Optional[types.HttpOptions] = None
|
|
758
|
+
if (
|
|
759
|
+
parameter_model.config is not None
|
|
760
|
+
and parameter_model.config.http_options is not None
|
|
761
|
+
):
|
|
762
|
+
http_options = parameter_model.config.http_options
|
|
763
|
+
|
|
764
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
765
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
766
|
+
|
|
767
|
+
response = self._api_client.request("get", path, request_dict, http_options)
|
|
768
|
+
|
|
769
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
770
|
+
|
|
771
|
+
return_value = types.Memory._from_response(
|
|
772
|
+
response=response_dict,
|
|
773
|
+
kwargs=(
|
|
774
|
+
{
|
|
775
|
+
"config": {
|
|
776
|
+
"response_schema": getattr(
|
|
777
|
+
parameter_model.config, "response_schema", None
|
|
778
|
+
),
|
|
779
|
+
"response_json_schema": getattr(
|
|
780
|
+
parameter_model.config, "response_json_schema", None
|
|
781
|
+
),
|
|
782
|
+
"include_all_fields": getattr(
|
|
783
|
+
parameter_model.config, "include_all_fields", None
|
|
784
|
+
),
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
if getattr(parameter_model, "config", None)
|
|
788
|
+
else {}
|
|
789
|
+
),
|
|
790
|
+
)
|
|
791
|
+
|
|
792
|
+
self._api_client._verify_response(return_value)
|
|
793
|
+
return return_value
|
|
794
|
+
|
|
795
|
+
def _list(
|
|
796
|
+
self, *, name: str, config: Optional[types.ListMemoriesConfigOrDict] = None
|
|
797
|
+
) -> types.ListMemoriesResponse:
|
|
798
|
+
"""
|
|
799
|
+
Lists memories.
|
|
800
|
+
"""
|
|
801
|
+
|
|
802
|
+
parameter_model = types._ListMemoriesRequestParameters(
|
|
803
|
+
name=name,
|
|
804
|
+
config=config,
|
|
805
|
+
)
|
|
806
|
+
|
|
807
|
+
request_url_dict: Optional[dict[str, str]]
|
|
808
|
+
if not self._api_client.vertexai:
|
|
809
|
+
raise ValueError(
|
|
810
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
811
|
+
)
|
|
812
|
+
else:
|
|
813
|
+
request_dict = _ListMemoriesRequestParameters_to_vertex(parameter_model)
|
|
814
|
+
request_url_dict = request_dict.get("_url")
|
|
815
|
+
if request_url_dict:
|
|
816
|
+
path = "{name}/memories".format_map(request_url_dict)
|
|
817
|
+
else:
|
|
818
|
+
path = "{name}/memories"
|
|
819
|
+
|
|
820
|
+
query_params = request_dict.get("_query")
|
|
821
|
+
if query_params:
|
|
822
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
823
|
+
# TODO: remove the hack that pops config.
|
|
824
|
+
request_dict.pop("config", None)
|
|
825
|
+
|
|
826
|
+
http_options: Optional[types.HttpOptions] = None
|
|
827
|
+
if (
|
|
828
|
+
parameter_model.config is not None
|
|
829
|
+
and parameter_model.config.http_options is not None
|
|
830
|
+
):
|
|
831
|
+
http_options = parameter_model.config.http_options
|
|
832
|
+
|
|
833
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
834
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
835
|
+
|
|
836
|
+
response = self._api_client.request("get", path, request_dict, http_options)
|
|
837
|
+
|
|
838
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
839
|
+
|
|
840
|
+
return_value = types.ListMemoriesResponse._from_response(
|
|
841
|
+
response=response_dict,
|
|
842
|
+
kwargs=(
|
|
843
|
+
{
|
|
844
|
+
"config": {
|
|
845
|
+
"response_schema": getattr(
|
|
846
|
+
parameter_model.config, "response_schema", None
|
|
847
|
+
),
|
|
848
|
+
"response_json_schema": getattr(
|
|
849
|
+
parameter_model.config, "response_json_schema", None
|
|
850
|
+
),
|
|
851
|
+
"include_all_fields": getattr(
|
|
852
|
+
parameter_model.config, "include_all_fields", None
|
|
853
|
+
),
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
if getattr(parameter_model, "config", None)
|
|
857
|
+
else {}
|
|
858
|
+
),
|
|
859
|
+
)
|
|
860
|
+
|
|
861
|
+
self._api_client._verify_response(return_value)
|
|
862
|
+
return return_value
|
|
863
|
+
|
|
864
|
+
def _get_memory_operation(
|
|
865
|
+
self,
|
|
866
|
+
*,
|
|
867
|
+
operation_name: str,
|
|
868
|
+
config: Optional[types.GetMemoryBankOperationConfigOrDict] = None,
|
|
869
|
+
) -> types.MemoryOperation:
|
|
870
|
+
parameter_model = types._GetMemoryOperationParameters(
|
|
871
|
+
operation_name=operation_name,
|
|
872
|
+
config=config,
|
|
873
|
+
)
|
|
874
|
+
|
|
875
|
+
request_url_dict: Optional[dict[str, str]]
|
|
876
|
+
if not self._api_client.vertexai:
|
|
877
|
+
raise ValueError(
|
|
878
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
879
|
+
)
|
|
880
|
+
else:
|
|
881
|
+
request_dict = _GetMemoryOperationParameters_to_vertex(parameter_model)
|
|
882
|
+
request_url_dict = request_dict.get("_url")
|
|
883
|
+
if request_url_dict:
|
|
884
|
+
path = "{operationName}".format_map(request_url_dict)
|
|
885
|
+
else:
|
|
886
|
+
path = "{operationName}"
|
|
887
|
+
|
|
888
|
+
query_params = request_dict.get("_query")
|
|
889
|
+
if query_params:
|
|
890
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
891
|
+
# TODO: remove the hack that pops config.
|
|
892
|
+
request_dict.pop("config", None)
|
|
893
|
+
|
|
894
|
+
http_options: Optional[types.HttpOptions] = None
|
|
895
|
+
if (
|
|
896
|
+
parameter_model.config is not None
|
|
897
|
+
and parameter_model.config.http_options is not None
|
|
898
|
+
):
|
|
899
|
+
http_options = parameter_model.config.http_options
|
|
900
|
+
|
|
901
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
902
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
903
|
+
|
|
904
|
+
response = self._api_client.request("get", path, request_dict, http_options)
|
|
905
|
+
|
|
906
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
907
|
+
|
|
908
|
+
return_value = types.MemoryOperation._from_response(
|
|
909
|
+
response=response_dict,
|
|
910
|
+
kwargs=(
|
|
911
|
+
{
|
|
912
|
+
"config": {
|
|
913
|
+
"response_schema": getattr(
|
|
914
|
+
parameter_model.config, "response_schema", None
|
|
915
|
+
),
|
|
916
|
+
"response_json_schema": getattr(
|
|
917
|
+
parameter_model.config, "response_json_schema", None
|
|
918
|
+
),
|
|
919
|
+
"include_all_fields": getattr(
|
|
920
|
+
parameter_model.config, "include_all_fields", None
|
|
921
|
+
),
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
if getattr(parameter_model, "config", None)
|
|
925
|
+
else {}
|
|
926
|
+
),
|
|
927
|
+
)
|
|
928
|
+
|
|
929
|
+
self._api_client._verify_response(return_value)
|
|
930
|
+
return return_value
|
|
931
|
+
|
|
932
|
+
def _get_generate_memories_operation(
|
|
933
|
+
self,
|
|
934
|
+
*,
|
|
935
|
+
operation_name: str,
|
|
936
|
+
config: Optional[types.GetMemoryBankOperationConfigOrDict] = None,
|
|
937
|
+
) -> types.GenerateMemoriesOperation:
|
|
938
|
+
parameter_model = types._GetGenerateMemoriesOperationParameters(
|
|
939
|
+
operation_name=operation_name,
|
|
940
|
+
config=config,
|
|
941
|
+
)
|
|
942
|
+
|
|
943
|
+
request_url_dict: Optional[dict[str, str]]
|
|
944
|
+
if not self._api_client.vertexai:
|
|
945
|
+
raise ValueError(
|
|
946
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
947
|
+
)
|
|
948
|
+
else:
|
|
949
|
+
request_dict = _GetGenerateMemoriesOperationParameters_to_vertex(
|
|
950
|
+
parameter_model
|
|
951
|
+
)
|
|
952
|
+
request_url_dict = request_dict.get("_url")
|
|
953
|
+
if request_url_dict:
|
|
954
|
+
path = "{operationName}".format_map(request_url_dict)
|
|
955
|
+
else:
|
|
956
|
+
path = "{operationName}"
|
|
957
|
+
|
|
958
|
+
query_params = request_dict.get("_query")
|
|
959
|
+
if query_params:
|
|
960
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
961
|
+
# TODO: remove the hack that pops config.
|
|
962
|
+
request_dict.pop("config", None)
|
|
963
|
+
|
|
964
|
+
http_options: Optional[types.HttpOptions] = None
|
|
965
|
+
if (
|
|
966
|
+
parameter_model.config is not None
|
|
967
|
+
and parameter_model.config.http_options is not None
|
|
968
|
+
):
|
|
969
|
+
http_options = parameter_model.config.http_options
|
|
970
|
+
|
|
971
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
972
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
973
|
+
|
|
974
|
+
response = self._api_client.request("get", path, request_dict, http_options)
|
|
975
|
+
|
|
976
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
977
|
+
|
|
978
|
+
return_value = types.GenerateMemoriesOperation._from_response(
|
|
979
|
+
response=response_dict,
|
|
980
|
+
kwargs=(
|
|
981
|
+
{
|
|
982
|
+
"config": {
|
|
983
|
+
"response_schema": getattr(
|
|
984
|
+
parameter_model.config, "response_schema", None
|
|
985
|
+
),
|
|
986
|
+
"response_json_schema": getattr(
|
|
987
|
+
parameter_model.config, "response_json_schema", None
|
|
988
|
+
),
|
|
989
|
+
"include_all_fields": getattr(
|
|
990
|
+
parameter_model.config, "include_all_fields", None
|
|
991
|
+
),
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
if getattr(parameter_model, "config", None)
|
|
995
|
+
else {}
|
|
996
|
+
),
|
|
997
|
+
)
|
|
998
|
+
|
|
999
|
+
self._api_client._verify_response(return_value)
|
|
1000
|
+
return return_value
|
|
1001
|
+
|
|
1002
|
+
def _retrieve(
|
|
1003
|
+
self,
|
|
1004
|
+
*,
|
|
1005
|
+
name: str,
|
|
1006
|
+
scope: dict[str, str],
|
|
1007
|
+
similarity_search_params: Optional[
|
|
1008
|
+
types.RetrieveMemoriesRequestSimilaritySearchParamsOrDict
|
|
1009
|
+
] = None,
|
|
1010
|
+
simple_retrieval_params: Optional[
|
|
1011
|
+
types.RetrieveMemoriesRequestSimpleRetrievalParamsOrDict
|
|
1012
|
+
] = None,
|
|
1013
|
+
config: Optional[types.RetrieveMemoriesConfigOrDict] = None,
|
|
1014
|
+
) -> types.RetrieveMemoriesResponse:
|
|
1015
|
+
"""
|
|
1016
|
+
Retrieves memories from a Memory Bank.
|
|
1017
|
+
"""
|
|
1018
|
+
|
|
1019
|
+
parameter_model = types._RetrieveMemoriesRequestParameters(
|
|
1020
|
+
name=name,
|
|
1021
|
+
scope=scope,
|
|
1022
|
+
similarity_search_params=similarity_search_params,
|
|
1023
|
+
simple_retrieval_params=simple_retrieval_params,
|
|
1024
|
+
config=config,
|
|
1025
|
+
)
|
|
1026
|
+
|
|
1027
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1028
|
+
if not self._api_client.vertexai:
|
|
1029
|
+
raise ValueError(
|
|
1030
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1031
|
+
)
|
|
1032
|
+
else:
|
|
1033
|
+
request_dict = _RetrieveMemoriesRequestParameters_to_vertex(parameter_model)
|
|
1034
|
+
request_url_dict = request_dict.get("_url")
|
|
1035
|
+
if request_url_dict:
|
|
1036
|
+
path = "{name}/memories:retrieve".format_map(request_url_dict)
|
|
1037
|
+
else:
|
|
1038
|
+
path = "{name}/memories:retrieve"
|
|
1039
|
+
|
|
1040
|
+
query_params = request_dict.get("_query")
|
|
1041
|
+
if query_params:
|
|
1042
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1043
|
+
# TODO: remove the hack that pops config.
|
|
1044
|
+
request_dict.pop("config", None)
|
|
1045
|
+
|
|
1046
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1047
|
+
if (
|
|
1048
|
+
parameter_model.config is not None
|
|
1049
|
+
and parameter_model.config.http_options is not None
|
|
1050
|
+
):
|
|
1051
|
+
http_options = parameter_model.config.http_options
|
|
1052
|
+
|
|
1053
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1054
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1055
|
+
|
|
1056
|
+
response = self._api_client.request("post", path, request_dict, http_options)
|
|
1057
|
+
|
|
1058
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1059
|
+
|
|
1060
|
+
return_value = types.RetrieveMemoriesResponse._from_response(
|
|
1061
|
+
response=response_dict,
|
|
1062
|
+
kwargs=(
|
|
1063
|
+
{
|
|
1064
|
+
"config": {
|
|
1065
|
+
"response_schema": getattr(
|
|
1066
|
+
parameter_model.config, "response_schema", None
|
|
1067
|
+
),
|
|
1068
|
+
"response_json_schema": getattr(
|
|
1069
|
+
parameter_model.config, "response_json_schema", None
|
|
1070
|
+
),
|
|
1071
|
+
"include_all_fields": getattr(
|
|
1072
|
+
parameter_model.config, "include_all_fields", None
|
|
1073
|
+
),
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
if getattr(parameter_model, "config", None)
|
|
1077
|
+
else {}
|
|
1078
|
+
),
|
|
1079
|
+
)
|
|
1080
|
+
|
|
1081
|
+
self._api_client._verify_response(return_value)
|
|
1082
|
+
return return_value
|
|
1083
|
+
|
|
1084
|
+
def retrieve_profiles(
|
|
1085
|
+
self,
|
|
1086
|
+
*,
|
|
1087
|
+
name: str,
|
|
1088
|
+
scope: dict[str, str],
|
|
1089
|
+
config: Optional[types.RetrieveMemoryProfilesConfigOrDict] = None,
|
|
1090
|
+
) -> types.RetrieveProfilesResponse:
|
|
1091
|
+
"""
|
|
1092
|
+
Retrieves memory profiles for a Memory Bank.
|
|
1093
|
+
|
|
1094
|
+
For example, you can use the following code to retrieve all memory profiles
|
|
1095
|
+
for scope `{'user_id': '123'}`:
|
|
1096
|
+
|
|
1097
|
+
```python
|
|
1098
|
+
result = client.memory_banks.memories.retrieve_profiles(
|
|
1099
|
+
name="projects/123/locations/us-central1/reasoningEngines/456",
|
|
1100
|
+
scope={"user_id": "123"}
|
|
1101
|
+
)
|
|
1102
|
+
|
|
1103
|
+
for profile in result.profiles.values():
|
|
1104
|
+
# Each profile is a dictionary corresponding to the relevant schema.
|
|
1105
|
+
print(profile.profile)
|
|
1106
|
+
```
|
|
1107
|
+
|
|
1108
|
+
Args:
|
|
1109
|
+
name (str): Required. A fully-qualified resource name or ID such as
|
|
1110
|
+
"projects/123/locations/us-central1/reasoningEngines/456".
|
|
1111
|
+
scope (dict[str, str]): Required. The scope of the memories to retrieve.
|
|
1112
|
+
A memory must have exactly the same scope as the scope provided here
|
|
1113
|
+
to be retrieved (i.e. same keys and values). Order does not matter,
|
|
1114
|
+
but it is case-sensitive.
|
|
1115
|
+
|
|
1116
|
+
Returns:
|
|
1117
|
+
RetrieveProfilesResponse: The retrieved memory profiles.
|
|
1118
|
+
|
|
1119
|
+
"""
|
|
1120
|
+
|
|
1121
|
+
parameter_model = types._RetrieveMemoryProfilesRequestParameters(
|
|
1122
|
+
name=name,
|
|
1123
|
+
scope=scope,
|
|
1124
|
+
config=config,
|
|
1125
|
+
)
|
|
1126
|
+
|
|
1127
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1128
|
+
if not self._api_client.vertexai:
|
|
1129
|
+
raise ValueError(
|
|
1130
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1131
|
+
)
|
|
1132
|
+
else:
|
|
1133
|
+
request_dict = _RetrieveMemoryProfilesRequestParameters_to_vertex(
|
|
1134
|
+
parameter_model
|
|
1135
|
+
)
|
|
1136
|
+
request_url_dict = request_dict.get("_url")
|
|
1137
|
+
if request_url_dict:
|
|
1138
|
+
path = "{name}/memories:retrieveProfiles".format_map(request_url_dict)
|
|
1139
|
+
else:
|
|
1140
|
+
path = "{name}/memories:retrieveProfiles"
|
|
1141
|
+
|
|
1142
|
+
query_params = request_dict.get("_query")
|
|
1143
|
+
if query_params:
|
|
1144
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1145
|
+
# TODO: remove the hack that pops config.
|
|
1146
|
+
request_dict.pop("config", None)
|
|
1147
|
+
|
|
1148
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1149
|
+
if (
|
|
1150
|
+
parameter_model.config is not None
|
|
1151
|
+
and parameter_model.config.http_options is not None
|
|
1152
|
+
):
|
|
1153
|
+
http_options = parameter_model.config.http_options
|
|
1154
|
+
|
|
1155
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1156
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1157
|
+
|
|
1158
|
+
response = self._api_client.request("post", path, request_dict, http_options)
|
|
1159
|
+
|
|
1160
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1161
|
+
|
|
1162
|
+
return_value = types.RetrieveProfilesResponse._from_response(
|
|
1163
|
+
response=response_dict,
|
|
1164
|
+
kwargs=(
|
|
1165
|
+
{
|
|
1166
|
+
"config": {
|
|
1167
|
+
"response_schema": getattr(
|
|
1168
|
+
parameter_model.config, "response_schema", None
|
|
1169
|
+
),
|
|
1170
|
+
"response_json_schema": getattr(
|
|
1171
|
+
parameter_model.config, "response_json_schema", None
|
|
1172
|
+
),
|
|
1173
|
+
"include_all_fields": getattr(
|
|
1174
|
+
parameter_model.config, "include_all_fields", None
|
|
1175
|
+
),
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
if getattr(parameter_model, "config", None)
|
|
1179
|
+
else {}
|
|
1180
|
+
),
|
|
1181
|
+
)
|
|
1182
|
+
|
|
1183
|
+
self._api_client._verify_response(return_value)
|
|
1184
|
+
return return_value
|
|
1185
|
+
|
|
1186
|
+
def _rollback(
|
|
1187
|
+
self,
|
|
1188
|
+
*,
|
|
1189
|
+
name: str,
|
|
1190
|
+
target_revision_id: str,
|
|
1191
|
+
config: Optional[types.RollbackMemoryConfigOrDict] = None,
|
|
1192
|
+
) -> types.RollbackMemoryOperation:
|
|
1193
|
+
"""
|
|
1194
|
+
Rollback a memory to a previous revision.
|
|
1195
|
+
"""
|
|
1196
|
+
|
|
1197
|
+
parameter_model = types._RollbackMemoryRequestParameters(
|
|
1198
|
+
name=name,
|
|
1199
|
+
target_revision_id=target_revision_id,
|
|
1200
|
+
config=config,
|
|
1201
|
+
)
|
|
1202
|
+
|
|
1203
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1204
|
+
if not self._api_client.vertexai:
|
|
1205
|
+
raise ValueError(
|
|
1206
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1207
|
+
)
|
|
1208
|
+
else:
|
|
1209
|
+
request_dict = _RollbackMemoryRequestParameters_to_vertex(parameter_model)
|
|
1210
|
+
request_url_dict = request_dict.get("_url")
|
|
1211
|
+
if request_url_dict:
|
|
1212
|
+
path = "{name}:rollback".format_map(request_url_dict)
|
|
1213
|
+
else:
|
|
1214
|
+
path = "{name}:rollback"
|
|
1215
|
+
|
|
1216
|
+
query_params = request_dict.get("_query")
|
|
1217
|
+
if query_params:
|
|
1218
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1219
|
+
# TODO: remove the hack that pops config.
|
|
1220
|
+
request_dict.pop("config", None)
|
|
1221
|
+
|
|
1222
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1223
|
+
if (
|
|
1224
|
+
parameter_model.config is not None
|
|
1225
|
+
and parameter_model.config.http_options is not None
|
|
1226
|
+
):
|
|
1227
|
+
http_options = parameter_model.config.http_options
|
|
1228
|
+
|
|
1229
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1230
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1231
|
+
|
|
1232
|
+
response = self._api_client.request("post", path, request_dict, http_options)
|
|
1233
|
+
|
|
1234
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1235
|
+
|
|
1236
|
+
return_value = types.RollbackMemoryOperation._from_response(
|
|
1237
|
+
response=response_dict,
|
|
1238
|
+
kwargs=(
|
|
1239
|
+
{
|
|
1240
|
+
"config": {
|
|
1241
|
+
"response_schema": getattr(
|
|
1242
|
+
parameter_model.config, "response_schema", None
|
|
1243
|
+
),
|
|
1244
|
+
"response_json_schema": getattr(
|
|
1245
|
+
parameter_model.config, "response_json_schema", None
|
|
1246
|
+
),
|
|
1247
|
+
"include_all_fields": getattr(
|
|
1248
|
+
parameter_model.config, "include_all_fields", None
|
|
1249
|
+
),
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
if getattr(parameter_model, "config", None)
|
|
1253
|
+
else {}
|
|
1254
|
+
),
|
|
1255
|
+
)
|
|
1256
|
+
|
|
1257
|
+
self._api_client._verify_response(return_value)
|
|
1258
|
+
return return_value
|
|
1259
|
+
|
|
1260
|
+
def _update(
|
|
1261
|
+
self,
|
|
1262
|
+
*,
|
|
1263
|
+
name: str,
|
|
1264
|
+
fact: Optional[str] = None,
|
|
1265
|
+
scope: Optional[dict[str, str]] = None,
|
|
1266
|
+
config: Optional[types.UpdateMemoryConfigOrDict] = None,
|
|
1267
|
+
) -> types.MemoryOperation:
|
|
1268
|
+
"""
|
|
1269
|
+
Updates a memory.
|
|
1270
|
+
"""
|
|
1271
|
+
|
|
1272
|
+
parameter_model = types._UpdateMemoryRequestParameters(
|
|
1273
|
+
name=name,
|
|
1274
|
+
fact=fact,
|
|
1275
|
+
scope=scope,
|
|
1276
|
+
config=config,
|
|
1277
|
+
)
|
|
1278
|
+
|
|
1279
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1280
|
+
if not self._api_client.vertexai:
|
|
1281
|
+
raise ValueError(
|
|
1282
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1283
|
+
)
|
|
1284
|
+
else:
|
|
1285
|
+
request_dict = _UpdateMemoryRequestParameters_to_vertex(parameter_model)
|
|
1286
|
+
request_url_dict = request_dict.get("_url")
|
|
1287
|
+
if request_url_dict:
|
|
1288
|
+
path = "{name}".format_map(request_url_dict)
|
|
1289
|
+
else:
|
|
1290
|
+
path = "{name}"
|
|
1291
|
+
|
|
1292
|
+
query_params = request_dict.get("_query")
|
|
1293
|
+
if query_params:
|
|
1294
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1295
|
+
# TODO: remove the hack that pops config.
|
|
1296
|
+
request_dict.pop("config", None)
|
|
1297
|
+
|
|
1298
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1299
|
+
if (
|
|
1300
|
+
parameter_model.config is not None
|
|
1301
|
+
and parameter_model.config.http_options is not None
|
|
1302
|
+
):
|
|
1303
|
+
http_options = parameter_model.config.http_options
|
|
1304
|
+
|
|
1305
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1306
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1307
|
+
|
|
1308
|
+
response = self._api_client.request("patch", path, request_dict, http_options)
|
|
1309
|
+
|
|
1310
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1311
|
+
|
|
1312
|
+
return_value = types.MemoryOperation._from_response(
|
|
1313
|
+
response=response_dict,
|
|
1314
|
+
kwargs=(
|
|
1315
|
+
{
|
|
1316
|
+
"config": {
|
|
1317
|
+
"response_schema": getattr(
|
|
1318
|
+
parameter_model.config, "response_schema", None
|
|
1319
|
+
),
|
|
1320
|
+
"response_json_schema": getattr(
|
|
1321
|
+
parameter_model.config, "response_json_schema", None
|
|
1322
|
+
),
|
|
1323
|
+
"include_all_fields": getattr(
|
|
1324
|
+
parameter_model.config, "include_all_fields", None
|
|
1325
|
+
),
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
if getattr(parameter_model, "config", None)
|
|
1329
|
+
else {}
|
|
1330
|
+
),
|
|
1331
|
+
)
|
|
1332
|
+
|
|
1333
|
+
self._api_client._verify_response(return_value)
|
|
1334
|
+
return return_value
|
|
1335
|
+
|
|
1336
|
+
def _purge(
|
|
1337
|
+
self,
|
|
1338
|
+
*,
|
|
1339
|
+
name: str,
|
|
1340
|
+
filter: Optional[str] = None,
|
|
1341
|
+
filter_groups: Optional[
|
|
1342
|
+
builtins.list[types.MemoryConjunctionFilterOrDict]
|
|
1343
|
+
] = None,
|
|
1344
|
+
force: Optional[bool] = None,
|
|
1345
|
+
config: Optional[types.PurgeMemoriesConfigOrDict] = None,
|
|
1346
|
+
) -> types.PurgeMemoriesOperation:
|
|
1347
|
+
"""
|
|
1348
|
+
Purges memories from a Memory Bank.
|
|
1349
|
+
"""
|
|
1350
|
+
|
|
1351
|
+
parameter_model = types._PurgeMemoriesRequestParameters(
|
|
1352
|
+
name=name,
|
|
1353
|
+
filter=filter,
|
|
1354
|
+
filter_groups=filter_groups,
|
|
1355
|
+
force=force,
|
|
1356
|
+
config=config,
|
|
1357
|
+
)
|
|
1358
|
+
|
|
1359
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1360
|
+
if not self._api_client.vertexai:
|
|
1361
|
+
raise ValueError(
|
|
1362
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1363
|
+
)
|
|
1364
|
+
else:
|
|
1365
|
+
request_dict = _PurgeMemoriesRequestParameters_to_vertex(parameter_model)
|
|
1366
|
+
request_url_dict = request_dict.get("_url")
|
|
1367
|
+
if request_url_dict:
|
|
1368
|
+
path = "{name}/memories:purge".format_map(request_url_dict)
|
|
1369
|
+
else:
|
|
1370
|
+
path = "{name}/memories:purge"
|
|
1371
|
+
|
|
1372
|
+
query_params = request_dict.get("_query")
|
|
1373
|
+
if query_params:
|
|
1374
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1375
|
+
# TODO: remove the hack that pops config.
|
|
1376
|
+
request_dict.pop("config", None)
|
|
1377
|
+
|
|
1378
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1379
|
+
if (
|
|
1380
|
+
parameter_model.config is not None
|
|
1381
|
+
and parameter_model.config.http_options is not None
|
|
1382
|
+
):
|
|
1383
|
+
http_options = parameter_model.config.http_options
|
|
1384
|
+
|
|
1385
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1386
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1387
|
+
|
|
1388
|
+
response = self._api_client.request("post", path, request_dict, http_options)
|
|
1389
|
+
|
|
1390
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1391
|
+
|
|
1392
|
+
return_value = types.PurgeMemoriesOperation._from_response(
|
|
1393
|
+
response=response_dict,
|
|
1394
|
+
kwargs=(
|
|
1395
|
+
{
|
|
1396
|
+
"config": {
|
|
1397
|
+
"response_schema": getattr(
|
|
1398
|
+
parameter_model.config, "response_schema", None
|
|
1399
|
+
),
|
|
1400
|
+
"response_json_schema": getattr(
|
|
1401
|
+
parameter_model.config, "response_json_schema", None
|
|
1402
|
+
),
|
|
1403
|
+
"include_all_fields": getattr(
|
|
1404
|
+
parameter_model.config, "include_all_fields", None
|
|
1405
|
+
),
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
if getattr(parameter_model, "config", None)
|
|
1409
|
+
else {}
|
|
1410
|
+
),
|
|
1411
|
+
)
|
|
1412
|
+
|
|
1413
|
+
self._api_client._verify_response(return_value)
|
|
1414
|
+
return return_value
|
|
1415
|
+
|
|
1416
|
+
_revisions = None
|
|
1417
|
+
|
|
1418
|
+
@property
|
|
1419
|
+
def revisions(self) -> "memory_revisions_module.MemoryRevisions":
|
|
1420
|
+
if self._revisions is None:
|
|
1421
|
+
self._revisions = importlib.import_module(".memory_revisions", __package__)
|
|
1422
|
+
return self._revisions.MemoryRevisions(self._api_client) # type: ignore[no-any-return]
|
|
1423
|
+
|
|
1424
|
+
def create(
|
|
1425
|
+
self,
|
|
1426
|
+
*,
|
|
1427
|
+
name: str,
|
|
1428
|
+
fact: str,
|
|
1429
|
+
scope: dict[str, str],
|
|
1430
|
+
config: Optional[types.MemoryConfigOrDict] = None,
|
|
1431
|
+
) -> types.MemoryOperation:
|
|
1432
|
+
"""Creates a new memory in Memory Bank.
|
|
1433
|
+
|
|
1434
|
+
Args:
|
|
1435
|
+
name (str):
|
|
1436
|
+
Required. The name of the memory to create.
|
|
1437
|
+
fact (str):
|
|
1438
|
+
Required. The fact to be stored in the memory.
|
|
1439
|
+
scope (dict[str, str]):
|
|
1440
|
+
Required. The scope of the memory. For example, {"user_id": "123"}.
|
|
1441
|
+
config (MemoryConfigOrDict):
|
|
1442
|
+
Optional. The configuration for the memory.
|
|
1443
|
+
|
|
1444
|
+
Returns:
|
|
1445
|
+
MemoryOperation: The operation for creating the memory.
|
|
1446
|
+
"""
|
|
1447
|
+
if config is None:
|
|
1448
|
+
config = types.MemoryConfig()
|
|
1449
|
+
elif isinstance(config, dict):
|
|
1450
|
+
config = types.MemoryConfig.model_validate(config)
|
|
1451
|
+
operation = self._create(
|
|
1452
|
+
name=name,
|
|
1453
|
+
fact=fact,
|
|
1454
|
+
scope=scope,
|
|
1455
|
+
config=config,
|
|
1456
|
+
)
|
|
1457
|
+
if config.wait_for_completion:
|
|
1458
|
+
if not operation.done:
|
|
1459
|
+
operation = _memory_bank_utils._await_operation(
|
|
1460
|
+
operation_name=operation.name,
|
|
1461
|
+
get_operation_fn=self._get_memory_operation,
|
|
1462
|
+
poll_interval_seconds=0.5,
|
|
1463
|
+
)
|
|
1464
|
+
# We need to make a call to get the memory because the operation
|
|
1465
|
+
# response might not contain the relevant fields.
|
|
1466
|
+
if operation.response:
|
|
1467
|
+
operation.response = self.get(name=operation.response.name)
|
|
1468
|
+
elif operation.error:
|
|
1469
|
+
raise RuntimeError(f"Failed to create memory: {operation.error}")
|
|
1470
|
+
else:
|
|
1471
|
+
raise RuntimeError("Error creating memory.")
|
|
1472
|
+
return operation
|
|
1473
|
+
|
|
1474
|
+
def generate(
|
|
1475
|
+
self,
|
|
1476
|
+
*,
|
|
1477
|
+
name: str,
|
|
1478
|
+
vertex_session_source: Optional[
|
|
1479
|
+
types.GenerateMemoriesRequestVertexSessionSourceOrDict
|
|
1480
|
+
] = None,
|
|
1481
|
+
direct_contents_source: Optional[
|
|
1482
|
+
types.GenerateMemoriesRequestDirectContentsSourceOrDict
|
|
1483
|
+
] = None,
|
|
1484
|
+
direct_memories_source: Optional[
|
|
1485
|
+
types.GenerateMemoriesRequestDirectMemoriesSourceOrDict
|
|
1486
|
+
] = None,
|
|
1487
|
+
scope: Optional[dict[str, str]] = None,
|
|
1488
|
+
config: Optional[types.GenerateMemoriesConfigOrDict] = None,
|
|
1489
|
+
) -> types.GenerateMemoriesOperation:
|
|
1490
|
+
"""Generates memories with Memory Bank.
|
|
1491
|
+
|
|
1492
|
+
Args:
|
|
1493
|
+
name (str):
|
|
1494
|
+
Required. The name of the memory bank to generate memories with.
|
|
1495
|
+
vertex_session_source (GenerateMemoriesRequestVertexSessionSource):
|
|
1496
|
+
Optional. The vertex session source to use for generating
|
|
1497
|
+
memories. Only one of vertex_session_source,
|
|
1498
|
+
direct_contents_source, or direct_memories_source can be
|
|
1499
|
+
specified.
|
|
1500
|
+
direct_contents_source(GenerateMemoriesRequestDirectContentsSource):
|
|
1501
|
+
Optional. The direct contents source to use for generating
|
|
1502
|
+
memories. Only one of vertex_session_source, direct_contents_source,
|
|
1503
|
+
or direct_memories_source can be specified.
|
|
1504
|
+
direct_memories_source (GenerateMemoriesRequestDirectMemoriesSource):
|
|
1505
|
+
Optional. The direct memories source to use for generating
|
|
1506
|
+
memories. Only one of vertex_session_source, direct_contents_source,
|
|
1507
|
+
or direct_memories_source can be specified.
|
|
1508
|
+
scope (dict[str, str]):
|
|
1509
|
+
Optional. The scope of the memories to generate. This is optional
|
|
1510
|
+
if vertex_session_source is used, otherwise it must be specified.
|
|
1511
|
+
config (GenerateMemoriesConfig):
|
|
1512
|
+
Optional. The configuration for the memories to generate.
|
|
1513
|
+
|
|
1514
|
+
Returns:
|
|
1515
|
+
GenerateMemoriesOperation:
|
|
1516
|
+
The operation for generating the memories.
|
|
1517
|
+
"""
|
|
1518
|
+
if config is None:
|
|
1519
|
+
config = types.GenerateMemoriesConfig()
|
|
1520
|
+
elif isinstance(config, dict):
|
|
1521
|
+
config = types.GenerateMemoriesConfig.model_validate(config)
|
|
1522
|
+
operation = self._generate(
|
|
1523
|
+
name=name,
|
|
1524
|
+
vertex_session_source=vertex_session_source,
|
|
1525
|
+
direct_contents_source=direct_contents_source,
|
|
1526
|
+
direct_memories_source=direct_memories_source,
|
|
1527
|
+
scope=scope,
|
|
1528
|
+
config=config,
|
|
1529
|
+
)
|
|
1530
|
+
if config.wait_for_completion and not operation.done:
|
|
1531
|
+
operation = _memory_bank_utils._await_operation(
|
|
1532
|
+
operation_name=operation.name,
|
|
1533
|
+
get_operation_fn=self._get_generate_memories_operation,
|
|
1534
|
+
poll_interval_seconds=0.5,
|
|
1535
|
+
)
|
|
1536
|
+
if operation.error:
|
|
1537
|
+
raise RuntimeError(f"Failed to generate memory: {operation.error}")
|
|
1538
|
+
return operation
|
|
1539
|
+
|
|
1540
|
+
def list(
|
|
1541
|
+
self,
|
|
1542
|
+
*,
|
|
1543
|
+
name: str,
|
|
1544
|
+
config: Optional[types.ListMemoriesConfigOrDict] = None,
|
|
1545
|
+
) -> Iterator[types.Memory]:
|
|
1546
|
+
"""Lists Memory Bank memories.
|
|
1547
|
+
|
|
1548
|
+
Args:
|
|
1549
|
+
name (str):
|
|
1550
|
+
Required. The name of the memory bank to list memories for.
|
|
1551
|
+
config (ListMemoriesConfig):
|
|
1552
|
+
Optional. The configuration for the memories to list.
|
|
1553
|
+
|
|
1554
|
+
Returns:
|
|
1555
|
+
Iterable[Memory]: An iterable of memories.
|
|
1556
|
+
"""
|
|
1557
|
+
|
|
1558
|
+
return Pager(
|
|
1559
|
+
"memories",
|
|
1560
|
+
functools.partial(self._list, name=name),
|
|
1561
|
+
self._list(name=name, config=config),
|
|
1562
|
+
config,
|
|
1563
|
+
)
|
|
1564
|
+
|
|
1565
|
+
def retrieve(
|
|
1566
|
+
self,
|
|
1567
|
+
*,
|
|
1568
|
+
name: str,
|
|
1569
|
+
scope: dict[str, str],
|
|
1570
|
+
similarity_search_params: Optional[
|
|
1571
|
+
types.RetrieveMemoriesRequestSimilaritySearchParamsOrDict
|
|
1572
|
+
] = None,
|
|
1573
|
+
simple_retrieval_params: Optional[
|
|
1574
|
+
types.RetrieveMemoriesRequestSimpleRetrievalParamsOrDict
|
|
1575
|
+
] = None,
|
|
1576
|
+
config: Optional[types.RetrieveMemoriesConfigOrDict] = None,
|
|
1577
|
+
) -> Iterator[types.RetrieveMemoriesResponseRetrievedMemory]:
|
|
1578
|
+
"""Retrieves memories from Memory Bank.
|
|
1579
|
+
|
|
1580
|
+
Args:
|
|
1581
|
+
name (str):
|
|
1582
|
+
Required. The name of the memory bank to retrieve memories from.
|
|
1583
|
+
scope (dict[str, str]):
|
|
1584
|
+
Required. The scope of the memories to retrieve. For example,
|
|
1585
|
+
{"user_id": "123"}.
|
|
1586
|
+
similarity_search_params (RetrieveMemoriesRequestSimilaritySearchParams):
|
|
1587
|
+
Optional. The similarity search parameters to use for retrieving
|
|
1588
|
+
memories.
|
|
1589
|
+
simple_retrieval_params (RetrieveMemoriesRequestSimpleRetrievalParams):
|
|
1590
|
+
Optional. The simple retrieval parameters to use for retrieving
|
|
1591
|
+
memories.
|
|
1592
|
+
config (RetrieveMemoriesConfig):
|
|
1593
|
+
Optional. The configuration for the memories to retrieve.
|
|
1594
|
+
|
|
1595
|
+
Returns:
|
|
1596
|
+
Iterator[RetrieveMemoriesResponseRetrievedMemory]: An iterable of
|
|
1597
|
+
retrieved memories.
|
|
1598
|
+
"""
|
|
1599
|
+
return Pager(
|
|
1600
|
+
"retrieved_memories",
|
|
1601
|
+
lambda config: self._retrieve(
|
|
1602
|
+
name=name,
|
|
1603
|
+
similarity_search_params=similarity_search_params,
|
|
1604
|
+
simple_retrieval_params=simple_retrieval_params,
|
|
1605
|
+
scope=scope,
|
|
1606
|
+
config=config,
|
|
1607
|
+
),
|
|
1608
|
+
self._retrieve(
|
|
1609
|
+
name=name,
|
|
1610
|
+
similarity_search_params=similarity_search_params,
|
|
1611
|
+
simple_retrieval_params=simple_retrieval_params,
|
|
1612
|
+
scope=scope,
|
|
1613
|
+
config=config,
|
|
1614
|
+
),
|
|
1615
|
+
config,
|
|
1616
|
+
)
|
|
1617
|
+
|
|
1618
|
+
def rollback(
|
|
1619
|
+
self,
|
|
1620
|
+
*,
|
|
1621
|
+
name: str,
|
|
1622
|
+
target_revision_id: str,
|
|
1623
|
+
config: Optional[types.RollbackMemoryConfigOrDict] = None,
|
|
1624
|
+
) -> types.RollbackMemoryOperation:
|
|
1625
|
+
"""Rolls back a memory to a previous revision.
|
|
1626
|
+
|
|
1627
|
+
Args:
|
|
1628
|
+
name (str):
|
|
1629
|
+
Required. The name of the memory to rollback.
|
|
1630
|
+
target_revision_id (str):
|
|
1631
|
+
Required. The revision ID to roll back to
|
|
1632
|
+
config (RollbackMemoryConfig):
|
|
1633
|
+
Optional. The configuration for the rollback.
|
|
1634
|
+
|
|
1635
|
+
Returns:
|
|
1636
|
+
RollbackMemoryOperation:
|
|
1637
|
+
The operation for rolling back the memory.
|
|
1638
|
+
"""
|
|
1639
|
+
if config is None:
|
|
1640
|
+
config = types.RollbackMemoryConfig()
|
|
1641
|
+
elif isinstance(config, dict):
|
|
1642
|
+
config = types.RollbackMemoryConfig.model_validate(config)
|
|
1643
|
+
operation = self._rollback(
|
|
1644
|
+
name=name,
|
|
1645
|
+
target_revision_id=target_revision_id,
|
|
1646
|
+
config=config,
|
|
1647
|
+
)
|
|
1648
|
+
if config.wait_for_completion and not operation.done:
|
|
1649
|
+
operation = _memory_bank_utils._await_operation(
|
|
1650
|
+
operation_name=operation.name,
|
|
1651
|
+
get_operation_fn=self._get_memory_operation,
|
|
1652
|
+
poll_interval_seconds=0.5,
|
|
1653
|
+
)
|
|
1654
|
+
if operation.error:
|
|
1655
|
+
raise RuntimeError(f"Failed to rollback memory: {operation.error}")
|
|
1656
|
+
return operation
|
|
1657
|
+
|
|
1658
|
+
def purge(
|
|
1659
|
+
self,
|
|
1660
|
+
*,
|
|
1661
|
+
name: str,
|
|
1662
|
+
filter: Optional[str] = None,
|
|
1663
|
+
filter_groups: Optional[List[types.MemoryConjunctionFilter]] = None,
|
|
1664
|
+
force: bool = False,
|
|
1665
|
+
config: Optional[types.PurgeMemoriesConfigOrDict] = None,
|
|
1666
|
+
) -> types.PurgeMemoriesOperation:
|
|
1667
|
+
"""Purges memories from Memory Bank.
|
|
1668
|
+
|
|
1669
|
+
Args:
|
|
1670
|
+
name (str):
|
|
1671
|
+
Required. The name of the Memory Bank to purge memories from.
|
|
1672
|
+
filter (str):
|
|
1673
|
+
Optional. The standard list filter to determine which memories to purge.
|
|
1674
|
+
filter_groups (list[MemoryConjunctionFilter]):
|
|
1675
|
+
Optional. Metadata filters that will be applied to the memories'
|
|
1676
|
+
`metadata` using OR logic. Filters are defined using disjunctive
|
|
1677
|
+
normal form (OR of ANDs).
|
|
1678
|
+
force (bool):
|
|
1679
|
+
Optional. Whether to force the purge operation. If false, the
|
|
1680
|
+
operation will be staged but not executed.
|
|
1681
|
+
config (PurgeMemoriesConfig):
|
|
1682
|
+
Optional. The configuration for the purge operation.
|
|
1683
|
+
|
|
1684
|
+
Returns:
|
|
1685
|
+
PurgeMemoriesOperation:
|
|
1686
|
+
The operation for purging the memories.
|
|
1687
|
+
"""
|
|
1688
|
+
if config is None:
|
|
1689
|
+
config = types.PurgeMemoriesConfig()
|
|
1690
|
+
elif isinstance(config, dict):
|
|
1691
|
+
config = types.PurgeMemoriesConfig.model_validate(config)
|
|
1692
|
+
operation = self._purge(
|
|
1693
|
+
name=name,
|
|
1694
|
+
filter=filter,
|
|
1695
|
+
filter_groups=filter_groups,
|
|
1696
|
+
force=force,
|
|
1697
|
+
config=config,
|
|
1698
|
+
)
|
|
1699
|
+
if config.wait_for_completion and not operation.done:
|
|
1700
|
+
operation = _memory_bank_utils._await_operation(
|
|
1701
|
+
operation_name=operation.name,
|
|
1702
|
+
get_operation_fn=self._get_memory_operation,
|
|
1703
|
+
poll_interval_seconds=0.5,
|
|
1704
|
+
)
|
|
1705
|
+
if operation.error:
|
|
1706
|
+
raise RuntimeError(f"Failed to purge memories: {operation.error}")
|
|
1707
|
+
return operation
|
|
1708
|
+
|
|
1709
|
+
|
|
1710
|
+
class AsyncMemories(_api_module.BaseModule):
|
|
1711
|
+
|
|
1712
|
+
async def _create(
|
|
1713
|
+
self,
|
|
1714
|
+
*,
|
|
1715
|
+
name: str,
|
|
1716
|
+
fact: str,
|
|
1717
|
+
scope: dict[str, str],
|
|
1718
|
+
config: Optional[types.MemoryConfigOrDict] = None,
|
|
1719
|
+
) -> types.MemoryOperation:
|
|
1720
|
+
"""
|
|
1721
|
+
Creates a new memory in the Memory Bank.
|
|
1722
|
+
"""
|
|
1723
|
+
|
|
1724
|
+
parameter_model = types._CreateMemoryRequestParameters(
|
|
1725
|
+
name=name,
|
|
1726
|
+
fact=fact,
|
|
1727
|
+
scope=scope,
|
|
1728
|
+
config=config,
|
|
1729
|
+
)
|
|
1730
|
+
|
|
1731
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1732
|
+
if not self._api_client.vertexai:
|
|
1733
|
+
raise ValueError(
|
|
1734
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1735
|
+
)
|
|
1736
|
+
else:
|
|
1737
|
+
request_dict = _CreateMemoryRequestParameters_to_vertex(parameter_model)
|
|
1738
|
+
request_url_dict = request_dict.get("_url")
|
|
1739
|
+
if request_url_dict:
|
|
1740
|
+
path = "{name}/memories".format_map(request_url_dict)
|
|
1741
|
+
else:
|
|
1742
|
+
path = "{name}/memories"
|
|
1743
|
+
|
|
1744
|
+
query_params = request_dict.get("_query")
|
|
1745
|
+
if query_params:
|
|
1746
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1747
|
+
# TODO: remove the hack that pops config.
|
|
1748
|
+
request_dict.pop("config", None)
|
|
1749
|
+
|
|
1750
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1751
|
+
if (
|
|
1752
|
+
parameter_model.config is not None
|
|
1753
|
+
and parameter_model.config.http_options is not None
|
|
1754
|
+
):
|
|
1755
|
+
http_options = parameter_model.config.http_options
|
|
1756
|
+
|
|
1757
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1758
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1759
|
+
|
|
1760
|
+
response = await self._api_client.async_request(
|
|
1761
|
+
"post", path, request_dict, http_options
|
|
1762
|
+
)
|
|
1763
|
+
|
|
1764
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1765
|
+
|
|
1766
|
+
return_value = types.MemoryOperation._from_response(
|
|
1767
|
+
response=response_dict,
|
|
1768
|
+
kwargs=(
|
|
1769
|
+
{
|
|
1770
|
+
"config": {
|
|
1771
|
+
"response_schema": getattr(
|
|
1772
|
+
parameter_model.config, "response_schema", None
|
|
1773
|
+
),
|
|
1774
|
+
"response_json_schema": getattr(
|
|
1775
|
+
parameter_model.config, "response_json_schema", None
|
|
1776
|
+
),
|
|
1777
|
+
"include_all_fields": getattr(
|
|
1778
|
+
parameter_model.config, "include_all_fields", None
|
|
1779
|
+
),
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
if getattr(parameter_model, "config", None)
|
|
1783
|
+
else {}
|
|
1784
|
+
),
|
|
1785
|
+
)
|
|
1786
|
+
|
|
1787
|
+
self._api_client._verify_response(return_value)
|
|
1788
|
+
return return_value
|
|
1789
|
+
|
|
1790
|
+
async def delete(
|
|
1791
|
+
self, *, name: str, config: Optional[types.DeleteMemoryConfigOrDict] = None
|
|
1792
|
+
) -> types.DeleteMemoryOperation:
|
|
1793
|
+
"""
|
|
1794
|
+
Delete a memory.
|
|
1795
|
+
|
|
1796
|
+
Args:
|
|
1797
|
+
name (str):
|
|
1798
|
+
Required. The name of the memory to delete. Format:
|
|
1799
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/memories/{memory}`.
|
|
1800
|
+
config (DeleteRuntimeMemoryConfig):
|
|
1801
|
+
Optional. Additional configurations for deleting the Agent Runtime.
|
|
1802
|
+
|
|
1803
|
+
"""
|
|
1804
|
+
|
|
1805
|
+
parameter_model = types._DeleteMemoryRequestParameters(
|
|
1806
|
+
name=name,
|
|
1807
|
+
config=config,
|
|
1808
|
+
)
|
|
1809
|
+
|
|
1810
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1811
|
+
if not self._api_client.vertexai:
|
|
1812
|
+
raise ValueError(
|
|
1813
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1814
|
+
)
|
|
1815
|
+
else:
|
|
1816
|
+
request_dict = _DeleteMemoryRequestParameters_to_vertex(parameter_model)
|
|
1817
|
+
request_url_dict = request_dict.get("_url")
|
|
1818
|
+
if request_url_dict:
|
|
1819
|
+
path = "{name}".format_map(request_url_dict)
|
|
1820
|
+
else:
|
|
1821
|
+
path = "{name}"
|
|
1822
|
+
|
|
1823
|
+
query_params = request_dict.get("_query")
|
|
1824
|
+
if query_params:
|
|
1825
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1826
|
+
# TODO: remove the hack that pops config.
|
|
1827
|
+
request_dict.pop("config", None)
|
|
1828
|
+
|
|
1829
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1830
|
+
if (
|
|
1831
|
+
parameter_model.config is not None
|
|
1832
|
+
and parameter_model.config.http_options is not None
|
|
1833
|
+
):
|
|
1834
|
+
http_options = parameter_model.config.http_options
|
|
1835
|
+
|
|
1836
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1837
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1838
|
+
|
|
1839
|
+
response = await self._api_client.async_request(
|
|
1840
|
+
"delete", path, request_dict, http_options
|
|
1841
|
+
)
|
|
1842
|
+
|
|
1843
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1844
|
+
|
|
1845
|
+
return_value = types.DeleteMemoryOperation._from_response(
|
|
1846
|
+
response=response_dict,
|
|
1847
|
+
kwargs=(
|
|
1848
|
+
{
|
|
1849
|
+
"config": {
|
|
1850
|
+
"response_schema": getattr(
|
|
1851
|
+
parameter_model.config, "response_schema", None
|
|
1852
|
+
),
|
|
1853
|
+
"response_json_schema": getattr(
|
|
1854
|
+
parameter_model.config, "response_json_schema", None
|
|
1855
|
+
),
|
|
1856
|
+
"include_all_fields": getattr(
|
|
1857
|
+
parameter_model.config, "include_all_fields", None
|
|
1858
|
+
),
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
if getattr(parameter_model, "config", None)
|
|
1862
|
+
else {}
|
|
1863
|
+
),
|
|
1864
|
+
)
|
|
1865
|
+
|
|
1866
|
+
self._api_client._verify_response(return_value)
|
|
1867
|
+
return return_value
|
|
1868
|
+
|
|
1869
|
+
async def _generate(
|
|
1870
|
+
self,
|
|
1871
|
+
*,
|
|
1872
|
+
name: str,
|
|
1873
|
+
vertex_session_source: Optional[
|
|
1874
|
+
types.GenerateMemoriesRequestVertexSessionSourceOrDict
|
|
1875
|
+
] = None,
|
|
1876
|
+
direct_contents_source: Optional[
|
|
1877
|
+
types.GenerateMemoriesRequestDirectContentsSourceOrDict
|
|
1878
|
+
] = None,
|
|
1879
|
+
direct_memories_source: Optional[
|
|
1880
|
+
types.GenerateMemoriesRequestDirectMemoriesSourceOrDict
|
|
1881
|
+
] = None,
|
|
1882
|
+
scope: Optional[dict[str, str]] = None,
|
|
1883
|
+
config: Optional[types.GenerateMemoriesConfigOrDict] = None,
|
|
1884
|
+
) -> types.GenerateMemoriesOperation:
|
|
1885
|
+
"""
|
|
1886
|
+
Generates memories for a Memory Bank.
|
|
1887
|
+
"""
|
|
1888
|
+
|
|
1889
|
+
parameter_model = types._GenerateMemoriesRequestParameters(
|
|
1890
|
+
name=name,
|
|
1891
|
+
vertex_session_source=vertex_session_source,
|
|
1892
|
+
direct_contents_source=direct_contents_source,
|
|
1893
|
+
direct_memories_source=direct_memories_source,
|
|
1894
|
+
scope=scope,
|
|
1895
|
+
config=config,
|
|
1896
|
+
)
|
|
1897
|
+
|
|
1898
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1899
|
+
if not self._api_client.vertexai:
|
|
1900
|
+
raise ValueError(
|
|
1901
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1902
|
+
)
|
|
1903
|
+
else:
|
|
1904
|
+
request_dict = _GenerateMemoriesRequestParameters_to_vertex(parameter_model)
|
|
1905
|
+
request_url_dict = request_dict.get("_url")
|
|
1906
|
+
if request_url_dict:
|
|
1907
|
+
path = "{name}/memories:generate".format_map(request_url_dict)
|
|
1908
|
+
else:
|
|
1909
|
+
path = "{name}/memories:generate"
|
|
1910
|
+
|
|
1911
|
+
query_params = request_dict.get("_query")
|
|
1912
|
+
if query_params:
|
|
1913
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1914
|
+
# TODO: remove the hack that pops config.
|
|
1915
|
+
request_dict.pop("config", None)
|
|
1916
|
+
|
|
1917
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1918
|
+
if (
|
|
1919
|
+
parameter_model.config is not None
|
|
1920
|
+
and parameter_model.config.http_options is not None
|
|
1921
|
+
):
|
|
1922
|
+
http_options = parameter_model.config.http_options
|
|
1923
|
+
|
|
1924
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1925
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1926
|
+
|
|
1927
|
+
response = await self._api_client.async_request(
|
|
1928
|
+
"post", path, request_dict, http_options
|
|
1929
|
+
)
|
|
1930
|
+
|
|
1931
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1932
|
+
|
|
1933
|
+
return_value = types.GenerateMemoriesOperation._from_response(
|
|
1934
|
+
response=response_dict,
|
|
1935
|
+
kwargs=(
|
|
1936
|
+
{
|
|
1937
|
+
"config": {
|
|
1938
|
+
"response_schema": getattr(
|
|
1939
|
+
parameter_model.config, "response_schema", None
|
|
1940
|
+
),
|
|
1941
|
+
"response_json_schema": getattr(
|
|
1942
|
+
parameter_model.config, "response_json_schema", None
|
|
1943
|
+
),
|
|
1944
|
+
"include_all_fields": getattr(
|
|
1945
|
+
parameter_model.config, "include_all_fields", None
|
|
1946
|
+
),
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
if getattr(parameter_model, "config", None)
|
|
1950
|
+
else {}
|
|
1951
|
+
),
|
|
1952
|
+
)
|
|
1953
|
+
|
|
1954
|
+
self._api_client._verify_response(return_value)
|
|
1955
|
+
return return_value
|
|
1956
|
+
|
|
1957
|
+
async def get(
|
|
1958
|
+
self, *, name: str, config: Optional[types.GetMemoryConfigOrDict] = None
|
|
1959
|
+
) -> types.Memory:
|
|
1960
|
+
"""
|
|
1961
|
+
Gets a memory.
|
|
1962
|
+
|
|
1963
|
+
Args:
|
|
1964
|
+
name (str): Required. A fully-qualified resource name or ID such as
|
|
1965
|
+
"projects/123/locations/us-central1/reasoningEngines/456/memories/789"
|
|
1966
|
+
or a shortened name such as "reasoningEngines/456/memories/789".
|
|
1967
|
+
|
|
1968
|
+
"""
|
|
1969
|
+
|
|
1970
|
+
parameter_model = types._GetMemoryRequestParameters(
|
|
1971
|
+
name=name,
|
|
1972
|
+
config=config,
|
|
1973
|
+
)
|
|
1974
|
+
|
|
1975
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1976
|
+
if not self._api_client.vertexai:
|
|
1977
|
+
raise ValueError(
|
|
1978
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1979
|
+
)
|
|
1980
|
+
else:
|
|
1981
|
+
request_dict = _GetMemoryRequestParameters_to_vertex(parameter_model)
|
|
1982
|
+
request_url_dict = request_dict.get("_url")
|
|
1983
|
+
if request_url_dict:
|
|
1984
|
+
path = "{name}".format_map(request_url_dict)
|
|
1985
|
+
else:
|
|
1986
|
+
path = "{name}"
|
|
1987
|
+
|
|
1988
|
+
query_params = request_dict.get("_query")
|
|
1989
|
+
if query_params:
|
|
1990
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1991
|
+
# TODO: remove the hack that pops config.
|
|
1992
|
+
request_dict.pop("config", None)
|
|
1993
|
+
|
|
1994
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1995
|
+
if (
|
|
1996
|
+
parameter_model.config is not None
|
|
1997
|
+
and parameter_model.config.http_options is not None
|
|
1998
|
+
):
|
|
1999
|
+
http_options = parameter_model.config.http_options
|
|
2000
|
+
|
|
2001
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
2002
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
2003
|
+
|
|
2004
|
+
response = await self._api_client.async_request(
|
|
2005
|
+
"get", path, request_dict, http_options
|
|
2006
|
+
)
|
|
2007
|
+
|
|
2008
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
2009
|
+
|
|
2010
|
+
return_value = types.Memory._from_response(
|
|
2011
|
+
response=response_dict,
|
|
2012
|
+
kwargs=(
|
|
2013
|
+
{
|
|
2014
|
+
"config": {
|
|
2015
|
+
"response_schema": getattr(
|
|
2016
|
+
parameter_model.config, "response_schema", None
|
|
2017
|
+
),
|
|
2018
|
+
"response_json_schema": getattr(
|
|
2019
|
+
parameter_model.config, "response_json_schema", None
|
|
2020
|
+
),
|
|
2021
|
+
"include_all_fields": getattr(
|
|
2022
|
+
parameter_model.config, "include_all_fields", None
|
|
2023
|
+
),
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
if getattr(parameter_model, "config", None)
|
|
2027
|
+
else {}
|
|
2028
|
+
),
|
|
2029
|
+
)
|
|
2030
|
+
|
|
2031
|
+
self._api_client._verify_response(return_value)
|
|
2032
|
+
return return_value
|
|
2033
|
+
|
|
2034
|
+
async def _list(
|
|
2035
|
+
self, *, name: str, config: Optional[types.ListMemoriesConfigOrDict] = None
|
|
2036
|
+
) -> types.ListMemoriesResponse:
|
|
2037
|
+
"""
|
|
2038
|
+
Lists memories.
|
|
2039
|
+
"""
|
|
2040
|
+
|
|
2041
|
+
parameter_model = types._ListMemoriesRequestParameters(
|
|
2042
|
+
name=name,
|
|
2043
|
+
config=config,
|
|
2044
|
+
)
|
|
2045
|
+
|
|
2046
|
+
request_url_dict: Optional[dict[str, str]]
|
|
2047
|
+
if not self._api_client.vertexai:
|
|
2048
|
+
raise ValueError(
|
|
2049
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
2050
|
+
)
|
|
2051
|
+
else:
|
|
2052
|
+
request_dict = _ListMemoriesRequestParameters_to_vertex(parameter_model)
|
|
2053
|
+
request_url_dict = request_dict.get("_url")
|
|
2054
|
+
if request_url_dict:
|
|
2055
|
+
path = "{name}/memories".format_map(request_url_dict)
|
|
2056
|
+
else:
|
|
2057
|
+
path = "{name}/memories"
|
|
2058
|
+
|
|
2059
|
+
query_params = request_dict.get("_query")
|
|
2060
|
+
if query_params:
|
|
2061
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
2062
|
+
# TODO: remove the hack that pops config.
|
|
2063
|
+
request_dict.pop("config", None)
|
|
2064
|
+
|
|
2065
|
+
http_options: Optional[types.HttpOptions] = None
|
|
2066
|
+
if (
|
|
2067
|
+
parameter_model.config is not None
|
|
2068
|
+
and parameter_model.config.http_options is not None
|
|
2069
|
+
):
|
|
2070
|
+
http_options = parameter_model.config.http_options
|
|
2071
|
+
|
|
2072
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
2073
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
2074
|
+
|
|
2075
|
+
response = await self._api_client.async_request(
|
|
2076
|
+
"get", path, request_dict, http_options
|
|
2077
|
+
)
|
|
2078
|
+
|
|
2079
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
2080
|
+
|
|
2081
|
+
return_value = types.ListMemoriesResponse._from_response(
|
|
2082
|
+
response=response_dict,
|
|
2083
|
+
kwargs=(
|
|
2084
|
+
{
|
|
2085
|
+
"config": {
|
|
2086
|
+
"response_schema": getattr(
|
|
2087
|
+
parameter_model.config, "response_schema", None
|
|
2088
|
+
),
|
|
2089
|
+
"response_json_schema": getattr(
|
|
2090
|
+
parameter_model.config, "response_json_schema", None
|
|
2091
|
+
),
|
|
2092
|
+
"include_all_fields": getattr(
|
|
2093
|
+
parameter_model.config, "include_all_fields", None
|
|
2094
|
+
),
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
if getattr(parameter_model, "config", None)
|
|
2098
|
+
else {}
|
|
2099
|
+
),
|
|
2100
|
+
)
|
|
2101
|
+
|
|
2102
|
+
self._api_client._verify_response(return_value)
|
|
2103
|
+
return return_value
|
|
2104
|
+
|
|
2105
|
+
async def _get_memory_operation(
|
|
2106
|
+
self,
|
|
2107
|
+
*,
|
|
2108
|
+
operation_name: str,
|
|
2109
|
+
config: Optional[types.GetMemoryBankOperationConfigOrDict] = None,
|
|
2110
|
+
) -> types.MemoryOperation:
|
|
2111
|
+
parameter_model = types._GetMemoryOperationParameters(
|
|
2112
|
+
operation_name=operation_name,
|
|
2113
|
+
config=config,
|
|
2114
|
+
)
|
|
2115
|
+
|
|
2116
|
+
request_url_dict: Optional[dict[str, str]]
|
|
2117
|
+
if not self._api_client.vertexai:
|
|
2118
|
+
raise ValueError(
|
|
2119
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
2120
|
+
)
|
|
2121
|
+
else:
|
|
2122
|
+
request_dict = _GetMemoryOperationParameters_to_vertex(parameter_model)
|
|
2123
|
+
request_url_dict = request_dict.get("_url")
|
|
2124
|
+
if request_url_dict:
|
|
2125
|
+
path = "{operationName}".format_map(request_url_dict)
|
|
2126
|
+
else:
|
|
2127
|
+
path = "{operationName}"
|
|
2128
|
+
|
|
2129
|
+
query_params = request_dict.get("_query")
|
|
2130
|
+
if query_params:
|
|
2131
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
2132
|
+
# TODO: remove the hack that pops config.
|
|
2133
|
+
request_dict.pop("config", None)
|
|
2134
|
+
|
|
2135
|
+
http_options: Optional[types.HttpOptions] = None
|
|
2136
|
+
if (
|
|
2137
|
+
parameter_model.config is not None
|
|
2138
|
+
and parameter_model.config.http_options is not None
|
|
2139
|
+
):
|
|
2140
|
+
http_options = parameter_model.config.http_options
|
|
2141
|
+
|
|
2142
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
2143
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
2144
|
+
|
|
2145
|
+
response = await self._api_client.async_request(
|
|
2146
|
+
"get", path, request_dict, http_options
|
|
2147
|
+
)
|
|
2148
|
+
|
|
2149
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
2150
|
+
|
|
2151
|
+
return_value = types.MemoryOperation._from_response(
|
|
2152
|
+
response=response_dict,
|
|
2153
|
+
kwargs=(
|
|
2154
|
+
{
|
|
2155
|
+
"config": {
|
|
2156
|
+
"response_schema": getattr(
|
|
2157
|
+
parameter_model.config, "response_schema", None
|
|
2158
|
+
),
|
|
2159
|
+
"response_json_schema": getattr(
|
|
2160
|
+
parameter_model.config, "response_json_schema", None
|
|
2161
|
+
),
|
|
2162
|
+
"include_all_fields": getattr(
|
|
2163
|
+
parameter_model.config, "include_all_fields", None
|
|
2164
|
+
),
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
if getattr(parameter_model, "config", None)
|
|
2168
|
+
else {}
|
|
2169
|
+
),
|
|
2170
|
+
)
|
|
2171
|
+
|
|
2172
|
+
self._api_client._verify_response(return_value)
|
|
2173
|
+
return return_value
|
|
2174
|
+
|
|
2175
|
+
async def _get_generate_memories_operation(
|
|
2176
|
+
self,
|
|
2177
|
+
*,
|
|
2178
|
+
operation_name: str,
|
|
2179
|
+
config: Optional[types.GetMemoryBankOperationConfigOrDict] = None,
|
|
2180
|
+
) -> types.GenerateMemoriesOperation:
|
|
2181
|
+
parameter_model = types._GetGenerateMemoriesOperationParameters(
|
|
2182
|
+
operation_name=operation_name,
|
|
2183
|
+
config=config,
|
|
2184
|
+
)
|
|
2185
|
+
|
|
2186
|
+
request_url_dict: Optional[dict[str, str]]
|
|
2187
|
+
if not self._api_client.vertexai:
|
|
2188
|
+
raise ValueError(
|
|
2189
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
2190
|
+
)
|
|
2191
|
+
else:
|
|
2192
|
+
request_dict = _GetGenerateMemoriesOperationParameters_to_vertex(
|
|
2193
|
+
parameter_model
|
|
2194
|
+
)
|
|
2195
|
+
request_url_dict = request_dict.get("_url")
|
|
2196
|
+
if request_url_dict:
|
|
2197
|
+
path = "{operationName}".format_map(request_url_dict)
|
|
2198
|
+
else:
|
|
2199
|
+
path = "{operationName}"
|
|
2200
|
+
|
|
2201
|
+
query_params = request_dict.get("_query")
|
|
2202
|
+
if query_params:
|
|
2203
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
2204
|
+
# TODO: remove the hack that pops config.
|
|
2205
|
+
request_dict.pop("config", None)
|
|
2206
|
+
|
|
2207
|
+
http_options: Optional[types.HttpOptions] = None
|
|
2208
|
+
if (
|
|
2209
|
+
parameter_model.config is not None
|
|
2210
|
+
and parameter_model.config.http_options is not None
|
|
2211
|
+
):
|
|
2212
|
+
http_options = parameter_model.config.http_options
|
|
2213
|
+
|
|
2214
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
2215
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
2216
|
+
|
|
2217
|
+
response = await self._api_client.async_request(
|
|
2218
|
+
"get", path, request_dict, http_options
|
|
2219
|
+
)
|
|
2220
|
+
|
|
2221
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
2222
|
+
|
|
2223
|
+
return_value = types.GenerateMemoriesOperation._from_response(
|
|
2224
|
+
response=response_dict,
|
|
2225
|
+
kwargs=(
|
|
2226
|
+
{
|
|
2227
|
+
"config": {
|
|
2228
|
+
"response_schema": getattr(
|
|
2229
|
+
parameter_model.config, "response_schema", None
|
|
2230
|
+
),
|
|
2231
|
+
"response_json_schema": getattr(
|
|
2232
|
+
parameter_model.config, "response_json_schema", None
|
|
2233
|
+
),
|
|
2234
|
+
"include_all_fields": getattr(
|
|
2235
|
+
parameter_model.config, "include_all_fields", None
|
|
2236
|
+
),
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
if getattr(parameter_model, "config", None)
|
|
2240
|
+
else {}
|
|
2241
|
+
),
|
|
2242
|
+
)
|
|
2243
|
+
|
|
2244
|
+
self._api_client._verify_response(return_value)
|
|
2245
|
+
return return_value
|
|
2246
|
+
|
|
2247
|
+
async def _retrieve(
|
|
2248
|
+
self,
|
|
2249
|
+
*,
|
|
2250
|
+
name: str,
|
|
2251
|
+
scope: dict[str, str],
|
|
2252
|
+
similarity_search_params: Optional[
|
|
2253
|
+
types.RetrieveMemoriesRequestSimilaritySearchParamsOrDict
|
|
2254
|
+
] = None,
|
|
2255
|
+
simple_retrieval_params: Optional[
|
|
2256
|
+
types.RetrieveMemoriesRequestSimpleRetrievalParamsOrDict
|
|
2257
|
+
] = None,
|
|
2258
|
+
config: Optional[types.RetrieveMemoriesConfigOrDict] = None,
|
|
2259
|
+
) -> types.RetrieveMemoriesResponse:
|
|
2260
|
+
"""
|
|
2261
|
+
Retrieves memories from a Memory Bank.
|
|
2262
|
+
"""
|
|
2263
|
+
|
|
2264
|
+
parameter_model = types._RetrieveMemoriesRequestParameters(
|
|
2265
|
+
name=name,
|
|
2266
|
+
scope=scope,
|
|
2267
|
+
similarity_search_params=similarity_search_params,
|
|
2268
|
+
simple_retrieval_params=simple_retrieval_params,
|
|
2269
|
+
config=config,
|
|
2270
|
+
)
|
|
2271
|
+
|
|
2272
|
+
request_url_dict: Optional[dict[str, str]]
|
|
2273
|
+
if not self._api_client.vertexai:
|
|
2274
|
+
raise ValueError(
|
|
2275
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
2276
|
+
)
|
|
2277
|
+
else:
|
|
2278
|
+
request_dict = _RetrieveMemoriesRequestParameters_to_vertex(parameter_model)
|
|
2279
|
+
request_url_dict = request_dict.get("_url")
|
|
2280
|
+
if request_url_dict:
|
|
2281
|
+
path = "{name}/memories:retrieve".format_map(request_url_dict)
|
|
2282
|
+
else:
|
|
2283
|
+
path = "{name}/memories:retrieve"
|
|
2284
|
+
|
|
2285
|
+
query_params = request_dict.get("_query")
|
|
2286
|
+
if query_params:
|
|
2287
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
2288
|
+
# TODO: remove the hack that pops config.
|
|
2289
|
+
request_dict.pop("config", None)
|
|
2290
|
+
|
|
2291
|
+
http_options: Optional[types.HttpOptions] = None
|
|
2292
|
+
if (
|
|
2293
|
+
parameter_model.config is not None
|
|
2294
|
+
and parameter_model.config.http_options is not None
|
|
2295
|
+
):
|
|
2296
|
+
http_options = parameter_model.config.http_options
|
|
2297
|
+
|
|
2298
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
2299
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
2300
|
+
|
|
2301
|
+
response = await self._api_client.async_request(
|
|
2302
|
+
"post", path, request_dict, http_options
|
|
2303
|
+
)
|
|
2304
|
+
|
|
2305
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
2306
|
+
|
|
2307
|
+
return_value = types.RetrieveMemoriesResponse._from_response(
|
|
2308
|
+
response=response_dict,
|
|
2309
|
+
kwargs=(
|
|
2310
|
+
{
|
|
2311
|
+
"config": {
|
|
2312
|
+
"response_schema": getattr(
|
|
2313
|
+
parameter_model.config, "response_schema", None
|
|
2314
|
+
),
|
|
2315
|
+
"response_json_schema": getattr(
|
|
2316
|
+
parameter_model.config, "response_json_schema", None
|
|
2317
|
+
),
|
|
2318
|
+
"include_all_fields": getattr(
|
|
2319
|
+
parameter_model.config, "include_all_fields", None
|
|
2320
|
+
),
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
if getattr(parameter_model, "config", None)
|
|
2324
|
+
else {}
|
|
2325
|
+
),
|
|
2326
|
+
)
|
|
2327
|
+
|
|
2328
|
+
self._api_client._verify_response(return_value)
|
|
2329
|
+
return return_value
|
|
2330
|
+
|
|
2331
|
+
async def retrieve_profiles(
|
|
2332
|
+
self,
|
|
2333
|
+
*,
|
|
2334
|
+
name: str,
|
|
2335
|
+
scope: dict[str, str],
|
|
2336
|
+
config: Optional[types.RetrieveMemoryProfilesConfigOrDict] = None,
|
|
2337
|
+
) -> types.RetrieveProfilesResponse:
|
|
2338
|
+
"""
|
|
2339
|
+
Retrieves memory profiles for a Memory Bank.
|
|
2340
|
+
|
|
2341
|
+
For example, you can use the following code to retrieve all memory profiles
|
|
2342
|
+
for scope `{'user_id': '123'}`:
|
|
2343
|
+
|
|
2344
|
+
```python
|
|
2345
|
+
result = client.memory_banks.memories.retrieve_profiles(
|
|
2346
|
+
name="projects/123/locations/us-central1/reasoningEngines/456",
|
|
2347
|
+
scope={"user_id": "123"}
|
|
2348
|
+
)
|
|
2349
|
+
|
|
2350
|
+
for profile in result.profiles.values():
|
|
2351
|
+
# Each profile is a dictionary corresponding to the relevant schema.
|
|
2352
|
+
print(profile.profile)
|
|
2353
|
+
```
|
|
2354
|
+
|
|
2355
|
+
Args:
|
|
2356
|
+
name (str): Required. A fully-qualified resource name or ID such as
|
|
2357
|
+
"projects/123/locations/us-central1/reasoningEngines/456".
|
|
2358
|
+
scope (dict[str, str]): Required. The scope of the memories to retrieve.
|
|
2359
|
+
A memory must have exactly the same scope as the scope provided here
|
|
2360
|
+
to be retrieved (i.e. same keys and values). Order does not matter,
|
|
2361
|
+
but it is case-sensitive.
|
|
2362
|
+
|
|
2363
|
+
Returns:
|
|
2364
|
+
RetrieveProfilesResponse: The retrieved memory profiles.
|
|
2365
|
+
|
|
2366
|
+
"""
|
|
2367
|
+
|
|
2368
|
+
parameter_model = types._RetrieveMemoryProfilesRequestParameters(
|
|
2369
|
+
name=name,
|
|
2370
|
+
scope=scope,
|
|
2371
|
+
config=config,
|
|
2372
|
+
)
|
|
2373
|
+
|
|
2374
|
+
request_url_dict: Optional[dict[str, str]]
|
|
2375
|
+
if not self._api_client.vertexai:
|
|
2376
|
+
raise ValueError(
|
|
2377
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
2378
|
+
)
|
|
2379
|
+
else:
|
|
2380
|
+
request_dict = _RetrieveMemoryProfilesRequestParameters_to_vertex(
|
|
2381
|
+
parameter_model
|
|
2382
|
+
)
|
|
2383
|
+
request_url_dict = request_dict.get("_url")
|
|
2384
|
+
if request_url_dict:
|
|
2385
|
+
path = "{name}/memories:retrieveProfiles".format_map(request_url_dict)
|
|
2386
|
+
else:
|
|
2387
|
+
path = "{name}/memories:retrieveProfiles"
|
|
2388
|
+
|
|
2389
|
+
query_params = request_dict.get("_query")
|
|
2390
|
+
if query_params:
|
|
2391
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
2392
|
+
# TODO: remove the hack that pops config.
|
|
2393
|
+
request_dict.pop("config", None)
|
|
2394
|
+
|
|
2395
|
+
http_options: Optional[types.HttpOptions] = None
|
|
2396
|
+
if (
|
|
2397
|
+
parameter_model.config is not None
|
|
2398
|
+
and parameter_model.config.http_options is not None
|
|
2399
|
+
):
|
|
2400
|
+
http_options = parameter_model.config.http_options
|
|
2401
|
+
|
|
2402
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
2403
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
2404
|
+
|
|
2405
|
+
response = await self._api_client.async_request(
|
|
2406
|
+
"post", path, request_dict, http_options
|
|
2407
|
+
)
|
|
2408
|
+
|
|
2409
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
2410
|
+
|
|
2411
|
+
return_value = types.RetrieveProfilesResponse._from_response(
|
|
2412
|
+
response=response_dict,
|
|
2413
|
+
kwargs=(
|
|
2414
|
+
{
|
|
2415
|
+
"config": {
|
|
2416
|
+
"response_schema": getattr(
|
|
2417
|
+
parameter_model.config, "response_schema", None
|
|
2418
|
+
),
|
|
2419
|
+
"response_json_schema": getattr(
|
|
2420
|
+
parameter_model.config, "response_json_schema", None
|
|
2421
|
+
),
|
|
2422
|
+
"include_all_fields": getattr(
|
|
2423
|
+
parameter_model.config, "include_all_fields", None
|
|
2424
|
+
),
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
if getattr(parameter_model, "config", None)
|
|
2428
|
+
else {}
|
|
2429
|
+
),
|
|
2430
|
+
)
|
|
2431
|
+
|
|
2432
|
+
self._api_client._verify_response(return_value)
|
|
2433
|
+
return return_value
|
|
2434
|
+
|
|
2435
|
+
async def _rollback(
|
|
2436
|
+
self,
|
|
2437
|
+
*,
|
|
2438
|
+
name: str,
|
|
2439
|
+
target_revision_id: str,
|
|
2440
|
+
config: Optional[types.RollbackMemoryConfigOrDict] = None,
|
|
2441
|
+
) -> types.RollbackMemoryOperation:
|
|
2442
|
+
"""
|
|
2443
|
+
Rollback a memory to a previous revision.
|
|
2444
|
+
"""
|
|
2445
|
+
|
|
2446
|
+
parameter_model = types._RollbackMemoryRequestParameters(
|
|
2447
|
+
name=name,
|
|
2448
|
+
target_revision_id=target_revision_id,
|
|
2449
|
+
config=config,
|
|
2450
|
+
)
|
|
2451
|
+
|
|
2452
|
+
request_url_dict: Optional[dict[str, str]]
|
|
2453
|
+
if not self._api_client.vertexai:
|
|
2454
|
+
raise ValueError(
|
|
2455
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
2456
|
+
)
|
|
2457
|
+
else:
|
|
2458
|
+
request_dict = _RollbackMemoryRequestParameters_to_vertex(parameter_model)
|
|
2459
|
+
request_url_dict = request_dict.get("_url")
|
|
2460
|
+
if request_url_dict:
|
|
2461
|
+
path = "{name}:rollback".format_map(request_url_dict)
|
|
2462
|
+
else:
|
|
2463
|
+
path = "{name}:rollback"
|
|
2464
|
+
|
|
2465
|
+
query_params = request_dict.get("_query")
|
|
2466
|
+
if query_params:
|
|
2467
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
2468
|
+
# TODO: remove the hack that pops config.
|
|
2469
|
+
request_dict.pop("config", None)
|
|
2470
|
+
|
|
2471
|
+
http_options: Optional[types.HttpOptions] = None
|
|
2472
|
+
if (
|
|
2473
|
+
parameter_model.config is not None
|
|
2474
|
+
and parameter_model.config.http_options is not None
|
|
2475
|
+
):
|
|
2476
|
+
http_options = parameter_model.config.http_options
|
|
2477
|
+
|
|
2478
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
2479
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
2480
|
+
|
|
2481
|
+
response = await self._api_client.async_request(
|
|
2482
|
+
"post", path, request_dict, http_options
|
|
2483
|
+
)
|
|
2484
|
+
|
|
2485
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
2486
|
+
|
|
2487
|
+
return_value = types.RollbackMemoryOperation._from_response(
|
|
2488
|
+
response=response_dict,
|
|
2489
|
+
kwargs=(
|
|
2490
|
+
{
|
|
2491
|
+
"config": {
|
|
2492
|
+
"response_schema": getattr(
|
|
2493
|
+
parameter_model.config, "response_schema", None
|
|
2494
|
+
),
|
|
2495
|
+
"response_json_schema": getattr(
|
|
2496
|
+
parameter_model.config, "response_json_schema", None
|
|
2497
|
+
),
|
|
2498
|
+
"include_all_fields": getattr(
|
|
2499
|
+
parameter_model.config, "include_all_fields", None
|
|
2500
|
+
),
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
if getattr(parameter_model, "config", None)
|
|
2504
|
+
else {}
|
|
2505
|
+
),
|
|
2506
|
+
)
|
|
2507
|
+
|
|
2508
|
+
self._api_client._verify_response(return_value)
|
|
2509
|
+
return return_value
|
|
2510
|
+
|
|
2511
|
+
async def _update(
|
|
2512
|
+
self,
|
|
2513
|
+
*,
|
|
2514
|
+
name: str,
|
|
2515
|
+
fact: Optional[str] = None,
|
|
2516
|
+
scope: Optional[dict[str, str]] = None,
|
|
2517
|
+
config: Optional[types.UpdateMemoryConfigOrDict] = None,
|
|
2518
|
+
) -> types.MemoryOperation:
|
|
2519
|
+
"""
|
|
2520
|
+
Updates a memory.
|
|
2521
|
+
"""
|
|
2522
|
+
|
|
2523
|
+
parameter_model = types._UpdateMemoryRequestParameters(
|
|
2524
|
+
name=name,
|
|
2525
|
+
fact=fact,
|
|
2526
|
+
scope=scope,
|
|
2527
|
+
config=config,
|
|
2528
|
+
)
|
|
2529
|
+
|
|
2530
|
+
request_url_dict: Optional[dict[str, str]]
|
|
2531
|
+
if not self._api_client.vertexai:
|
|
2532
|
+
raise ValueError(
|
|
2533
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
2534
|
+
)
|
|
2535
|
+
else:
|
|
2536
|
+
request_dict = _UpdateMemoryRequestParameters_to_vertex(parameter_model)
|
|
2537
|
+
request_url_dict = request_dict.get("_url")
|
|
2538
|
+
if request_url_dict:
|
|
2539
|
+
path = "{name}".format_map(request_url_dict)
|
|
2540
|
+
else:
|
|
2541
|
+
path = "{name}"
|
|
2542
|
+
|
|
2543
|
+
query_params = request_dict.get("_query")
|
|
2544
|
+
if query_params:
|
|
2545
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
2546
|
+
# TODO: remove the hack that pops config.
|
|
2547
|
+
request_dict.pop("config", None)
|
|
2548
|
+
|
|
2549
|
+
http_options: Optional[types.HttpOptions] = None
|
|
2550
|
+
if (
|
|
2551
|
+
parameter_model.config is not None
|
|
2552
|
+
and parameter_model.config.http_options is not None
|
|
2553
|
+
):
|
|
2554
|
+
http_options = parameter_model.config.http_options
|
|
2555
|
+
|
|
2556
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
2557
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
2558
|
+
|
|
2559
|
+
response = await self._api_client.async_request(
|
|
2560
|
+
"patch", path, request_dict, http_options
|
|
2561
|
+
)
|
|
2562
|
+
|
|
2563
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
2564
|
+
|
|
2565
|
+
return_value = types.MemoryOperation._from_response(
|
|
2566
|
+
response=response_dict,
|
|
2567
|
+
kwargs=(
|
|
2568
|
+
{
|
|
2569
|
+
"config": {
|
|
2570
|
+
"response_schema": getattr(
|
|
2571
|
+
parameter_model.config, "response_schema", None
|
|
2572
|
+
),
|
|
2573
|
+
"response_json_schema": getattr(
|
|
2574
|
+
parameter_model.config, "response_json_schema", None
|
|
2575
|
+
),
|
|
2576
|
+
"include_all_fields": getattr(
|
|
2577
|
+
parameter_model.config, "include_all_fields", None
|
|
2578
|
+
),
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
if getattr(parameter_model, "config", None)
|
|
2582
|
+
else {}
|
|
2583
|
+
),
|
|
2584
|
+
)
|
|
2585
|
+
|
|
2586
|
+
self._api_client._verify_response(return_value)
|
|
2587
|
+
return return_value
|
|
2588
|
+
|
|
2589
|
+
async def _purge(
|
|
2590
|
+
self,
|
|
2591
|
+
*,
|
|
2592
|
+
name: str,
|
|
2593
|
+
filter: Optional[str] = None,
|
|
2594
|
+
filter_groups: Optional[
|
|
2595
|
+
builtins.list[types.MemoryConjunctionFilterOrDict]
|
|
2596
|
+
] = None,
|
|
2597
|
+
force: Optional[bool] = None,
|
|
2598
|
+
config: Optional[types.PurgeMemoriesConfigOrDict] = None,
|
|
2599
|
+
) -> types.PurgeMemoriesOperation:
|
|
2600
|
+
"""
|
|
2601
|
+
Purges memories from a Memory Bank.
|
|
2602
|
+
"""
|
|
2603
|
+
|
|
2604
|
+
parameter_model = types._PurgeMemoriesRequestParameters(
|
|
2605
|
+
name=name,
|
|
2606
|
+
filter=filter,
|
|
2607
|
+
filter_groups=filter_groups,
|
|
2608
|
+
force=force,
|
|
2609
|
+
config=config,
|
|
2610
|
+
)
|
|
2611
|
+
|
|
2612
|
+
request_url_dict: Optional[dict[str, str]]
|
|
2613
|
+
if not self._api_client.vertexai:
|
|
2614
|
+
raise ValueError(
|
|
2615
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
2616
|
+
)
|
|
2617
|
+
else:
|
|
2618
|
+
request_dict = _PurgeMemoriesRequestParameters_to_vertex(parameter_model)
|
|
2619
|
+
request_url_dict = request_dict.get("_url")
|
|
2620
|
+
if request_url_dict:
|
|
2621
|
+
path = "{name}/memories:purge".format_map(request_url_dict)
|
|
2622
|
+
else:
|
|
2623
|
+
path = "{name}/memories:purge"
|
|
2624
|
+
|
|
2625
|
+
query_params = request_dict.get("_query")
|
|
2626
|
+
if query_params:
|
|
2627
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
2628
|
+
# TODO: remove the hack that pops config.
|
|
2629
|
+
request_dict.pop("config", None)
|
|
2630
|
+
|
|
2631
|
+
http_options: Optional[types.HttpOptions] = None
|
|
2632
|
+
if (
|
|
2633
|
+
parameter_model.config is not None
|
|
2634
|
+
and parameter_model.config.http_options is not None
|
|
2635
|
+
):
|
|
2636
|
+
http_options = parameter_model.config.http_options
|
|
2637
|
+
|
|
2638
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
2639
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
2640
|
+
|
|
2641
|
+
response = await self._api_client.async_request(
|
|
2642
|
+
"post", path, request_dict, http_options
|
|
2643
|
+
)
|
|
2644
|
+
|
|
2645
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
2646
|
+
|
|
2647
|
+
return_value = types.PurgeMemoriesOperation._from_response(
|
|
2648
|
+
response=response_dict,
|
|
2649
|
+
kwargs=(
|
|
2650
|
+
{
|
|
2651
|
+
"config": {
|
|
2652
|
+
"response_schema": getattr(
|
|
2653
|
+
parameter_model.config, "response_schema", None
|
|
2654
|
+
),
|
|
2655
|
+
"response_json_schema": getattr(
|
|
2656
|
+
parameter_model.config, "response_json_schema", None
|
|
2657
|
+
),
|
|
2658
|
+
"include_all_fields": getattr(
|
|
2659
|
+
parameter_model.config, "include_all_fields", None
|
|
2660
|
+
),
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
if getattr(parameter_model, "config", None)
|
|
2664
|
+
else {}
|
|
2665
|
+
),
|
|
2666
|
+
)
|
|
2667
|
+
|
|
2668
|
+
self._api_client._verify_response(return_value)
|
|
2669
|
+
return return_value
|
|
2670
|
+
|
|
2671
|
+
_revisions = None
|
|
2672
|
+
|
|
2673
|
+
@property
|
|
2674
|
+
def revisions(self) -> "memory_revisions_module.AsyncMemoryRevisions":
|
|
2675
|
+
if self._revisions is None:
|
|
2676
|
+
self._revisions = importlib.import_module(".memory_revisions", __package__)
|
|
2677
|
+
return self._revisions.AsyncMemoryRevisions(self._api_client) # type: ignore[no-any-return]
|
|
2678
|
+
|
|
2679
|
+
async def create(
|
|
2680
|
+
self,
|
|
2681
|
+
*,
|
|
2682
|
+
name: str,
|
|
2683
|
+
fact: str,
|
|
2684
|
+
scope: dict[str, str],
|
|
2685
|
+
config: Optional[types.MemoryConfigOrDict] = None,
|
|
2686
|
+
) -> types.MemoryOperation:
|
|
2687
|
+
"""Creates a new memory in Memory Bank.
|
|
2688
|
+
|
|
2689
|
+
Args:
|
|
2690
|
+
name (str):
|
|
2691
|
+
Required. The name of the memory to create.
|
|
2692
|
+
fact (str):
|
|
2693
|
+
Required. The fact to be stored in the memory.
|
|
2694
|
+
scope (dict[str, str]):
|
|
2695
|
+
Required. The scope of the memory. For example, {"user_id": "123"}.
|
|
2696
|
+
config (MemoryConfigOrDict):
|
|
2697
|
+
Optional. The configuration for the memory.
|
|
2698
|
+
|
|
2699
|
+
Returns:
|
|
2700
|
+
MemoryOperation: The operation for creating the memory.
|
|
2701
|
+
"""
|
|
2702
|
+
if config is None:
|
|
2703
|
+
config = types.MemoryConfig()
|
|
2704
|
+
elif isinstance(config, dict):
|
|
2705
|
+
config = types.MemoryConfig.model_validate(config)
|
|
2706
|
+
operation = await self._create(
|
|
2707
|
+
name=name,
|
|
2708
|
+
fact=fact,
|
|
2709
|
+
scope=scope,
|
|
2710
|
+
config=config,
|
|
2711
|
+
)
|
|
2712
|
+
if config.wait_for_completion:
|
|
2713
|
+
if not operation.done:
|
|
2714
|
+
operation = await _memory_bank_utils._await_async_operation(
|
|
2715
|
+
operation_name=operation.name,
|
|
2716
|
+
get_operation_fn=self._get_memory_operation,
|
|
2717
|
+
poll_interval_seconds=0.5,
|
|
2718
|
+
)
|
|
2719
|
+
# We need to make a call to get the memory because the operation
|
|
2720
|
+
# response might not contain the relevant fields.
|
|
2721
|
+
if operation.response:
|
|
2722
|
+
operation.response = await self.get(name=operation.response.name)
|
|
2723
|
+
elif operation.error:
|
|
2724
|
+
raise RuntimeError(f"Failed to create memory: {operation.error}")
|
|
2725
|
+
else:
|
|
2726
|
+
raise RuntimeError("Error creating memory.")
|
|
2727
|
+
return operation
|
|
2728
|
+
|
|
2729
|
+
async def generate(
|
|
2730
|
+
self,
|
|
2731
|
+
*,
|
|
2732
|
+
name: str,
|
|
2733
|
+
vertex_session_source: Optional[
|
|
2734
|
+
types.GenerateMemoriesRequestVertexSessionSourceOrDict
|
|
2735
|
+
] = None,
|
|
2736
|
+
direct_contents_source: Optional[
|
|
2737
|
+
types.GenerateMemoriesRequestDirectContentsSourceOrDict
|
|
2738
|
+
] = None,
|
|
2739
|
+
direct_memories_source: Optional[
|
|
2740
|
+
types.GenerateMemoriesRequestDirectMemoriesSourceOrDict
|
|
2741
|
+
] = None,
|
|
2742
|
+
scope: Optional[dict[str, str]] = None,
|
|
2743
|
+
config: Optional[types.GenerateMemoriesConfigOrDict] = None,
|
|
2744
|
+
) -> types.GenerateMemoriesOperation:
|
|
2745
|
+
"""Generates memories for Memory Bank.
|
|
2746
|
+
|
|
2747
|
+
Args:
|
|
2748
|
+
name (str):
|
|
2749
|
+
Required. The name of the Memory Bank to generate memories for.
|
|
2750
|
+
vertex_session_source (GenerateMemoriesRequestVertexSessionSource):
|
|
2751
|
+
Optional. The vertex session source to use for generating
|
|
2752
|
+
memories. Only one of vertex_session_source,
|
|
2753
|
+
direct_contents_source, or direct_memories_source can be
|
|
2754
|
+
specified.
|
|
2755
|
+
direct_contents_source(GenerateMemoriesRequestDirectContentsSource):
|
|
2756
|
+
Optional. The direct contents source to use for generating
|
|
2757
|
+
memories. Only one of vertex_session_source, direct_contents_source,
|
|
2758
|
+
or direct_memories_source can be specified.
|
|
2759
|
+
direct_memories_source (GenerateMemoriesRequestDirectMemoriesSource):
|
|
2760
|
+
Optional. The direct memories source to use for generating
|
|
2761
|
+
memories. Only one of vertex_session_source, direct_contents_source,
|
|
2762
|
+
or direct_memories_source can be specified.
|
|
2763
|
+
scope (dict[str, str]):
|
|
2764
|
+
Optional. The scope of the memories to generate. This is optional
|
|
2765
|
+
if vertex_session_source is used, otherwise it must be specified.
|
|
2766
|
+
config (GenerateMemoriesConfig):
|
|
2767
|
+
Optional. The configuration for the memories to generate.
|
|
2768
|
+
|
|
2769
|
+
Returns:
|
|
2770
|
+
GenerateMemoriesOperation:
|
|
2771
|
+
The operation for generating the memories.
|
|
2772
|
+
"""
|
|
2773
|
+
if config is None:
|
|
2774
|
+
config = types.GenerateMemoriesConfig()
|
|
2775
|
+
elif isinstance(config, dict):
|
|
2776
|
+
config = types.GenerateMemoriesConfig.model_validate(config)
|
|
2777
|
+
operation = await self._generate(
|
|
2778
|
+
name=name,
|
|
2779
|
+
vertex_session_source=vertex_session_source,
|
|
2780
|
+
direct_contents_source=direct_contents_source,
|
|
2781
|
+
direct_memories_source=direct_memories_source,
|
|
2782
|
+
scope=scope,
|
|
2783
|
+
config=config,
|
|
2784
|
+
)
|
|
2785
|
+
if config.wait_for_completion and not operation.done:
|
|
2786
|
+
operation = await _memory_bank_utils._await_async_operation(
|
|
2787
|
+
operation_name=operation.name,
|
|
2788
|
+
get_operation_fn=self._get_generate_memories_operation,
|
|
2789
|
+
poll_interval_seconds=0.5,
|
|
2790
|
+
)
|
|
2791
|
+
if operation.error:
|
|
2792
|
+
raise RuntimeError(f"Failed to generate memory: {operation.error}")
|
|
2793
|
+
return operation
|
|
2794
|
+
|
|
2795
|
+
async def list(
|
|
2796
|
+
self,
|
|
2797
|
+
*,
|
|
2798
|
+
name: str,
|
|
2799
|
+
config: Optional[types.ListMemoriesConfigOrDict] = None,
|
|
2800
|
+
) -> AsyncPager[types.Memory]:
|
|
2801
|
+
"""Lists memories in Memory Bank.
|
|
2802
|
+
|
|
2803
|
+
Args:
|
|
2804
|
+
name (str):
|
|
2805
|
+
Required. The name of the Memory Bank to list memories for.
|
|
2806
|
+
config (ListMemoriesConfig):
|
|
2807
|
+
Optional. The configuration for the memories to list.
|
|
2808
|
+
|
|
2809
|
+
Returns:
|
|
2810
|
+
AsyncPager[Memory]: An async pager of memories.
|
|
2811
|
+
"""
|
|
2812
|
+
|
|
2813
|
+
return AsyncPager(
|
|
2814
|
+
"memories",
|
|
2815
|
+
functools.partial(self._list, name=name),
|
|
2816
|
+
await self._list(name=name, config=config),
|
|
2817
|
+
config,
|
|
2818
|
+
)
|
|
2819
|
+
|
|
2820
|
+
async def retrieve(
|
|
2821
|
+
self,
|
|
2822
|
+
*,
|
|
2823
|
+
name: str,
|
|
2824
|
+
scope: dict[str, str],
|
|
2825
|
+
similarity_search_params: Optional[
|
|
2826
|
+
types.RetrieveMemoriesRequestSimilaritySearchParamsOrDict
|
|
2827
|
+
] = None,
|
|
2828
|
+
simple_retrieval_params: Optional[
|
|
2829
|
+
types.RetrieveMemoriesRequestSimpleRetrievalParamsOrDict
|
|
2830
|
+
] = None,
|
|
2831
|
+
config: Optional[types.RetrieveMemoriesConfigOrDict] = None,
|
|
2832
|
+
) -> AsyncPager[types.RetrieveMemoriesResponseRetrievedMemory]:
|
|
2833
|
+
"""Retrieves memories from Memory Bank.
|
|
2834
|
+
|
|
2835
|
+
Args:
|
|
2836
|
+
name (str):
|
|
2837
|
+
Required. The name of the Memory Bank to retrieve memories for.
|
|
2838
|
+
scope (dict[str, str]):
|
|
2839
|
+
Required. The scope of the memories to retrieve. For example,
|
|
2840
|
+
{"user_id": "123"}.
|
|
2841
|
+
similarity_search_params (RetrieveMemoriesRequestSimilaritySearchParams):
|
|
2842
|
+
Optional. The similarity search parameters to use for retrieving
|
|
2843
|
+
memories.
|
|
2844
|
+
simple_retrieval_params (RetrieveMemoriesRequestSimpleRetrievalParams):
|
|
2845
|
+
Optional. The simple retrieval parameters to use for retrieving
|
|
2846
|
+
memories.
|
|
2847
|
+
config (RetrieveMemoriesConfig):
|
|
2848
|
+
Optional. The configuration for the memories to retrieve.
|
|
2849
|
+
|
|
2850
|
+
Returns:
|
|
2851
|
+
AsyncPager[RetrieveMemoriesResponseRetrievedMemory]: An async pager of
|
|
2852
|
+
retrieved memories.
|
|
2853
|
+
"""
|
|
2854
|
+
return AsyncPager(
|
|
2855
|
+
"retrieved_memories",
|
|
2856
|
+
lambda config: self._retrieve(
|
|
2857
|
+
name=name,
|
|
2858
|
+
similarity_search_params=similarity_search_params,
|
|
2859
|
+
simple_retrieval_params=simple_retrieval_params,
|
|
2860
|
+
scope=scope,
|
|
2861
|
+
config=config,
|
|
2862
|
+
),
|
|
2863
|
+
await self._retrieve(
|
|
2864
|
+
name=name,
|
|
2865
|
+
similarity_search_params=similarity_search_params,
|
|
2866
|
+
simple_retrieval_params=simple_retrieval_params,
|
|
2867
|
+
scope=scope,
|
|
2868
|
+
config=config,
|
|
2869
|
+
),
|
|
2870
|
+
config,
|
|
2871
|
+
)
|
|
2872
|
+
|
|
2873
|
+
async def rollback(
|
|
2874
|
+
self,
|
|
2875
|
+
*,
|
|
2876
|
+
name: str,
|
|
2877
|
+
target_revision_id: str,
|
|
2878
|
+
config: Optional[types.RollbackMemoryConfigOrDict] = None,
|
|
2879
|
+
) -> types.RollbackMemoryOperation:
|
|
2880
|
+
"""Rolls back a memory to a previous revision.
|
|
2881
|
+
|
|
2882
|
+
Args:
|
|
2883
|
+
name (str):
|
|
2884
|
+
Required. The name of the memory to rollback.
|
|
2885
|
+
target_revision_id (str):
|
|
2886
|
+
Required. The revision ID to roll back to
|
|
2887
|
+
config (RollbackMemoryConfig):
|
|
2888
|
+
Optional. The configuration for the rollback.
|
|
2889
|
+
|
|
2890
|
+
Returns:
|
|
2891
|
+
RollbackMemoryOperation:
|
|
2892
|
+
The operation for rolling back the memory.
|
|
2893
|
+
"""
|
|
2894
|
+
if config is None:
|
|
2895
|
+
config = types.RollbackMemoryConfig()
|
|
2896
|
+
elif isinstance(config, dict):
|
|
2897
|
+
config = types.RollbackMemoryConfig.model_validate(config)
|
|
2898
|
+
operation = await self._rollback(
|
|
2899
|
+
name=name,
|
|
2900
|
+
target_revision_id=target_revision_id,
|
|
2901
|
+
config=config,
|
|
2902
|
+
)
|
|
2903
|
+
if config.wait_for_completion and not operation.done:
|
|
2904
|
+
operation = await _memory_bank_utils._await_async_operation(
|
|
2905
|
+
operation_name=operation.name,
|
|
2906
|
+
get_operation_fn=self._get_memory_operation,
|
|
2907
|
+
poll_interval_seconds=0.5,
|
|
2908
|
+
)
|
|
2909
|
+
if operation.error:
|
|
2910
|
+
raise RuntimeError(f"Failed to rollback memory: {operation.error}")
|
|
2911
|
+
return operation
|
|
2912
|
+
|
|
2913
|
+
async def purge(
|
|
2914
|
+
self,
|
|
2915
|
+
*,
|
|
2916
|
+
name: str,
|
|
2917
|
+
filter: Optional[str] = None,
|
|
2918
|
+
filter_groups: Optional[List[types.MemoryConjunctionFilter]] = None,
|
|
2919
|
+
force: bool = False,
|
|
2920
|
+
config: Optional[types.PurgeMemoriesConfigOrDict] = None,
|
|
2921
|
+
) -> types.PurgeMemoriesOperation:
|
|
2922
|
+
"""Purges memories from a Memory Bank.
|
|
2923
|
+
|
|
2924
|
+
Args:
|
|
2925
|
+
name (str):
|
|
2926
|
+
Required. The name of the Memory Bank to purge memories from.
|
|
2927
|
+
filter (str):
|
|
2928
|
+
Optional. The standard list filter to determine which memories to purge.
|
|
2929
|
+
filter_groups (list[MemoryConjunctionFilter]):
|
|
2930
|
+
Optional. Metadata filters that will be applied to the memories'
|
|
2931
|
+
`metadata` using OR logic. Filters are defined using disjunctive
|
|
2932
|
+
normal form (OR of ANDs).
|
|
2933
|
+
force (bool):
|
|
2934
|
+
Optional. Whether to force the purge operation. If false, the
|
|
2935
|
+
operation will be staged but not executed.
|
|
2936
|
+
config (PurgeMemoriesConfig):
|
|
2937
|
+
Optional. The configuration for the purge operation.
|
|
2938
|
+
|
|
2939
|
+
Returns:
|
|
2940
|
+
MemoryBankPurgeMemoriesOperation:
|
|
2941
|
+
The operation for purging the memories.
|
|
2942
|
+
"""
|
|
2943
|
+
if config is None:
|
|
2944
|
+
config = types.PurgeMemoriesConfig()
|
|
2945
|
+
elif isinstance(config, dict):
|
|
2946
|
+
config = types.PurgeMemoriesConfig.model_validate(config)
|
|
2947
|
+
operation = await self._purge(
|
|
2948
|
+
name=name,
|
|
2949
|
+
filter=filter,
|
|
2950
|
+
filter_groups=filter_groups,
|
|
2951
|
+
force=force,
|
|
2952
|
+
config=config,
|
|
2953
|
+
)
|
|
2954
|
+
if config.wait_for_completion and not operation.done:
|
|
2955
|
+
operation = await _memory_bank_utils._await_async_operation(
|
|
2956
|
+
operation_name=operation.name,
|
|
2957
|
+
get_operation_fn=self._get_memory_operation,
|
|
2958
|
+
poll_interval_seconds=0.5,
|
|
2959
|
+
)
|
|
2960
|
+
if operation.error:
|
|
2961
|
+
raise RuntimeError(f"Failed to purge memories: {operation.error}")
|
|
2962
|
+
return operation
|