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,1927 @@
|
|
|
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 importlib
|
|
19
|
+
import json
|
|
20
|
+
import logging
|
|
21
|
+
import typing
|
|
22
|
+
from typing import Any, AsyncIterator, Iterator, Optional, Union
|
|
23
|
+
from urllib.parse import urlencode
|
|
24
|
+
|
|
25
|
+
from google.genai import _api_module
|
|
26
|
+
from google.genai import _common
|
|
27
|
+
from google.genai._common import get_value_by_path as getv
|
|
28
|
+
from google.genai._common import set_value_by_path as setv
|
|
29
|
+
from google.genai.pagers import AsyncPager, Pager
|
|
30
|
+
|
|
31
|
+
from . import _memory_bank_utils
|
|
32
|
+
from . import types
|
|
33
|
+
|
|
34
|
+
if typing.TYPE_CHECKING:
|
|
35
|
+
from . import memories as memories_module
|
|
36
|
+
|
|
37
|
+
_ = memories_module
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
logger = logging.getLogger("agentplatform_genai.memorybanks")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _CreateMemoryBankConfig_to_vertex(
|
|
44
|
+
from_object: Union[dict[str, Any], object],
|
|
45
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
46
|
+
) -> dict[str, Any]:
|
|
47
|
+
to_object: dict[str, Any] = {}
|
|
48
|
+
|
|
49
|
+
if getv(from_object, ["display_name"]) is not None:
|
|
50
|
+
setv(parent_object, ["displayName"], getv(from_object, ["display_name"]))
|
|
51
|
+
|
|
52
|
+
if getv(from_object, ["description"]) is not None:
|
|
53
|
+
setv(parent_object, ["description"], getv(from_object, ["description"]))
|
|
54
|
+
|
|
55
|
+
if getv(from_object, ["encryption_spec"]) is not None:
|
|
56
|
+
setv(parent_object, ["encryptionSpec"], getv(from_object, ["encryption_spec"]))
|
|
57
|
+
|
|
58
|
+
return to_object
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _CreateMemoryBankRequestParameters_to_vertex(
|
|
62
|
+
from_object: Union[dict[str, Any], object],
|
|
63
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
64
|
+
) -> dict[str, Any]:
|
|
65
|
+
to_object: dict[str, Any] = {}
|
|
66
|
+
if getv(from_object, ["config"]) is not None:
|
|
67
|
+
_CreateMemoryBankConfig_to_vertex(getv(from_object, ["config"]), to_object)
|
|
68
|
+
|
|
69
|
+
if getv(from_object, ["memory_bank_config"]) is not None:
|
|
70
|
+
setv(
|
|
71
|
+
to_object,
|
|
72
|
+
["context_spec", "memory_bank_config"],
|
|
73
|
+
_ReasoningEngineContextSpecMemoryBankConfig_to_vertex(
|
|
74
|
+
getv(from_object, ["memory_bank_config"]), to_object
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
return to_object
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _DeleteMemoryBankRequestParameters_to_vertex(
|
|
82
|
+
from_object: Union[dict[str, Any], object],
|
|
83
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
84
|
+
) -> dict[str, Any]:
|
|
85
|
+
to_object: dict[str, Any] = {}
|
|
86
|
+
if getv(from_object, ["name"]) is not None:
|
|
87
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
88
|
+
|
|
89
|
+
if getv(from_object, ["force"]) is not None:
|
|
90
|
+
setv(to_object, ["force"], getv(from_object, ["force"]))
|
|
91
|
+
|
|
92
|
+
return to_object
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _GetMemoryBankOperationParameters_to_vertex(
|
|
96
|
+
from_object: Union[dict[str, Any], object],
|
|
97
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
98
|
+
) -> dict[str, Any]:
|
|
99
|
+
to_object: dict[str, Any] = {}
|
|
100
|
+
if getv(from_object, ["operation_name"]) is not None:
|
|
101
|
+
setv(
|
|
102
|
+
to_object, ["_url", "operationName"], getv(from_object, ["operation_name"])
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
return to_object
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _GetMemoryBankRequestParameters_to_vertex(
|
|
109
|
+
from_object: Union[dict[str, Any], object],
|
|
110
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
111
|
+
) -> dict[str, Any]:
|
|
112
|
+
to_object: dict[str, Any] = {}
|
|
113
|
+
if getv(from_object, ["name"]) is not None:
|
|
114
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
115
|
+
|
|
116
|
+
return to_object
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _IngestEventsConfig_to_vertex(
|
|
120
|
+
from_object: Union[dict[str, Any], object],
|
|
121
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
122
|
+
) -> dict[str, Any]:
|
|
123
|
+
to_object: dict[str, Any] = {}
|
|
124
|
+
|
|
125
|
+
if getv(from_object, ["force_flush"]) is not None:
|
|
126
|
+
setv(parent_object, ["forceFlush"], getv(from_object, ["force_flush"]))
|
|
127
|
+
|
|
128
|
+
if getv(from_object, ["revision_labels"]) is not None:
|
|
129
|
+
setv(parent_object, ["revisionLabels"], getv(from_object, ["revision_labels"]))
|
|
130
|
+
|
|
131
|
+
if getv(from_object, ["revision_expire_time"]) is not None:
|
|
132
|
+
setv(
|
|
133
|
+
parent_object,
|
|
134
|
+
["revisionExpireTime"],
|
|
135
|
+
getv(from_object, ["revision_expire_time"]),
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
if getv(from_object, ["revision_ttl"]) is not None:
|
|
139
|
+
setv(parent_object, ["revisionTtl"], getv(from_object, ["revision_ttl"]))
|
|
140
|
+
|
|
141
|
+
if getv(from_object, ["disable_memory_revisions"]) is not None:
|
|
142
|
+
setv(
|
|
143
|
+
parent_object,
|
|
144
|
+
["disableMemoryRevisions"],
|
|
145
|
+
getv(from_object, ["disable_memory_revisions"]),
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
if getv(from_object, ["metadata"]) is not None:
|
|
149
|
+
setv(
|
|
150
|
+
parent_object,
|
|
151
|
+
["metadata"],
|
|
152
|
+
{k: v for k, v in getv(from_object, ["metadata"]).items()},
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
if getv(from_object, ["metadata_merge_strategy"]) is not None:
|
|
156
|
+
setv(
|
|
157
|
+
parent_object,
|
|
158
|
+
["metadataMergeStrategy"],
|
|
159
|
+
getv(from_object, ["metadata_merge_strategy"]),
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
return to_object
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _IngestEventsRequestParameters_to_vertex(
|
|
166
|
+
from_object: Union[dict[str, Any], object],
|
|
167
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
168
|
+
) -> dict[str, Any]:
|
|
169
|
+
to_object: dict[str, Any] = {}
|
|
170
|
+
if getv(from_object, ["name"]) is not None:
|
|
171
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
172
|
+
|
|
173
|
+
if getv(from_object, ["stream_id"]) is not None:
|
|
174
|
+
setv(to_object, ["streamId"], getv(from_object, ["stream_id"]))
|
|
175
|
+
|
|
176
|
+
if getv(from_object, ["direct_contents_source"]) is not None:
|
|
177
|
+
setv(
|
|
178
|
+
to_object,
|
|
179
|
+
["directContentsSource"],
|
|
180
|
+
getv(from_object, ["direct_contents_source"]),
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
if getv(from_object, ["scope"]) is not None:
|
|
184
|
+
setv(to_object, ["scope"], getv(from_object, ["scope"]))
|
|
185
|
+
|
|
186
|
+
if getv(from_object, ["generation_trigger_config"]) is not None:
|
|
187
|
+
setv(
|
|
188
|
+
to_object,
|
|
189
|
+
["generationTriggerConfig"],
|
|
190
|
+
getv(from_object, ["generation_trigger_config"]),
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
if getv(from_object, ["config"]) is not None:
|
|
194
|
+
_IngestEventsConfig_to_vertex(getv(from_object, ["config"]), to_object)
|
|
195
|
+
|
|
196
|
+
return to_object
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _ListMemoryBanksConfig_to_vertex(
|
|
200
|
+
from_object: Union[dict[str, Any], object],
|
|
201
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
202
|
+
) -> dict[str, Any]:
|
|
203
|
+
to_object: dict[str, Any] = {}
|
|
204
|
+
|
|
205
|
+
if getv(from_object, ["page_size"]) is not None:
|
|
206
|
+
setv(parent_object, ["_query", "pageSize"], getv(from_object, ["page_size"]))
|
|
207
|
+
|
|
208
|
+
if getv(from_object, ["page_token"]) is not None:
|
|
209
|
+
setv(parent_object, ["_query", "pageToken"], getv(from_object, ["page_token"]))
|
|
210
|
+
|
|
211
|
+
return to_object
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _ListMemoryBanksRequestParameters_to_vertex(
|
|
215
|
+
from_object: Union[dict[str, Any], object],
|
|
216
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
217
|
+
) -> dict[str, Any]:
|
|
218
|
+
to_object: dict[str, Any] = {}
|
|
219
|
+
if getv(from_object, ["config"]) is not None:
|
|
220
|
+
_ListMemoryBanksConfig_to_vertex(getv(from_object, ["config"]), to_object)
|
|
221
|
+
|
|
222
|
+
return to_object
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def _ListReasoningEnginesResponse_from_vertex(
|
|
226
|
+
from_object: Union[dict[str, Any], object],
|
|
227
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
228
|
+
) -> dict[str, Any]:
|
|
229
|
+
to_object: dict[str, Any] = {}
|
|
230
|
+
if getv(from_object, ["sdkHttpResponse"]) is not None:
|
|
231
|
+
setv(to_object, ["sdk_http_response"], getv(from_object, ["sdkHttpResponse"]))
|
|
232
|
+
|
|
233
|
+
if getv(from_object, ["nextPageToken"]) is not None:
|
|
234
|
+
setv(to_object, ["next_page_token"], getv(from_object, ["nextPageToken"]))
|
|
235
|
+
|
|
236
|
+
if getv(from_object, ["reasoningEngines"]) is not None:
|
|
237
|
+
setv(
|
|
238
|
+
to_object,
|
|
239
|
+
["reasoning_engines"],
|
|
240
|
+
[
|
|
241
|
+
_ReasoningEngine_from_vertex(item, to_object)
|
|
242
|
+
for item in getv(from_object, ["reasoningEngines"])
|
|
243
|
+
],
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
return to_object
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _ManagedSemanticMemoryConfig_from_vertex(
|
|
250
|
+
from_object: Union[dict[str, Any], object],
|
|
251
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
252
|
+
) -> dict[str, Any]:
|
|
253
|
+
to_object: dict[str, Any] = {}
|
|
254
|
+
if getv(from_object, ["generationConfig"]) is not None:
|
|
255
|
+
setv(to_object, ["generation_config"], getv(from_object, ["generationConfig"]))
|
|
256
|
+
|
|
257
|
+
if getv(from_object, ["ttlConfig"]) is not None:
|
|
258
|
+
setv(to_object, ["ttl_config"], getv(from_object, ["ttlConfig"]))
|
|
259
|
+
|
|
260
|
+
if getv(from_object, ["disableMemoryRevisions"]) is not None:
|
|
261
|
+
setv(
|
|
262
|
+
to_object,
|
|
263
|
+
["disable_memory_revisions"],
|
|
264
|
+
getv(from_object, ["disableMemoryRevisions"]),
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
if getv(from_object, ["similaritySearchConfig"]) is not None:
|
|
268
|
+
setv(
|
|
269
|
+
to_object,
|
|
270
|
+
["similarity_search_config"],
|
|
271
|
+
getv(from_object, ["similaritySearchConfig"]),
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
if getv(from_object, ["unstructuredMemoryConfigs"]) is not None:
|
|
275
|
+
setv(
|
|
276
|
+
to_object,
|
|
277
|
+
["unstructured_memory_configs"],
|
|
278
|
+
[item for item in getv(from_object, ["unstructuredMemoryConfigs"])],
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
if getv(from_object, ["structuredMemoryConfigs"]) is not None:
|
|
282
|
+
setv(
|
|
283
|
+
to_object,
|
|
284
|
+
["structured_memory_configs"],
|
|
285
|
+
[
|
|
286
|
+
_StructuredMemoryConfig_from_vertex(item, to_object)
|
|
287
|
+
for item in getv(from_object, ["structuredMemoryConfigs"])
|
|
288
|
+
],
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
return to_object
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def _MemoryBankOperation_from_vertex(
|
|
295
|
+
from_object: Union[dict[str, Any], object],
|
|
296
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
297
|
+
) -> dict[str, Any]:
|
|
298
|
+
to_object: dict[str, Any] = {}
|
|
299
|
+
if getv(from_object, ["name"]) is not None:
|
|
300
|
+
setv(to_object, ["name"], getv(from_object, ["name"]))
|
|
301
|
+
|
|
302
|
+
if getv(from_object, ["metadata"]) is not None:
|
|
303
|
+
setv(to_object, ["metadata"], getv(from_object, ["metadata"]))
|
|
304
|
+
|
|
305
|
+
if getv(from_object, ["done"]) is not None:
|
|
306
|
+
setv(to_object, ["done"], getv(from_object, ["done"]))
|
|
307
|
+
|
|
308
|
+
if getv(from_object, ["error"]) is not None:
|
|
309
|
+
setv(to_object, ["error"], getv(from_object, ["error"]))
|
|
310
|
+
|
|
311
|
+
if getv(from_object, ["response"]) is not None:
|
|
312
|
+
setv(
|
|
313
|
+
to_object,
|
|
314
|
+
["response"],
|
|
315
|
+
_MemoryBank_from_vertex(getv(from_object, ["response"]), to_object),
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
return to_object
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def _MemoryBank_from_vertex(
|
|
322
|
+
from_object: Union[dict[str, Any], object],
|
|
323
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
324
|
+
) -> dict[str, Any]:
|
|
325
|
+
to_object: dict[str, Any] = {}
|
|
326
|
+
if getv(from_object, ["name"]) is not None:
|
|
327
|
+
setv(to_object, ["name"], getv(from_object, ["name"]))
|
|
328
|
+
|
|
329
|
+
if getv(from_object, ["managedSemanticMemoryConfig"]) is not None:
|
|
330
|
+
setv(
|
|
331
|
+
to_object,
|
|
332
|
+
["managed_semantic_memory_config"],
|
|
333
|
+
_ManagedSemanticMemoryConfig_from_vertex(
|
|
334
|
+
getv(from_object, ["managedSemanticMemoryConfig"]), to_object
|
|
335
|
+
),
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
if getv(from_object, ["displayName"]) is not None:
|
|
339
|
+
setv(to_object, ["display_name"], getv(from_object, ["displayName"]))
|
|
340
|
+
|
|
341
|
+
if getv(from_object, ["description"]) is not None:
|
|
342
|
+
setv(to_object, ["description"], getv(from_object, ["description"]))
|
|
343
|
+
|
|
344
|
+
if getv(from_object, ["createTime"]) is not None:
|
|
345
|
+
setv(to_object, ["create_time"], getv(from_object, ["createTime"]))
|
|
346
|
+
|
|
347
|
+
if getv(from_object, ["updateTime"]) is not None:
|
|
348
|
+
setv(to_object, ["update_time"], getv(from_object, ["updateTime"]))
|
|
349
|
+
|
|
350
|
+
if getv(from_object, ["encryptionSpec"]) is not None:
|
|
351
|
+
setv(to_object, ["encryption_spec"], getv(from_object, ["encryptionSpec"]))
|
|
352
|
+
|
|
353
|
+
return to_object
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def _ReasoningEngineContextSpecMemoryBankConfig_from_vertex(
|
|
357
|
+
from_object: Union[dict[str, Any], object],
|
|
358
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
359
|
+
) -> dict[str, Any]:
|
|
360
|
+
to_object: dict[str, Any] = {}
|
|
361
|
+
if getv(from_object, ["customizationConfigs"]) is not None:
|
|
362
|
+
setv(
|
|
363
|
+
to_object,
|
|
364
|
+
["customization_configs"],
|
|
365
|
+
[item for item in getv(from_object, ["customizationConfigs"])],
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
if getv(from_object, ["disableMemoryRevisions"]) is not None:
|
|
369
|
+
setv(
|
|
370
|
+
to_object,
|
|
371
|
+
["disable_memory_revisions"],
|
|
372
|
+
getv(from_object, ["disableMemoryRevisions"]),
|
|
373
|
+
)
|
|
374
|
+
|
|
375
|
+
if getv(from_object, ["generationConfig"]) is not None:
|
|
376
|
+
setv(to_object, ["generation_config"], getv(from_object, ["generationConfig"]))
|
|
377
|
+
|
|
378
|
+
if getv(from_object, ["similaritySearchConfig"]) is not None:
|
|
379
|
+
setv(
|
|
380
|
+
to_object,
|
|
381
|
+
["similarity_search_config"],
|
|
382
|
+
getv(from_object, ["similaritySearchConfig"]),
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
if getv(from_object, ["ttlConfig"]) is not None:
|
|
386
|
+
setv(to_object, ["ttl_config"], getv(from_object, ["ttlConfig"]))
|
|
387
|
+
|
|
388
|
+
if getv(from_object, ["structuredMemoryConfigs"]) is not None:
|
|
389
|
+
setv(
|
|
390
|
+
to_object,
|
|
391
|
+
["structured_memory_configs"],
|
|
392
|
+
[
|
|
393
|
+
_StructuredMemoryConfig_from_vertex(item, to_object)
|
|
394
|
+
for item in getv(from_object, ["structuredMemoryConfigs"])
|
|
395
|
+
],
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
return to_object
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def _ReasoningEngineContextSpecMemoryBankConfig_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
|
+
if getv(from_object, ["customization_configs"]) is not None:
|
|
407
|
+
setv(
|
|
408
|
+
to_object,
|
|
409
|
+
["customizationConfigs"],
|
|
410
|
+
[item for item in getv(from_object, ["customization_configs"])],
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
if getv(from_object, ["disable_memory_revisions"]) is not None:
|
|
414
|
+
setv(
|
|
415
|
+
to_object,
|
|
416
|
+
["disableMemoryRevisions"],
|
|
417
|
+
getv(from_object, ["disable_memory_revisions"]),
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
if getv(from_object, ["generation_config"]) is not None:
|
|
421
|
+
setv(to_object, ["generationConfig"], getv(from_object, ["generation_config"]))
|
|
422
|
+
|
|
423
|
+
if getv(from_object, ["similarity_search_config"]) is not None:
|
|
424
|
+
setv(
|
|
425
|
+
to_object,
|
|
426
|
+
["similaritySearchConfig"],
|
|
427
|
+
getv(from_object, ["similarity_search_config"]),
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
if getv(from_object, ["ttl_config"]) is not None:
|
|
431
|
+
setv(to_object, ["ttlConfig"], getv(from_object, ["ttl_config"]))
|
|
432
|
+
|
|
433
|
+
if getv(from_object, ["structured_memory_configs"]) is not None:
|
|
434
|
+
setv(
|
|
435
|
+
to_object,
|
|
436
|
+
["structuredMemoryConfigs"],
|
|
437
|
+
[
|
|
438
|
+
_StructuredMemoryConfig_to_vertex(item, to_object)
|
|
439
|
+
for item in getv(from_object, ["structured_memory_configs"])
|
|
440
|
+
],
|
|
441
|
+
)
|
|
442
|
+
|
|
443
|
+
return to_object
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
def _ReasoningEngineContextSpec_from_vertex(
|
|
447
|
+
from_object: Union[dict[str, Any], object],
|
|
448
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
449
|
+
) -> dict[str, Any]:
|
|
450
|
+
to_object: dict[str, Any] = {}
|
|
451
|
+
if getv(from_object, ["memoryBankConfig"]) is not None:
|
|
452
|
+
setv(
|
|
453
|
+
to_object,
|
|
454
|
+
["memory_bank_config"],
|
|
455
|
+
_ReasoningEngineContextSpecMemoryBankConfig_from_vertex(
|
|
456
|
+
getv(from_object, ["memoryBankConfig"]), to_object
|
|
457
|
+
),
|
|
458
|
+
)
|
|
459
|
+
|
|
460
|
+
return to_object
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def _ReasoningEngine_from_vertex(
|
|
464
|
+
from_object: Union[dict[str, Any], object],
|
|
465
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
466
|
+
) -> dict[str, Any]:
|
|
467
|
+
to_object: dict[str, Any] = {}
|
|
468
|
+
if getv(from_object, ["encryptionSpec"]) is not None:
|
|
469
|
+
setv(to_object, ["encryption_spec"], getv(from_object, ["encryptionSpec"]))
|
|
470
|
+
|
|
471
|
+
if getv(from_object, ["contextSpec"]) is not None:
|
|
472
|
+
setv(
|
|
473
|
+
to_object,
|
|
474
|
+
["context_spec"],
|
|
475
|
+
_ReasoningEngineContextSpec_from_vertex(
|
|
476
|
+
getv(from_object, ["contextSpec"]), to_object
|
|
477
|
+
),
|
|
478
|
+
)
|
|
479
|
+
|
|
480
|
+
if getv(from_object, ["createTime"]) is not None:
|
|
481
|
+
setv(to_object, ["create_time"], getv(from_object, ["createTime"]))
|
|
482
|
+
|
|
483
|
+
if getv(from_object, ["description"]) is not None:
|
|
484
|
+
setv(to_object, ["description"], getv(from_object, ["description"]))
|
|
485
|
+
|
|
486
|
+
if getv(from_object, ["displayName"]) is not None:
|
|
487
|
+
setv(to_object, ["display_name"], getv(from_object, ["displayName"]))
|
|
488
|
+
|
|
489
|
+
if getv(from_object, ["etag"]) is not None:
|
|
490
|
+
setv(to_object, ["etag"], getv(from_object, ["etag"]))
|
|
491
|
+
|
|
492
|
+
if getv(from_object, ["labels"]) is not None:
|
|
493
|
+
setv(to_object, ["labels"], getv(from_object, ["labels"]))
|
|
494
|
+
|
|
495
|
+
if getv(from_object, ["name"]) is not None:
|
|
496
|
+
setv(to_object, ["name"], getv(from_object, ["name"]))
|
|
497
|
+
|
|
498
|
+
if getv(from_object, ["spec"]) is not None:
|
|
499
|
+
setv(to_object, ["spec"], getv(from_object, ["spec"]))
|
|
500
|
+
|
|
501
|
+
if getv(from_object, ["updateTime"]) is not None:
|
|
502
|
+
setv(to_object, ["update_time"], getv(from_object, ["updateTime"]))
|
|
503
|
+
|
|
504
|
+
if getv(from_object, ["trafficConfig"]) is not None:
|
|
505
|
+
setv(to_object, ["traffic_config"], getv(from_object, ["trafficConfig"]))
|
|
506
|
+
|
|
507
|
+
return to_object
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
def _StructuredMemoryConfig_from_vertex(
|
|
511
|
+
from_object: Union[dict[str, Any], object],
|
|
512
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
513
|
+
) -> dict[str, Any]:
|
|
514
|
+
to_object: dict[str, Any] = {}
|
|
515
|
+
if getv(from_object, ["schemaConfigs"]) is not None:
|
|
516
|
+
setv(
|
|
517
|
+
to_object,
|
|
518
|
+
["schema_configs"],
|
|
519
|
+
[
|
|
520
|
+
_StructuredMemorySchemaConfig_from_vertex(item, to_object)
|
|
521
|
+
for item in getv(from_object, ["schemaConfigs"])
|
|
522
|
+
],
|
|
523
|
+
)
|
|
524
|
+
|
|
525
|
+
if getv(from_object, ["scopeKeys"]) is not None:
|
|
526
|
+
setv(to_object, ["scope_keys"], getv(from_object, ["scopeKeys"]))
|
|
527
|
+
|
|
528
|
+
return to_object
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
def _StructuredMemoryConfig_to_vertex(
|
|
532
|
+
from_object: Union[dict[str, Any], object],
|
|
533
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
534
|
+
) -> dict[str, Any]:
|
|
535
|
+
to_object: dict[str, Any] = {}
|
|
536
|
+
if getv(from_object, ["schema_configs"]) is not None:
|
|
537
|
+
setv(
|
|
538
|
+
to_object,
|
|
539
|
+
["schemaConfigs"],
|
|
540
|
+
[
|
|
541
|
+
_StructuredMemorySchemaConfig_to_vertex(item, to_object)
|
|
542
|
+
for item in getv(from_object, ["schema_configs"])
|
|
543
|
+
],
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
if getv(from_object, ["scope_keys"]) is not None:
|
|
547
|
+
setv(to_object, ["scopeKeys"], getv(from_object, ["scope_keys"]))
|
|
548
|
+
|
|
549
|
+
return to_object
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
def _StructuredMemorySchemaConfig_from_vertex(
|
|
553
|
+
from_object: Union[dict[str, Any], object],
|
|
554
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
555
|
+
) -> dict[str, Any]:
|
|
556
|
+
to_object: dict[str, Any] = {}
|
|
557
|
+
if getv(from_object, ["schema"]) is not None:
|
|
558
|
+
setv(to_object, ["memory_schema"], getv(from_object, ["schema"]))
|
|
559
|
+
|
|
560
|
+
if getv(from_object, ["id"]) is not None:
|
|
561
|
+
setv(to_object, ["id"], getv(from_object, ["id"]))
|
|
562
|
+
|
|
563
|
+
if getv(from_object, ["memoryType"]) is not None:
|
|
564
|
+
setv(to_object, ["memory_type"], getv(from_object, ["memoryType"]))
|
|
565
|
+
|
|
566
|
+
return to_object
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
def _StructuredMemorySchemaConfig_to_vertex(
|
|
570
|
+
from_object: Union[dict[str, Any], object],
|
|
571
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
572
|
+
) -> dict[str, Any]:
|
|
573
|
+
to_object: dict[str, Any] = {}
|
|
574
|
+
if getv(from_object, ["memory_schema"]) is not None:
|
|
575
|
+
setv(to_object, ["schema"], getv(from_object, ["memory_schema"]))
|
|
576
|
+
|
|
577
|
+
if getv(from_object, ["id"]) is not None:
|
|
578
|
+
setv(to_object, ["id"], getv(from_object, ["id"]))
|
|
579
|
+
|
|
580
|
+
if getv(from_object, ["memory_type"]) is not None:
|
|
581
|
+
setv(to_object, ["memoryType"], getv(from_object, ["memory_type"]))
|
|
582
|
+
|
|
583
|
+
return to_object
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
class MemoryBanks(_api_module.BaseModule):
|
|
587
|
+
|
|
588
|
+
def _create(
|
|
589
|
+
self,
|
|
590
|
+
*,
|
|
591
|
+
config: Optional[types.CreateMemoryBankConfigOrDict] = None,
|
|
592
|
+
memory_bank_config: Optional[
|
|
593
|
+
types.ReasoningEngineContextSpecMemoryBankConfigOrDict
|
|
594
|
+
] = None,
|
|
595
|
+
) -> types.MemoryBankOperation:
|
|
596
|
+
"""
|
|
597
|
+
Creates a new Memory Bank.
|
|
598
|
+
"""
|
|
599
|
+
|
|
600
|
+
parameter_model = types._CreateMemoryBankRequestParameters(
|
|
601
|
+
config=config,
|
|
602
|
+
memory_bank_config=memory_bank_config,
|
|
603
|
+
)
|
|
604
|
+
|
|
605
|
+
request_url_dict: Optional[dict[str, str]]
|
|
606
|
+
if not self._api_client.vertexai:
|
|
607
|
+
raise ValueError(
|
|
608
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
609
|
+
)
|
|
610
|
+
else:
|
|
611
|
+
request_dict = _CreateMemoryBankRequestParameters_to_vertex(parameter_model)
|
|
612
|
+
request_url_dict = request_dict.get("_url")
|
|
613
|
+
if request_url_dict:
|
|
614
|
+
path = "reasoningEngines".format_map(request_url_dict)
|
|
615
|
+
else:
|
|
616
|
+
path = "reasoningEngines"
|
|
617
|
+
|
|
618
|
+
query_params = request_dict.get("_query")
|
|
619
|
+
if query_params:
|
|
620
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
621
|
+
# TODO: remove the hack that pops config.
|
|
622
|
+
request_dict.pop("config", None)
|
|
623
|
+
|
|
624
|
+
http_options: Optional[types.HttpOptions] = None
|
|
625
|
+
if (
|
|
626
|
+
parameter_model.config is not None
|
|
627
|
+
and parameter_model.config.http_options is not None
|
|
628
|
+
):
|
|
629
|
+
http_options = parameter_model.config.http_options
|
|
630
|
+
|
|
631
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
632
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
633
|
+
|
|
634
|
+
response = self._api_client.request("post", path, request_dict, http_options)
|
|
635
|
+
|
|
636
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
637
|
+
|
|
638
|
+
if self._api_client.vertexai:
|
|
639
|
+
response_dict = _MemoryBankOperation_from_vertex(response_dict)
|
|
640
|
+
|
|
641
|
+
return_value = types.MemoryBankOperation._from_response(
|
|
642
|
+
response=response_dict,
|
|
643
|
+
kwargs=(
|
|
644
|
+
{
|
|
645
|
+
"config": {
|
|
646
|
+
"response_schema": getattr(
|
|
647
|
+
parameter_model.config, "response_schema", None
|
|
648
|
+
),
|
|
649
|
+
"response_json_schema": getattr(
|
|
650
|
+
parameter_model.config, "response_json_schema", None
|
|
651
|
+
),
|
|
652
|
+
"include_all_fields": getattr(
|
|
653
|
+
parameter_model.config, "include_all_fields", None
|
|
654
|
+
),
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
if getattr(parameter_model, "config", None)
|
|
658
|
+
else {}
|
|
659
|
+
),
|
|
660
|
+
)
|
|
661
|
+
|
|
662
|
+
self._api_client._verify_response(return_value)
|
|
663
|
+
return return_value
|
|
664
|
+
|
|
665
|
+
def _delete(
|
|
666
|
+
self,
|
|
667
|
+
*,
|
|
668
|
+
name: str,
|
|
669
|
+
force: Optional[bool] = None,
|
|
670
|
+
config: Optional[types.DeleteMemoryBankConfigOrDict] = None,
|
|
671
|
+
) -> types.DeleteMemoryBankOperation:
|
|
672
|
+
"""
|
|
673
|
+
Deletes a memory bank.
|
|
674
|
+
"""
|
|
675
|
+
|
|
676
|
+
parameter_model = types._DeleteMemoryBankRequestParameters(
|
|
677
|
+
name=name,
|
|
678
|
+
force=force,
|
|
679
|
+
config=config,
|
|
680
|
+
)
|
|
681
|
+
|
|
682
|
+
request_url_dict: Optional[dict[str, str]]
|
|
683
|
+
if not self._api_client.vertexai:
|
|
684
|
+
raise ValueError(
|
|
685
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
686
|
+
)
|
|
687
|
+
else:
|
|
688
|
+
request_dict = _DeleteMemoryBankRequestParameters_to_vertex(parameter_model)
|
|
689
|
+
request_url_dict = request_dict.get("_url")
|
|
690
|
+
if request_url_dict:
|
|
691
|
+
path = "{name}".format_map(request_url_dict)
|
|
692
|
+
else:
|
|
693
|
+
path = "{name}"
|
|
694
|
+
|
|
695
|
+
query_params = request_dict.get("_query")
|
|
696
|
+
if query_params:
|
|
697
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
698
|
+
# TODO: remove the hack that pops config.
|
|
699
|
+
request_dict.pop("config", None)
|
|
700
|
+
|
|
701
|
+
http_options: Optional[types.HttpOptions] = None
|
|
702
|
+
if (
|
|
703
|
+
parameter_model.config is not None
|
|
704
|
+
and parameter_model.config.http_options is not None
|
|
705
|
+
):
|
|
706
|
+
http_options = parameter_model.config.http_options
|
|
707
|
+
|
|
708
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
709
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
710
|
+
|
|
711
|
+
response = self._api_client.request("delete", path, request_dict, http_options)
|
|
712
|
+
|
|
713
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
714
|
+
|
|
715
|
+
return_value = types.DeleteMemoryBankOperation._from_response(
|
|
716
|
+
response=response_dict,
|
|
717
|
+
kwargs=(
|
|
718
|
+
{
|
|
719
|
+
"config": {
|
|
720
|
+
"response_schema": getattr(
|
|
721
|
+
parameter_model.config, "response_schema", None
|
|
722
|
+
),
|
|
723
|
+
"response_json_schema": getattr(
|
|
724
|
+
parameter_model.config, "response_json_schema", None
|
|
725
|
+
),
|
|
726
|
+
"include_all_fields": getattr(
|
|
727
|
+
parameter_model.config, "include_all_fields", None
|
|
728
|
+
),
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
if getattr(parameter_model, "config", None)
|
|
732
|
+
else {}
|
|
733
|
+
),
|
|
734
|
+
)
|
|
735
|
+
|
|
736
|
+
self._api_client._verify_response(return_value)
|
|
737
|
+
return return_value
|
|
738
|
+
|
|
739
|
+
def _get(
|
|
740
|
+
self, *, name: str, config: Optional[types.GetMemoryBankConfigOrDict] = None
|
|
741
|
+
) -> types.ReasoningEngine:
|
|
742
|
+
"""
|
|
743
|
+
Get a Memory Bank instance.
|
|
744
|
+
"""
|
|
745
|
+
|
|
746
|
+
parameter_model = types._GetMemoryBankRequestParameters(
|
|
747
|
+
name=name,
|
|
748
|
+
config=config,
|
|
749
|
+
)
|
|
750
|
+
|
|
751
|
+
request_url_dict: Optional[dict[str, str]]
|
|
752
|
+
if not self._api_client.vertexai:
|
|
753
|
+
raise ValueError(
|
|
754
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
755
|
+
)
|
|
756
|
+
else:
|
|
757
|
+
request_dict = _GetMemoryBankRequestParameters_to_vertex(parameter_model)
|
|
758
|
+
request_url_dict = request_dict.get("_url")
|
|
759
|
+
if request_url_dict:
|
|
760
|
+
path = "{name}".format_map(request_url_dict)
|
|
761
|
+
else:
|
|
762
|
+
path = "{name}"
|
|
763
|
+
|
|
764
|
+
query_params = request_dict.get("_query")
|
|
765
|
+
if query_params:
|
|
766
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
767
|
+
# TODO: remove the hack that pops config.
|
|
768
|
+
request_dict.pop("config", None)
|
|
769
|
+
|
|
770
|
+
http_options: Optional[types.HttpOptions] = None
|
|
771
|
+
if (
|
|
772
|
+
parameter_model.config is not None
|
|
773
|
+
and parameter_model.config.http_options is not None
|
|
774
|
+
):
|
|
775
|
+
http_options = parameter_model.config.http_options
|
|
776
|
+
|
|
777
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
778
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
779
|
+
|
|
780
|
+
response = self._api_client.request("get", path, request_dict, http_options)
|
|
781
|
+
|
|
782
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
783
|
+
|
|
784
|
+
if self._api_client.vertexai:
|
|
785
|
+
response_dict = _ReasoningEngine_from_vertex(response_dict)
|
|
786
|
+
|
|
787
|
+
return_value = types.ReasoningEngine._from_response(
|
|
788
|
+
response=response_dict,
|
|
789
|
+
kwargs=(
|
|
790
|
+
{
|
|
791
|
+
"config": {
|
|
792
|
+
"response_schema": getattr(
|
|
793
|
+
parameter_model.config, "response_schema", None
|
|
794
|
+
),
|
|
795
|
+
"response_json_schema": getattr(
|
|
796
|
+
parameter_model.config, "response_json_schema", None
|
|
797
|
+
),
|
|
798
|
+
"include_all_fields": getattr(
|
|
799
|
+
parameter_model.config, "include_all_fields", None
|
|
800
|
+
),
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
if getattr(parameter_model, "config", None)
|
|
804
|
+
else {}
|
|
805
|
+
),
|
|
806
|
+
)
|
|
807
|
+
|
|
808
|
+
self._api_client._verify_response(return_value)
|
|
809
|
+
return return_value
|
|
810
|
+
|
|
811
|
+
def _ingest_events(
|
|
812
|
+
self,
|
|
813
|
+
*,
|
|
814
|
+
name: str,
|
|
815
|
+
stream_id: Optional[str] = None,
|
|
816
|
+
direct_contents_source: Optional[
|
|
817
|
+
types.IngestionDirectContentsSourceOrDict
|
|
818
|
+
] = None,
|
|
819
|
+
scope: Optional[dict[str, str]] = None,
|
|
820
|
+
generation_trigger_config: Optional[
|
|
821
|
+
types.MemoryGenerationTriggerConfigOrDict
|
|
822
|
+
] = None,
|
|
823
|
+
config: Optional[types.IngestEventsConfigOrDict] = None,
|
|
824
|
+
) -> types.MemoryBankIngestEventsOperation:
|
|
825
|
+
"""
|
|
826
|
+
Ingest events into a Memory Bank.
|
|
827
|
+
"""
|
|
828
|
+
|
|
829
|
+
parameter_model = types._IngestEventsRequestParameters(
|
|
830
|
+
name=name,
|
|
831
|
+
stream_id=stream_id,
|
|
832
|
+
direct_contents_source=direct_contents_source,
|
|
833
|
+
scope=scope,
|
|
834
|
+
generation_trigger_config=generation_trigger_config,
|
|
835
|
+
config=config,
|
|
836
|
+
)
|
|
837
|
+
|
|
838
|
+
request_url_dict: Optional[dict[str, str]]
|
|
839
|
+
if not self._api_client.vertexai:
|
|
840
|
+
raise ValueError(
|
|
841
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
842
|
+
)
|
|
843
|
+
else:
|
|
844
|
+
request_dict = _IngestEventsRequestParameters_to_vertex(parameter_model)
|
|
845
|
+
request_url_dict = request_dict.get("_url")
|
|
846
|
+
if request_url_dict:
|
|
847
|
+
path = "{name}/memories:ingestEvents".format_map(request_url_dict)
|
|
848
|
+
else:
|
|
849
|
+
path = "{name}/memories:ingestEvents"
|
|
850
|
+
|
|
851
|
+
query_params = request_dict.get("_query")
|
|
852
|
+
if query_params:
|
|
853
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
854
|
+
# TODO: remove the hack that pops config.
|
|
855
|
+
request_dict.pop("config", None)
|
|
856
|
+
|
|
857
|
+
http_options: Optional[types.HttpOptions] = None
|
|
858
|
+
if (
|
|
859
|
+
parameter_model.config is not None
|
|
860
|
+
and parameter_model.config.http_options is not None
|
|
861
|
+
):
|
|
862
|
+
http_options = parameter_model.config.http_options
|
|
863
|
+
|
|
864
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
865
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
866
|
+
|
|
867
|
+
response = self._api_client.request("post", path, request_dict, http_options)
|
|
868
|
+
|
|
869
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
870
|
+
|
|
871
|
+
return_value = types.MemoryBankIngestEventsOperation._from_response(
|
|
872
|
+
response=response_dict,
|
|
873
|
+
kwargs=(
|
|
874
|
+
{
|
|
875
|
+
"config": {
|
|
876
|
+
"response_schema": getattr(
|
|
877
|
+
parameter_model.config, "response_schema", None
|
|
878
|
+
),
|
|
879
|
+
"response_json_schema": getattr(
|
|
880
|
+
parameter_model.config, "response_json_schema", None
|
|
881
|
+
),
|
|
882
|
+
"include_all_fields": getattr(
|
|
883
|
+
parameter_model.config, "include_all_fields", None
|
|
884
|
+
),
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
if getattr(parameter_model, "config", None)
|
|
888
|
+
else {}
|
|
889
|
+
),
|
|
890
|
+
)
|
|
891
|
+
|
|
892
|
+
self._api_client._verify_response(return_value)
|
|
893
|
+
return return_value
|
|
894
|
+
|
|
895
|
+
def _list(
|
|
896
|
+
self, *, config: Optional[types.ListMemoryBanksConfigOrDict] = None
|
|
897
|
+
) -> types.ListReasoningEnginesResponse:
|
|
898
|
+
"""
|
|
899
|
+
Lists Memory Banks.
|
|
900
|
+
"""
|
|
901
|
+
|
|
902
|
+
parameter_model = types._ListMemoryBanksRequestParameters(
|
|
903
|
+
config=config,
|
|
904
|
+
)
|
|
905
|
+
|
|
906
|
+
request_url_dict: Optional[dict[str, str]]
|
|
907
|
+
if not self._api_client.vertexai:
|
|
908
|
+
raise ValueError(
|
|
909
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
910
|
+
)
|
|
911
|
+
else:
|
|
912
|
+
request_dict = _ListMemoryBanksRequestParameters_to_vertex(parameter_model)
|
|
913
|
+
request_url_dict = request_dict.get("_url")
|
|
914
|
+
if request_url_dict:
|
|
915
|
+
path = "reasoningEngines".format_map(request_url_dict)
|
|
916
|
+
else:
|
|
917
|
+
path = "reasoningEngines"
|
|
918
|
+
|
|
919
|
+
query_params = request_dict.get("_query")
|
|
920
|
+
if query_params:
|
|
921
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
922
|
+
# TODO: remove the hack that pops config.
|
|
923
|
+
request_dict.pop("config", None)
|
|
924
|
+
|
|
925
|
+
http_options: Optional[types.HttpOptions] = None
|
|
926
|
+
if (
|
|
927
|
+
parameter_model.config is not None
|
|
928
|
+
and parameter_model.config.http_options is not None
|
|
929
|
+
):
|
|
930
|
+
http_options = parameter_model.config.http_options
|
|
931
|
+
|
|
932
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
933
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
934
|
+
|
|
935
|
+
response = self._api_client.request("get", path, request_dict, http_options)
|
|
936
|
+
|
|
937
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
938
|
+
|
|
939
|
+
if self._api_client.vertexai:
|
|
940
|
+
response_dict = _ListReasoningEnginesResponse_from_vertex(response_dict)
|
|
941
|
+
|
|
942
|
+
return_value = types.ListReasoningEnginesResponse._from_response(
|
|
943
|
+
response=response_dict,
|
|
944
|
+
kwargs=(
|
|
945
|
+
{
|
|
946
|
+
"config": {
|
|
947
|
+
"response_schema": getattr(
|
|
948
|
+
parameter_model.config, "response_schema", None
|
|
949
|
+
),
|
|
950
|
+
"response_json_schema": getattr(
|
|
951
|
+
parameter_model.config, "response_json_schema", None
|
|
952
|
+
),
|
|
953
|
+
"include_all_fields": getattr(
|
|
954
|
+
parameter_model.config, "include_all_fields", None
|
|
955
|
+
),
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
if getattr(parameter_model, "config", None)
|
|
959
|
+
else {}
|
|
960
|
+
),
|
|
961
|
+
)
|
|
962
|
+
|
|
963
|
+
self._api_client._verify_response(return_value)
|
|
964
|
+
return return_value
|
|
965
|
+
|
|
966
|
+
def _get_memory_bank_operation(
|
|
967
|
+
self,
|
|
968
|
+
*,
|
|
969
|
+
operation_name: str,
|
|
970
|
+
config: Optional[types.GetMemoryBankOperationConfigOrDict] = None,
|
|
971
|
+
) -> types.MemoryBankOperation:
|
|
972
|
+
parameter_model = types._GetMemoryBankOperationParameters(
|
|
973
|
+
operation_name=operation_name,
|
|
974
|
+
config=config,
|
|
975
|
+
)
|
|
976
|
+
|
|
977
|
+
request_url_dict: Optional[dict[str, str]]
|
|
978
|
+
if not self._api_client.vertexai:
|
|
979
|
+
raise ValueError(
|
|
980
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
981
|
+
)
|
|
982
|
+
else:
|
|
983
|
+
request_dict = _GetMemoryBankOperationParameters_to_vertex(parameter_model)
|
|
984
|
+
request_url_dict = request_dict.get("_url")
|
|
985
|
+
if request_url_dict:
|
|
986
|
+
path = "{operationName}".format_map(request_url_dict)
|
|
987
|
+
else:
|
|
988
|
+
path = "{operationName}"
|
|
989
|
+
|
|
990
|
+
query_params = request_dict.get("_query")
|
|
991
|
+
if query_params:
|
|
992
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
993
|
+
# TODO: remove the hack that pops config.
|
|
994
|
+
request_dict.pop("config", None)
|
|
995
|
+
|
|
996
|
+
http_options: Optional[types.HttpOptions] = None
|
|
997
|
+
if (
|
|
998
|
+
parameter_model.config is not None
|
|
999
|
+
and parameter_model.config.http_options is not None
|
|
1000
|
+
):
|
|
1001
|
+
http_options = parameter_model.config.http_options
|
|
1002
|
+
|
|
1003
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1004
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1005
|
+
|
|
1006
|
+
response = self._api_client.request("get", path, request_dict, http_options)
|
|
1007
|
+
|
|
1008
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1009
|
+
|
|
1010
|
+
if self._api_client.vertexai:
|
|
1011
|
+
response_dict = _MemoryBankOperation_from_vertex(response_dict)
|
|
1012
|
+
|
|
1013
|
+
return_value = types.MemoryBankOperation._from_response(
|
|
1014
|
+
response=response_dict,
|
|
1015
|
+
kwargs=(
|
|
1016
|
+
{
|
|
1017
|
+
"config": {
|
|
1018
|
+
"response_schema": getattr(
|
|
1019
|
+
parameter_model.config, "response_schema", None
|
|
1020
|
+
),
|
|
1021
|
+
"response_json_schema": getattr(
|
|
1022
|
+
parameter_model.config, "response_json_schema", None
|
|
1023
|
+
),
|
|
1024
|
+
"include_all_fields": getattr(
|
|
1025
|
+
parameter_model.config, "include_all_fields", None
|
|
1026
|
+
),
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
if getattr(parameter_model, "config", None)
|
|
1030
|
+
else {}
|
|
1031
|
+
),
|
|
1032
|
+
)
|
|
1033
|
+
|
|
1034
|
+
self._api_client._verify_response(return_value)
|
|
1035
|
+
return return_value
|
|
1036
|
+
|
|
1037
|
+
_memories = None
|
|
1038
|
+
|
|
1039
|
+
@property
|
|
1040
|
+
def memories(self) -> "memories_module.Memories":
|
|
1041
|
+
if self._memories is None:
|
|
1042
|
+
self._memories = importlib.import_module(".memories", __package__)
|
|
1043
|
+
return self._memories.Memories(self._api_client) # type: ignore[no-any-return]
|
|
1044
|
+
|
|
1045
|
+
def create(
|
|
1046
|
+
self,
|
|
1047
|
+
*,
|
|
1048
|
+
managed_semantic_memory_config: Optional[
|
|
1049
|
+
types.ManagedSemanticMemoryConfigOrDict
|
|
1050
|
+
] = None,
|
|
1051
|
+
config: Optional[types.CreateMemoryBankConfigOrDict] = None,
|
|
1052
|
+
) -> types.MemoryBank:
|
|
1053
|
+
"""Creates a new Memory Bank."""
|
|
1054
|
+
memory_bank_config = (
|
|
1055
|
+
_memory_bank_utils._managed_semantic_memory_config_to_memory_bank_config(
|
|
1056
|
+
managed_semantic_memory_config
|
|
1057
|
+
)
|
|
1058
|
+
)
|
|
1059
|
+
|
|
1060
|
+
operation = self._create(
|
|
1061
|
+
memory_bank_config=memory_bank_config,
|
|
1062
|
+
config=config,
|
|
1063
|
+
)
|
|
1064
|
+
|
|
1065
|
+
operation = _memory_bank_utils._await_operation(
|
|
1066
|
+
operation_name=operation.name,
|
|
1067
|
+
get_operation_fn=self._get_memory_bank_operation,
|
|
1068
|
+
)
|
|
1069
|
+
if operation.error:
|
|
1070
|
+
raise RuntimeError(operation.error)
|
|
1071
|
+
if not operation.response:
|
|
1072
|
+
raise RuntimeError(
|
|
1073
|
+
f"Memory Bank creation completed without a response: {operation}"
|
|
1074
|
+
)
|
|
1075
|
+
memory_bank = types.MemoryBank(name=operation.response.name)
|
|
1076
|
+
return memory_bank
|
|
1077
|
+
|
|
1078
|
+
def delete(
|
|
1079
|
+
self,
|
|
1080
|
+
*,
|
|
1081
|
+
name: str,
|
|
1082
|
+
force: Optional[bool] = None,
|
|
1083
|
+
config: Optional[types.DeleteMemoryBankConfigOrDict] = None,
|
|
1084
|
+
) -> types.DeleteMemoryBankOperation:
|
|
1085
|
+
"""
|
|
1086
|
+
Delete a Memory Bank resource.
|
|
1087
|
+
|
|
1088
|
+
Args:
|
|
1089
|
+
name (str):
|
|
1090
|
+
Required. The name of the Memory Bank to be deleted. Format:
|
|
1091
|
+
`projects/{project}/locations/{location}/memoryBanks/{resource_id}`
|
|
1092
|
+
or `memoryBanks/{resource_id}`.
|
|
1093
|
+
force (bool):
|
|
1094
|
+
Optional. If set to True, child resources will also be deleted.
|
|
1095
|
+
Otherwise, the request will fail with FAILED_PRECONDITION error when
|
|
1096
|
+
the Memory Bank has undeleted child resources. Defaults to False.
|
|
1097
|
+
config (DeleteMemoryBankConfig):
|
|
1098
|
+
Optional. Additional configurations for deleting the Memory Bank.
|
|
1099
|
+
"""
|
|
1100
|
+
logger.info(f"Deleting MemoryBank resource: {name}")
|
|
1101
|
+
operation = self._delete(name=name, force=force, config=config)
|
|
1102
|
+
logger.info(f"Started MemoryBank delete operation: {operation.name}")
|
|
1103
|
+
return operation
|
|
1104
|
+
|
|
1105
|
+
def ingest_events(
|
|
1106
|
+
self,
|
|
1107
|
+
*,
|
|
1108
|
+
name: str,
|
|
1109
|
+
scope: dict[str, str],
|
|
1110
|
+
stream_id: str = "",
|
|
1111
|
+
direct_contents_source: Optional[
|
|
1112
|
+
types.IngestionDirectContentsSourceOrDict
|
|
1113
|
+
] = None,
|
|
1114
|
+
generation_trigger_config: Optional[
|
|
1115
|
+
types.MemoryGenerationTriggerConfigOrDict
|
|
1116
|
+
] = None,
|
|
1117
|
+
config: Optional[types.IngestEventsConfigOrDict] = None,
|
|
1118
|
+
) -> types.MemoryBankIngestEventsOperation:
|
|
1119
|
+
"""Ingests events into Memory Bank.
|
|
1120
|
+
|
|
1121
|
+
Example usage:
|
|
1122
|
+
```
|
|
1123
|
+
client.memory_banks.ingest_events(
|
|
1124
|
+
name="projects/test-project/locations/us-central1/reasoningEngines/test-agent-engine",
|
|
1125
|
+
scope={"user_id": "test-user-id"},
|
|
1126
|
+
direct_contents_source={
|
|
1127
|
+
"events": [
|
|
1128
|
+
{
|
|
1129
|
+
"content": {
|
|
1130
|
+
"role": "user",
|
|
1131
|
+
"parts": [
|
|
1132
|
+
{"text": "I am a software engineer."}
|
|
1133
|
+
],
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
]
|
|
1137
|
+
},
|
|
1138
|
+
generation_trigger_config={
|
|
1139
|
+
"generation_rule": {
|
|
1140
|
+
"idle_duration": "60s"
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
)
|
|
1144
|
+
```
|
|
1145
|
+
|
|
1146
|
+
Args:
|
|
1147
|
+
name (str):
|
|
1148
|
+
Required. The name of the Memory Bank to ingest events into.
|
|
1149
|
+
scope (dict[str, str]):
|
|
1150
|
+
Required. The scope of the events to ingest. For example,
|
|
1151
|
+
{"user_id": "123"}.
|
|
1152
|
+
stream_id (str):
|
|
1153
|
+
Optional. The ID of the stream to ingest events into. If not
|
|
1154
|
+
specified, the events will be ingested into the default stream.
|
|
1155
|
+
direct_contents_source (IngestionDirectContentsSource):
|
|
1156
|
+
The direct contents source, containing the events to ingest.
|
|
1157
|
+
generation_trigger_config (MemoryGenerationTriggerConfig):
|
|
1158
|
+
Optional. The configuration for the generation trigger config.
|
|
1159
|
+
config (IngestEventsConfig):
|
|
1160
|
+
Optional. The configuration for the ingest events operation.
|
|
1161
|
+
|
|
1162
|
+
Returns:
|
|
1163
|
+
IngestEventsOperation:
|
|
1164
|
+
The operation for ingesting the events.
|
|
1165
|
+
"""
|
|
1166
|
+
if config is None:
|
|
1167
|
+
config = types.IngestEventsConfig()
|
|
1168
|
+
elif isinstance(config, dict):
|
|
1169
|
+
config = types.IngestEventsConfig.model_validate(config)
|
|
1170
|
+
operation = self._ingest_events(
|
|
1171
|
+
name=name,
|
|
1172
|
+
scope=scope,
|
|
1173
|
+
stream_id=stream_id,
|
|
1174
|
+
generation_trigger_config=generation_trigger_config,
|
|
1175
|
+
direct_contents_source=direct_contents_source,
|
|
1176
|
+
config=config,
|
|
1177
|
+
)
|
|
1178
|
+
if config.wait_for_completion and not operation.done:
|
|
1179
|
+
operation = _memory_bank_utils._await_operation(
|
|
1180
|
+
operation_name=operation.name,
|
|
1181
|
+
get_operation_fn=self._get_memory_bank_operation,
|
|
1182
|
+
poll_interval_seconds=0.5,
|
|
1183
|
+
)
|
|
1184
|
+
if operation.error:
|
|
1185
|
+
raise RuntimeError(f"Failed to ingest events: {operation.error}")
|
|
1186
|
+
return operation
|
|
1187
|
+
|
|
1188
|
+
def get(
|
|
1189
|
+
self,
|
|
1190
|
+
*,
|
|
1191
|
+
name: str,
|
|
1192
|
+
config: Optional[types.GetMemoryBankConfigOrDict] = None,
|
|
1193
|
+
) -> types.MemoryBank:
|
|
1194
|
+
"""Gets a Memory Bank.
|
|
1195
|
+
|
|
1196
|
+
Args:
|
|
1197
|
+
name (str):
|
|
1198
|
+
Required. A fully-qualified resource name or ID such as
|
|
1199
|
+
"projects/123/locations/us-central1/reasoningEngines/456" or
|
|
1200
|
+
a shortened name such as "reasoningEngines/456".
|
|
1201
|
+
"""
|
|
1202
|
+
api_resource = self._get(name=name, config=config)
|
|
1203
|
+
memory_bank = _memory_bank_utils._reasoning_engine_to_memory_bank(api_resource)
|
|
1204
|
+
return memory_bank
|
|
1205
|
+
|
|
1206
|
+
def list(
|
|
1207
|
+
self, *, config: Optional[types.ListMemoryBanksConfigOrDict] = None
|
|
1208
|
+
) -> Iterator[types.MemoryBank]:
|
|
1209
|
+
"""List all instances of Memory Bank matching the filter.
|
|
1210
|
+
|
|
1211
|
+
Example Usage:
|
|
1212
|
+
|
|
1213
|
+
.. code-block:: python
|
|
1214
|
+
import agentplatform
|
|
1215
|
+
|
|
1216
|
+
client = agentplatform.Client(project="my_project", location="us-central1")
|
|
1217
|
+
for memory_bank in client.memory_banks.list(
|
|
1218
|
+
config={"filter": "'display_name="My Custom Memory Bank"'},
|
|
1219
|
+
):
|
|
1220
|
+
print(memory_bank.name)
|
|
1221
|
+
|
|
1222
|
+
Args:
|
|
1223
|
+
config (ListMemoryBanksConfig):
|
|
1224
|
+
Optional. The config for the memory banks to be listed.
|
|
1225
|
+
|
|
1226
|
+
Returns:
|
|
1227
|
+
Iterable[MemoryBank]: An iterable of Memory Banks matching the filter.
|
|
1228
|
+
"""
|
|
1229
|
+
|
|
1230
|
+
def transformed_list(*args, **kwargs) -> types.ListMemoryBanksResponse:
|
|
1231
|
+
res = self._list(*args, **kwargs)
|
|
1232
|
+
if getattr(res, "reasoning_engines", None):
|
|
1233
|
+
res.reasoning_engines = [
|
|
1234
|
+
_memory_bank_utils._reasoning_engine_to_memory_bank(engine)
|
|
1235
|
+
for engine in res.reasoning_engines
|
|
1236
|
+
]
|
|
1237
|
+
return res
|
|
1238
|
+
|
|
1239
|
+
return Pager(
|
|
1240
|
+
"reasoning_engines",
|
|
1241
|
+
transformed_list,
|
|
1242
|
+
transformed_list(config=config),
|
|
1243
|
+
config,
|
|
1244
|
+
)
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
class AsyncMemoryBanks(_api_module.BaseModule):
|
|
1248
|
+
|
|
1249
|
+
async def _create(
|
|
1250
|
+
self,
|
|
1251
|
+
*,
|
|
1252
|
+
config: Optional[types.CreateMemoryBankConfigOrDict] = None,
|
|
1253
|
+
memory_bank_config: Optional[
|
|
1254
|
+
types.ReasoningEngineContextSpecMemoryBankConfigOrDict
|
|
1255
|
+
] = None,
|
|
1256
|
+
) -> types.MemoryBankOperation:
|
|
1257
|
+
"""
|
|
1258
|
+
Creates a new Memory Bank.
|
|
1259
|
+
"""
|
|
1260
|
+
|
|
1261
|
+
parameter_model = types._CreateMemoryBankRequestParameters(
|
|
1262
|
+
config=config,
|
|
1263
|
+
memory_bank_config=memory_bank_config,
|
|
1264
|
+
)
|
|
1265
|
+
|
|
1266
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1267
|
+
if not self._api_client.vertexai:
|
|
1268
|
+
raise ValueError(
|
|
1269
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1270
|
+
)
|
|
1271
|
+
else:
|
|
1272
|
+
request_dict = _CreateMemoryBankRequestParameters_to_vertex(parameter_model)
|
|
1273
|
+
request_url_dict = request_dict.get("_url")
|
|
1274
|
+
if request_url_dict:
|
|
1275
|
+
path = "reasoningEngines".format_map(request_url_dict)
|
|
1276
|
+
else:
|
|
1277
|
+
path = "reasoningEngines"
|
|
1278
|
+
|
|
1279
|
+
query_params = request_dict.get("_query")
|
|
1280
|
+
if query_params:
|
|
1281
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1282
|
+
# TODO: remove the hack that pops config.
|
|
1283
|
+
request_dict.pop("config", None)
|
|
1284
|
+
|
|
1285
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1286
|
+
if (
|
|
1287
|
+
parameter_model.config is not None
|
|
1288
|
+
and parameter_model.config.http_options is not None
|
|
1289
|
+
):
|
|
1290
|
+
http_options = parameter_model.config.http_options
|
|
1291
|
+
|
|
1292
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1293
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1294
|
+
|
|
1295
|
+
response = await self._api_client.async_request(
|
|
1296
|
+
"post", path, request_dict, http_options
|
|
1297
|
+
)
|
|
1298
|
+
|
|
1299
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1300
|
+
|
|
1301
|
+
if self._api_client.vertexai:
|
|
1302
|
+
response_dict = _MemoryBankOperation_from_vertex(response_dict)
|
|
1303
|
+
|
|
1304
|
+
return_value = types.MemoryBankOperation._from_response(
|
|
1305
|
+
response=response_dict,
|
|
1306
|
+
kwargs=(
|
|
1307
|
+
{
|
|
1308
|
+
"config": {
|
|
1309
|
+
"response_schema": getattr(
|
|
1310
|
+
parameter_model.config, "response_schema", None
|
|
1311
|
+
),
|
|
1312
|
+
"response_json_schema": getattr(
|
|
1313
|
+
parameter_model.config, "response_json_schema", None
|
|
1314
|
+
),
|
|
1315
|
+
"include_all_fields": getattr(
|
|
1316
|
+
parameter_model.config, "include_all_fields", None
|
|
1317
|
+
),
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
if getattr(parameter_model, "config", None)
|
|
1321
|
+
else {}
|
|
1322
|
+
),
|
|
1323
|
+
)
|
|
1324
|
+
|
|
1325
|
+
self._api_client._verify_response(return_value)
|
|
1326
|
+
return return_value
|
|
1327
|
+
|
|
1328
|
+
async def _delete(
|
|
1329
|
+
self,
|
|
1330
|
+
*,
|
|
1331
|
+
name: str,
|
|
1332
|
+
force: Optional[bool] = None,
|
|
1333
|
+
config: Optional[types.DeleteMemoryBankConfigOrDict] = None,
|
|
1334
|
+
) -> types.DeleteMemoryBankOperation:
|
|
1335
|
+
"""
|
|
1336
|
+
Deletes a memory bank.
|
|
1337
|
+
"""
|
|
1338
|
+
|
|
1339
|
+
parameter_model = types._DeleteMemoryBankRequestParameters(
|
|
1340
|
+
name=name,
|
|
1341
|
+
force=force,
|
|
1342
|
+
config=config,
|
|
1343
|
+
)
|
|
1344
|
+
|
|
1345
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1346
|
+
if not self._api_client.vertexai:
|
|
1347
|
+
raise ValueError(
|
|
1348
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1349
|
+
)
|
|
1350
|
+
else:
|
|
1351
|
+
request_dict = _DeleteMemoryBankRequestParameters_to_vertex(parameter_model)
|
|
1352
|
+
request_url_dict = request_dict.get("_url")
|
|
1353
|
+
if request_url_dict:
|
|
1354
|
+
path = "{name}".format_map(request_url_dict)
|
|
1355
|
+
else:
|
|
1356
|
+
path = "{name}"
|
|
1357
|
+
|
|
1358
|
+
query_params = request_dict.get("_query")
|
|
1359
|
+
if query_params:
|
|
1360
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1361
|
+
# TODO: remove the hack that pops config.
|
|
1362
|
+
request_dict.pop("config", None)
|
|
1363
|
+
|
|
1364
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1365
|
+
if (
|
|
1366
|
+
parameter_model.config is not None
|
|
1367
|
+
and parameter_model.config.http_options is not None
|
|
1368
|
+
):
|
|
1369
|
+
http_options = parameter_model.config.http_options
|
|
1370
|
+
|
|
1371
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1372
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1373
|
+
|
|
1374
|
+
response = await self._api_client.async_request(
|
|
1375
|
+
"delete", path, request_dict, http_options
|
|
1376
|
+
)
|
|
1377
|
+
|
|
1378
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1379
|
+
|
|
1380
|
+
return_value = types.DeleteMemoryBankOperation._from_response(
|
|
1381
|
+
response=response_dict,
|
|
1382
|
+
kwargs=(
|
|
1383
|
+
{
|
|
1384
|
+
"config": {
|
|
1385
|
+
"response_schema": getattr(
|
|
1386
|
+
parameter_model.config, "response_schema", None
|
|
1387
|
+
),
|
|
1388
|
+
"response_json_schema": getattr(
|
|
1389
|
+
parameter_model.config, "response_json_schema", None
|
|
1390
|
+
),
|
|
1391
|
+
"include_all_fields": getattr(
|
|
1392
|
+
parameter_model.config, "include_all_fields", None
|
|
1393
|
+
),
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
if getattr(parameter_model, "config", None)
|
|
1397
|
+
else {}
|
|
1398
|
+
),
|
|
1399
|
+
)
|
|
1400
|
+
|
|
1401
|
+
self._api_client._verify_response(return_value)
|
|
1402
|
+
return return_value
|
|
1403
|
+
|
|
1404
|
+
async def _get(
|
|
1405
|
+
self, *, name: str, config: Optional[types.GetMemoryBankConfigOrDict] = None
|
|
1406
|
+
) -> types.ReasoningEngine:
|
|
1407
|
+
"""
|
|
1408
|
+
Get a Memory Bank instance.
|
|
1409
|
+
"""
|
|
1410
|
+
|
|
1411
|
+
parameter_model = types._GetMemoryBankRequestParameters(
|
|
1412
|
+
name=name,
|
|
1413
|
+
config=config,
|
|
1414
|
+
)
|
|
1415
|
+
|
|
1416
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1417
|
+
if not self._api_client.vertexai:
|
|
1418
|
+
raise ValueError(
|
|
1419
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1420
|
+
)
|
|
1421
|
+
else:
|
|
1422
|
+
request_dict = _GetMemoryBankRequestParameters_to_vertex(parameter_model)
|
|
1423
|
+
request_url_dict = request_dict.get("_url")
|
|
1424
|
+
if request_url_dict:
|
|
1425
|
+
path = "{name}".format_map(request_url_dict)
|
|
1426
|
+
else:
|
|
1427
|
+
path = "{name}"
|
|
1428
|
+
|
|
1429
|
+
query_params = request_dict.get("_query")
|
|
1430
|
+
if query_params:
|
|
1431
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1432
|
+
# TODO: remove the hack that pops config.
|
|
1433
|
+
request_dict.pop("config", None)
|
|
1434
|
+
|
|
1435
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1436
|
+
if (
|
|
1437
|
+
parameter_model.config is not None
|
|
1438
|
+
and parameter_model.config.http_options is not None
|
|
1439
|
+
):
|
|
1440
|
+
http_options = parameter_model.config.http_options
|
|
1441
|
+
|
|
1442
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1443
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1444
|
+
|
|
1445
|
+
response = await self._api_client.async_request(
|
|
1446
|
+
"get", path, request_dict, http_options
|
|
1447
|
+
)
|
|
1448
|
+
|
|
1449
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1450
|
+
|
|
1451
|
+
if self._api_client.vertexai:
|
|
1452
|
+
response_dict = _ReasoningEngine_from_vertex(response_dict)
|
|
1453
|
+
|
|
1454
|
+
return_value = types.ReasoningEngine._from_response(
|
|
1455
|
+
response=response_dict,
|
|
1456
|
+
kwargs=(
|
|
1457
|
+
{
|
|
1458
|
+
"config": {
|
|
1459
|
+
"response_schema": getattr(
|
|
1460
|
+
parameter_model.config, "response_schema", None
|
|
1461
|
+
),
|
|
1462
|
+
"response_json_schema": getattr(
|
|
1463
|
+
parameter_model.config, "response_json_schema", None
|
|
1464
|
+
),
|
|
1465
|
+
"include_all_fields": getattr(
|
|
1466
|
+
parameter_model.config, "include_all_fields", None
|
|
1467
|
+
),
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
if getattr(parameter_model, "config", None)
|
|
1471
|
+
else {}
|
|
1472
|
+
),
|
|
1473
|
+
)
|
|
1474
|
+
|
|
1475
|
+
self._api_client._verify_response(return_value)
|
|
1476
|
+
return return_value
|
|
1477
|
+
|
|
1478
|
+
async def _ingest_events(
|
|
1479
|
+
self,
|
|
1480
|
+
*,
|
|
1481
|
+
name: str,
|
|
1482
|
+
stream_id: Optional[str] = None,
|
|
1483
|
+
direct_contents_source: Optional[
|
|
1484
|
+
types.IngestionDirectContentsSourceOrDict
|
|
1485
|
+
] = None,
|
|
1486
|
+
scope: Optional[dict[str, str]] = None,
|
|
1487
|
+
generation_trigger_config: Optional[
|
|
1488
|
+
types.MemoryGenerationTriggerConfigOrDict
|
|
1489
|
+
] = None,
|
|
1490
|
+
config: Optional[types.IngestEventsConfigOrDict] = None,
|
|
1491
|
+
) -> types.MemoryBankIngestEventsOperation:
|
|
1492
|
+
"""
|
|
1493
|
+
Ingest events into a Memory Bank.
|
|
1494
|
+
"""
|
|
1495
|
+
|
|
1496
|
+
parameter_model = types._IngestEventsRequestParameters(
|
|
1497
|
+
name=name,
|
|
1498
|
+
stream_id=stream_id,
|
|
1499
|
+
direct_contents_source=direct_contents_source,
|
|
1500
|
+
scope=scope,
|
|
1501
|
+
generation_trigger_config=generation_trigger_config,
|
|
1502
|
+
config=config,
|
|
1503
|
+
)
|
|
1504
|
+
|
|
1505
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1506
|
+
if not self._api_client.vertexai:
|
|
1507
|
+
raise ValueError(
|
|
1508
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1509
|
+
)
|
|
1510
|
+
else:
|
|
1511
|
+
request_dict = _IngestEventsRequestParameters_to_vertex(parameter_model)
|
|
1512
|
+
request_url_dict = request_dict.get("_url")
|
|
1513
|
+
if request_url_dict:
|
|
1514
|
+
path = "{name}/memories:ingestEvents".format_map(request_url_dict)
|
|
1515
|
+
else:
|
|
1516
|
+
path = "{name}/memories:ingestEvents"
|
|
1517
|
+
|
|
1518
|
+
query_params = request_dict.get("_query")
|
|
1519
|
+
if query_params:
|
|
1520
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1521
|
+
# TODO: remove the hack that pops config.
|
|
1522
|
+
request_dict.pop("config", None)
|
|
1523
|
+
|
|
1524
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1525
|
+
if (
|
|
1526
|
+
parameter_model.config is not None
|
|
1527
|
+
and parameter_model.config.http_options is not None
|
|
1528
|
+
):
|
|
1529
|
+
http_options = parameter_model.config.http_options
|
|
1530
|
+
|
|
1531
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1532
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1533
|
+
|
|
1534
|
+
response = await self._api_client.async_request(
|
|
1535
|
+
"post", path, request_dict, http_options
|
|
1536
|
+
)
|
|
1537
|
+
|
|
1538
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1539
|
+
|
|
1540
|
+
return_value = types.MemoryBankIngestEventsOperation._from_response(
|
|
1541
|
+
response=response_dict,
|
|
1542
|
+
kwargs=(
|
|
1543
|
+
{
|
|
1544
|
+
"config": {
|
|
1545
|
+
"response_schema": getattr(
|
|
1546
|
+
parameter_model.config, "response_schema", None
|
|
1547
|
+
),
|
|
1548
|
+
"response_json_schema": getattr(
|
|
1549
|
+
parameter_model.config, "response_json_schema", None
|
|
1550
|
+
),
|
|
1551
|
+
"include_all_fields": getattr(
|
|
1552
|
+
parameter_model.config, "include_all_fields", None
|
|
1553
|
+
),
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
if getattr(parameter_model, "config", None)
|
|
1557
|
+
else {}
|
|
1558
|
+
),
|
|
1559
|
+
)
|
|
1560
|
+
|
|
1561
|
+
self._api_client._verify_response(return_value)
|
|
1562
|
+
return return_value
|
|
1563
|
+
|
|
1564
|
+
async def _list(
|
|
1565
|
+
self, *, config: Optional[types.ListMemoryBanksConfigOrDict] = None
|
|
1566
|
+
) -> types.ListReasoningEnginesResponse:
|
|
1567
|
+
"""
|
|
1568
|
+
Lists Memory Banks.
|
|
1569
|
+
"""
|
|
1570
|
+
|
|
1571
|
+
parameter_model = types._ListMemoryBanksRequestParameters(
|
|
1572
|
+
config=config,
|
|
1573
|
+
)
|
|
1574
|
+
|
|
1575
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1576
|
+
if not self._api_client.vertexai:
|
|
1577
|
+
raise ValueError(
|
|
1578
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1579
|
+
)
|
|
1580
|
+
else:
|
|
1581
|
+
request_dict = _ListMemoryBanksRequestParameters_to_vertex(parameter_model)
|
|
1582
|
+
request_url_dict = request_dict.get("_url")
|
|
1583
|
+
if request_url_dict:
|
|
1584
|
+
path = "reasoningEngines".format_map(request_url_dict)
|
|
1585
|
+
else:
|
|
1586
|
+
path = "reasoningEngines"
|
|
1587
|
+
|
|
1588
|
+
query_params = request_dict.get("_query")
|
|
1589
|
+
if query_params:
|
|
1590
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1591
|
+
# TODO: remove the hack that pops config.
|
|
1592
|
+
request_dict.pop("config", None)
|
|
1593
|
+
|
|
1594
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1595
|
+
if (
|
|
1596
|
+
parameter_model.config is not None
|
|
1597
|
+
and parameter_model.config.http_options is not None
|
|
1598
|
+
):
|
|
1599
|
+
http_options = parameter_model.config.http_options
|
|
1600
|
+
|
|
1601
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1602
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1603
|
+
|
|
1604
|
+
response = await self._api_client.async_request(
|
|
1605
|
+
"get", path, request_dict, http_options
|
|
1606
|
+
)
|
|
1607
|
+
|
|
1608
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1609
|
+
|
|
1610
|
+
if self._api_client.vertexai:
|
|
1611
|
+
response_dict = _ListReasoningEnginesResponse_from_vertex(response_dict)
|
|
1612
|
+
|
|
1613
|
+
return_value = types.ListReasoningEnginesResponse._from_response(
|
|
1614
|
+
response=response_dict,
|
|
1615
|
+
kwargs=(
|
|
1616
|
+
{
|
|
1617
|
+
"config": {
|
|
1618
|
+
"response_schema": getattr(
|
|
1619
|
+
parameter_model.config, "response_schema", None
|
|
1620
|
+
),
|
|
1621
|
+
"response_json_schema": getattr(
|
|
1622
|
+
parameter_model.config, "response_json_schema", None
|
|
1623
|
+
),
|
|
1624
|
+
"include_all_fields": getattr(
|
|
1625
|
+
parameter_model.config, "include_all_fields", None
|
|
1626
|
+
),
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
if getattr(parameter_model, "config", None)
|
|
1630
|
+
else {}
|
|
1631
|
+
),
|
|
1632
|
+
)
|
|
1633
|
+
|
|
1634
|
+
self._api_client._verify_response(return_value)
|
|
1635
|
+
return return_value
|
|
1636
|
+
|
|
1637
|
+
async def _get_memory_bank_operation(
|
|
1638
|
+
self,
|
|
1639
|
+
*,
|
|
1640
|
+
operation_name: str,
|
|
1641
|
+
config: Optional[types.GetMemoryBankOperationConfigOrDict] = None,
|
|
1642
|
+
) -> types.MemoryBankOperation:
|
|
1643
|
+
parameter_model = types._GetMemoryBankOperationParameters(
|
|
1644
|
+
operation_name=operation_name,
|
|
1645
|
+
config=config,
|
|
1646
|
+
)
|
|
1647
|
+
|
|
1648
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1649
|
+
if not self._api_client.vertexai:
|
|
1650
|
+
raise ValueError(
|
|
1651
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1652
|
+
)
|
|
1653
|
+
else:
|
|
1654
|
+
request_dict = _GetMemoryBankOperationParameters_to_vertex(parameter_model)
|
|
1655
|
+
request_url_dict = request_dict.get("_url")
|
|
1656
|
+
if request_url_dict:
|
|
1657
|
+
path = "{operationName}".format_map(request_url_dict)
|
|
1658
|
+
else:
|
|
1659
|
+
path = "{operationName}"
|
|
1660
|
+
|
|
1661
|
+
query_params = request_dict.get("_query")
|
|
1662
|
+
if query_params:
|
|
1663
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1664
|
+
# TODO: remove the hack that pops config.
|
|
1665
|
+
request_dict.pop("config", None)
|
|
1666
|
+
|
|
1667
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1668
|
+
if (
|
|
1669
|
+
parameter_model.config is not None
|
|
1670
|
+
and parameter_model.config.http_options is not None
|
|
1671
|
+
):
|
|
1672
|
+
http_options = parameter_model.config.http_options
|
|
1673
|
+
|
|
1674
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1675
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1676
|
+
|
|
1677
|
+
response = await self._api_client.async_request(
|
|
1678
|
+
"get", path, request_dict, http_options
|
|
1679
|
+
)
|
|
1680
|
+
|
|
1681
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1682
|
+
|
|
1683
|
+
if self._api_client.vertexai:
|
|
1684
|
+
response_dict = _MemoryBankOperation_from_vertex(response_dict)
|
|
1685
|
+
|
|
1686
|
+
return_value = types.MemoryBankOperation._from_response(
|
|
1687
|
+
response=response_dict,
|
|
1688
|
+
kwargs=(
|
|
1689
|
+
{
|
|
1690
|
+
"config": {
|
|
1691
|
+
"response_schema": getattr(
|
|
1692
|
+
parameter_model.config, "response_schema", None
|
|
1693
|
+
),
|
|
1694
|
+
"response_json_schema": getattr(
|
|
1695
|
+
parameter_model.config, "response_json_schema", None
|
|
1696
|
+
),
|
|
1697
|
+
"include_all_fields": getattr(
|
|
1698
|
+
parameter_model.config, "include_all_fields", None
|
|
1699
|
+
),
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
if getattr(parameter_model, "config", None)
|
|
1703
|
+
else {}
|
|
1704
|
+
),
|
|
1705
|
+
)
|
|
1706
|
+
|
|
1707
|
+
self._api_client._verify_response(return_value)
|
|
1708
|
+
return return_value
|
|
1709
|
+
|
|
1710
|
+
_memories = None
|
|
1711
|
+
|
|
1712
|
+
@property
|
|
1713
|
+
def memories(self) -> "memories_module.AsyncMemories":
|
|
1714
|
+
if self._memories is None:
|
|
1715
|
+
self._memories = importlib.import_module(".memories", __package__)
|
|
1716
|
+
return self._memories.AsyncMemories(self._api_client) # type: ignore[no-any-return]
|
|
1717
|
+
|
|
1718
|
+
async def create(
|
|
1719
|
+
self,
|
|
1720
|
+
*,
|
|
1721
|
+
managed_semantic_memory_config: Optional[
|
|
1722
|
+
types.ManagedSemanticMemoryConfigOrDict
|
|
1723
|
+
] = None,
|
|
1724
|
+
config: Optional[types.CreateMemoryBankConfigOrDict] = None,
|
|
1725
|
+
) -> types.MemoryBank:
|
|
1726
|
+
"""Creates a new Memory Bank."""
|
|
1727
|
+
memory_bank_config = (
|
|
1728
|
+
_memory_bank_utils._managed_semantic_memory_config_to_memory_bank_config(
|
|
1729
|
+
managed_semantic_memory_config
|
|
1730
|
+
)
|
|
1731
|
+
)
|
|
1732
|
+
|
|
1733
|
+
operation = await self._create(
|
|
1734
|
+
memory_bank_config=memory_bank_config,
|
|
1735
|
+
config=config,
|
|
1736
|
+
)
|
|
1737
|
+
|
|
1738
|
+
operation = await _memory_bank_utils._await_async_operation(
|
|
1739
|
+
operation_name=operation.name,
|
|
1740
|
+
get_operation_fn=self._get_memory_bank_operation,
|
|
1741
|
+
)
|
|
1742
|
+
if operation.error:
|
|
1743
|
+
raise RuntimeError(operation.error)
|
|
1744
|
+
if not operation.response:
|
|
1745
|
+
raise RuntimeError(
|
|
1746
|
+
f"Memory Bank creation completed without a response: {operation}"
|
|
1747
|
+
)
|
|
1748
|
+
memory_bank = types.MemoryBank(name=operation.response.name)
|
|
1749
|
+
return memory_bank
|
|
1750
|
+
|
|
1751
|
+
async def delete(
|
|
1752
|
+
self,
|
|
1753
|
+
*,
|
|
1754
|
+
name: str,
|
|
1755
|
+
force: Optional[bool] = None,
|
|
1756
|
+
config: Optional[types.DeleteMemoryBankConfigOrDict] = None,
|
|
1757
|
+
) -> types.DeleteMemoryBankOperation:
|
|
1758
|
+
"""
|
|
1759
|
+
Delete a Memory Bank resource.
|
|
1760
|
+
|
|
1761
|
+
Args:
|
|
1762
|
+
name (str):
|
|
1763
|
+
Required. The name of the Memory Bank to be deleted. Format:
|
|
1764
|
+
`projects/{project}/locations/{location}/memoryBanks/{resource_id}`
|
|
1765
|
+
or `memoryBanks/{resource_id}`.
|
|
1766
|
+
force (bool):
|
|
1767
|
+
Optional. If set to True, child resources will also be deleted.
|
|
1768
|
+
Otherwise, the request will fail with FAILED_PRECONDITION error when
|
|
1769
|
+
the Memory Bank has undeleted child resources. Defaults to False.
|
|
1770
|
+
config (DeleteMemoryBankConfig):
|
|
1771
|
+
Optional. Additional configurations for deleting the Memory Bank.
|
|
1772
|
+
"""
|
|
1773
|
+
logger.info(f"Deleting MemoryBank resource: {name}")
|
|
1774
|
+
operation = await self._delete(name=name, force=force, config=config)
|
|
1775
|
+
logger.info(f"Started MemoryBank delete operation: {operation.name}")
|
|
1776
|
+
return operation
|
|
1777
|
+
|
|
1778
|
+
async def ingest_events(
|
|
1779
|
+
self,
|
|
1780
|
+
*,
|
|
1781
|
+
name: str,
|
|
1782
|
+
scope: dict[str, str],
|
|
1783
|
+
stream_id: str = "",
|
|
1784
|
+
direct_contents_source: Optional[
|
|
1785
|
+
types.IngestionDirectContentsSourceOrDict
|
|
1786
|
+
] = None,
|
|
1787
|
+
generation_trigger_config: Optional[
|
|
1788
|
+
types.MemoryGenerationTriggerConfigOrDict
|
|
1789
|
+
] = None,
|
|
1790
|
+
config: Optional[types.IngestEventsConfigOrDict] = None,
|
|
1791
|
+
) -> types.MemoryBankIngestEventsOperation:
|
|
1792
|
+
"""Ingests events into Memory Bank.
|
|
1793
|
+
|
|
1794
|
+
Example usage:
|
|
1795
|
+
```
|
|
1796
|
+
await client.aio.memory_banks.ingest_events(
|
|
1797
|
+
name="projects/test-project/locations/us-central1/reasoningEngines/test-agent-engine",
|
|
1798
|
+
scope={"user_id": "test-user-id"},
|
|
1799
|
+
direct_contents_source={
|
|
1800
|
+
"events": [
|
|
1801
|
+
{
|
|
1802
|
+
"content": {
|
|
1803
|
+
"role": "user",
|
|
1804
|
+
"parts": [
|
|
1805
|
+
{"text": "I am a software engineer."}
|
|
1806
|
+
],
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
]
|
|
1810
|
+
},
|
|
1811
|
+
generation_trigger_config={
|
|
1812
|
+
"generation_rule": {
|
|
1813
|
+
"idle_duration": "60s"
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
)
|
|
1817
|
+
```
|
|
1818
|
+
|
|
1819
|
+
Args:
|
|
1820
|
+
name (str):
|
|
1821
|
+
Required. The name of the Memory Bank to ingest events into.
|
|
1822
|
+
scope (dict[str, str]):
|
|
1823
|
+
Required. The scope of the events to ingest. For example,
|
|
1824
|
+
{"user_id": "123"}.
|
|
1825
|
+
stream_id (str):
|
|
1826
|
+
Optional. The ID of the stream to ingest events into. If not
|
|
1827
|
+
specified, the events will be ingested into the default stream.
|
|
1828
|
+
direct_contents_source (IngestionDirectContentsSource):
|
|
1829
|
+
The direct contents source, containing the events to ingest.
|
|
1830
|
+
generation_trigger_config (MemoryGenerationTriggerConfig):
|
|
1831
|
+
Optional. The configuration for the generation trigger config.
|
|
1832
|
+
config (IngestEventsConfig):
|
|
1833
|
+
Optional. The configuration for the ingest events operation.
|
|
1834
|
+
|
|
1835
|
+
Returns:
|
|
1836
|
+
IngestEventsOperation:
|
|
1837
|
+
The operation for ingesting the events.
|
|
1838
|
+
"""
|
|
1839
|
+
if config is None:
|
|
1840
|
+
config = types.IngestEventsConfig()
|
|
1841
|
+
elif isinstance(config, dict):
|
|
1842
|
+
config = types.IngestEventsConfig.model_validate(config)
|
|
1843
|
+
operation = await self._ingest_events(
|
|
1844
|
+
name=name,
|
|
1845
|
+
scope=scope,
|
|
1846
|
+
stream_id=stream_id,
|
|
1847
|
+
generation_trigger_config=generation_trigger_config,
|
|
1848
|
+
direct_contents_source=direct_contents_source,
|
|
1849
|
+
config=config,
|
|
1850
|
+
)
|
|
1851
|
+
if config.wait_for_completion and not operation.done:
|
|
1852
|
+
operation = await _memory_bank_utils._await_async_operation(
|
|
1853
|
+
operation_name=operation.name,
|
|
1854
|
+
get_operation_fn=self._get_memory_bank_operation,
|
|
1855
|
+
poll_interval_seconds=0.5,
|
|
1856
|
+
)
|
|
1857
|
+
if operation.error:
|
|
1858
|
+
raise RuntimeError(f"Failed to ingest events: {operation.error}")
|
|
1859
|
+
return operation
|
|
1860
|
+
|
|
1861
|
+
async def get(
|
|
1862
|
+
self,
|
|
1863
|
+
*,
|
|
1864
|
+
name: str,
|
|
1865
|
+
config: Optional[types.GetMemoryBankConfigOrDict] = None,
|
|
1866
|
+
) -> types.MemoryBank:
|
|
1867
|
+
"""Gets a Memory Bank.
|
|
1868
|
+
|
|
1869
|
+
Args:
|
|
1870
|
+
name (str):
|
|
1871
|
+
Required. A fully-qualified resource name or ID such as
|
|
1872
|
+
"projects/123/locations/us-central1/reasoningEngines/456" or
|
|
1873
|
+
a shortened name such as "reasoningEngines/456".
|
|
1874
|
+
"""
|
|
1875
|
+
api_resource = await self._get(name=name, config=config)
|
|
1876
|
+
memory_bank = _memory_bank_utils._reasoning_engine_to_memory_bank(api_resource)
|
|
1877
|
+
return memory_bank
|
|
1878
|
+
|
|
1879
|
+
async def _list_pager(
|
|
1880
|
+
self, *, config: Optional[types.ListMemoryBanksConfigOrDict] = None
|
|
1881
|
+
) -> AsyncPager[types.ReasoningEngine]:
|
|
1882
|
+
return AsyncPager(
|
|
1883
|
+
"reasoning_engines",
|
|
1884
|
+
self._list,
|
|
1885
|
+
await self._list(config=config),
|
|
1886
|
+
config,
|
|
1887
|
+
)
|
|
1888
|
+
|
|
1889
|
+
async def list(
|
|
1890
|
+
self, *, config: Optional[types.ListMemoryBanksConfigOrDict] = None
|
|
1891
|
+
) -> AsyncIterator[types.MemoryBank]:
|
|
1892
|
+
"""List all instances of Memory Bank matching the filter.
|
|
1893
|
+
|
|
1894
|
+
Example Usage:
|
|
1895
|
+
|
|
1896
|
+
.. code-block:: python
|
|
1897
|
+
import agentplatform
|
|
1898
|
+
|
|
1899
|
+
client = agentplatform.Client(project="my_project", location="us-central1")
|
|
1900
|
+
async for memory_bank in await client.memory_banks.list(
|
|
1901
|
+
config={"filter": "'display_name="My Custom Memory Bank"'},
|
|
1902
|
+
):
|
|
1903
|
+
print(memory_bank.name)
|
|
1904
|
+
|
|
1905
|
+
Args:
|
|
1906
|
+
config (ListMemoryBanksConfig):
|
|
1907
|
+
Optional. The config for the memory banks to be listed.
|
|
1908
|
+
|
|
1909
|
+
Returns:
|
|
1910
|
+
Iterable[MemoryBank]: An iterable of Memory Banks matching the filter.
|
|
1911
|
+
"""
|
|
1912
|
+
|
|
1913
|
+
async def transformed_list(*args, **kwargs):
|
|
1914
|
+
res = await self._list(*args, **kwargs)
|
|
1915
|
+
if getattr(res, "reasoning_engines", None):
|
|
1916
|
+
res.reasoning_engines = [
|
|
1917
|
+
_memory_bank_utils._reasoning_engine_to_memory_bank(engine)
|
|
1918
|
+
for engine in res.reasoning_engines
|
|
1919
|
+
]
|
|
1920
|
+
return res
|
|
1921
|
+
|
|
1922
|
+
return AsyncPager(
|
|
1923
|
+
"reasoning_engines",
|
|
1924
|
+
transformed_list,
|
|
1925
|
+
await transformed_list(config=config),
|
|
1926
|
+
config,
|
|
1927
|
+
)
|