@@ -254,6 +254,52 @@ def _GetAgentEngineMemoryRequestParameters_to_vertex(
254254 return to_object
255255
256256
257+ def _IngestEventsConfig_to_vertex (
258+ from_object : Union [dict [str , Any ], object ],
259+ parent_object : Optional [dict [str , Any ]] = None ,
260+ ) -> dict [str , Any ]:
261+ to_object : dict [str , Any ] = {}
262+
263+ if getv (from_object , ["force_flush" ]) is not None :
264+ setv (parent_object , ["forceFlush" ], getv (from_object , ["force_flush" ]))
265+
266+ return to_object
267+
268+
269+ def _IngestEventsRequestParameters_to_vertex (
270+ from_object : Union [dict [str , Any ], object ],
271+ parent_object : Optional [dict [str , Any ]] = None ,
272+ ) -> dict [str , Any ]:
273+ to_object : dict [str , Any ] = {}
274+ if getv (from_object , ["config" ]) is not None :
275+ _IngestEventsConfig_to_vertex (getv (from_object , ["config" ]), to_object )
276+
277+ if getv (from_object , ["name" ]) is not None :
278+ setv (to_object , ["_url" , "name" ], getv (from_object , ["name" ]))
279+
280+ if getv (from_object , ["stream_id" ]) is not None :
281+ setv (to_object , ["streamId" ], getv (from_object , ["stream_id" ]))
282+
283+ if getv (from_object , ["direct_contents_source" ]) is not None :
284+ setv (
285+ to_object ,
286+ ["directContentsSource" ],
287+ getv (from_object , ["direct_contents_source" ]),
288+ )
289+
290+ if getv (from_object , ["scope" ]) is not None :
291+ setv (to_object , ["scope" ], getv (from_object , ["scope" ]))
292+
293+ if getv (from_object , ["generation_trigger_config" ]) is not None :
294+ setv (
295+ to_object ,
296+ ["generationTriggerConfig" ],
297+ getv (from_object , ["generation_trigger_config" ]),
298+ )
299+
300+ return to_object
301+
302+
257303def _ListAgentEngineMemoryConfig_to_vertex (
258304 from_object : Union [dict [str , Any ], object ],
259305 parent_object : Optional [dict [str , Any ]] = None ,
@@ -1112,6 +1158,69 @@ def _purge(
11121158 self ._api_client ._verify_response (return_value )
11131159 return return_value
11141160
1161+ def _ingest_events (
1162+ self ,
1163+ * ,
1164+ config : Optional [types .IngestEventsConfigOrDict ] = None ,
1165+ name : str ,
1166+ stream_id : Optional [str ] = None ,
1167+ direct_contents_source : Optional [
1168+ types .IngestionDirectContentsSourceOrDict
1169+ ] = None ,
1170+ scope : Optional [dict [str , str ]] = None ,
1171+ generation_trigger_config : Optional [types .GenerationTriggerConfigOrDict ] = None ,
1172+ ) -> types .MemoryBankIngestEventsOperation :
1173+ """
1174+ Ingest events into a Memory Bank.
1175+ """
1176+
1177+ parameter_model = types ._IngestEventsRequestParameters (
1178+ config = config ,
1179+ name = name ,
1180+ stream_id = stream_id ,
1181+ direct_contents_source = direct_contents_source ,
1182+ scope = scope ,
1183+ generation_trigger_config = generation_trigger_config ,
1184+ )
1185+
1186+ request_url_dict : Optional [dict [str , str ]]
1187+ if not self ._api_client .vertexai :
1188+ raise ValueError ("This method is only supported in the Vertex AI client." )
1189+ else :
1190+ request_dict = _IngestEventsRequestParameters_to_vertex (parameter_model )
1191+ request_url_dict = request_dict .get ("_url" )
1192+ if request_url_dict :
1193+ path = "{name}/memories:ingestEvents" .format_map (request_url_dict )
1194+ else :
1195+ path = "{name}/memories:ingestEvents"
1196+
1197+ query_params = request_dict .get ("_query" )
1198+ if query_params :
1199+ path = f"{ path } ?{ urlencode (query_params )} "
1200+ # TODO: remove the hack that pops config.
1201+ request_dict .pop ("config" , None )
1202+
1203+ http_options : Optional [types .HttpOptions ] = None
1204+ if (
1205+ parameter_model .config is not None
1206+ and parameter_model .config .http_options is not None
1207+ ):
1208+ http_options = parameter_model .config .http_options
1209+
1210+ request_dict = _common .convert_to_dict (request_dict )
1211+ request_dict = _common .encode_unserializable_types (request_dict )
1212+
1213+ response = self ._api_client .request ("post" , path , request_dict , http_options )
1214+
1215+ response_dict = {} if not response .body else json .loads (response .body )
1216+
1217+ return_value = types .MemoryBankIngestEventsOperation ._from_response (
1218+ response = response_dict , kwargs = parameter_model .model_dump ()
1219+ )
1220+
1221+ self ._api_client ._verify_response (return_value )
1222+ return return_value
1223+
11151224 _revisions = None
11161225
11171226 @property
@@ -1416,6 +1525,53 @@ def purge(
14161525 raise RuntimeError (f"Failed to purge memories: { operation .error } " )
14171526 return operation
14181527
1528+ def ingest_events (
1529+ self ,
1530+ * ,
1531+ name : str ,
1532+ scope : dict [str , str ],
1533+ stream_id : str = None ,
1534+ direct_contents_source : Optional [
1535+ types .IngestionDirectContentsSourceOrDict
1536+ ] = None ,
1537+ config : Optional [types .IngestAgentEngineMemoriesConfigOrDict ] = None ,
1538+ ) -> types .AgentEngineIngestEventsOperation :
1539+ """Ingests events into an Agent Engine.
1540+
1541+ Args:
1542+ name (str):
1543+ Required. The name of the Agent Engine to ingest events into.
1544+ scope (dict[str, str]):
1545+ Required. The scope of the events to ingest. For example,
1546+ {"user_id": "123"}.
1547+ config (IngestAgentEngineMemoriesConfig):
1548+ Optional. The configuration for the ingest events operation.
1549+
1550+ Returns:
1551+ AgentEngineIngestEventsOperation:
1552+ The operation for ingesting the events.
1553+ """
1554+ if config is None :
1555+ config = types .IngestAgentEngineMemoriesConfig ()
1556+ elif isinstance (config , dict ):
1557+ config = types .IngestAgentEngineMemoriesConfig .model_validate (config )
1558+ operation = self ._ingest_events (
1559+ name = name ,
1560+ scope = scope ,
1561+ stream_id = stream_id ,
1562+ direct_contents_source = direct_contents_source ,
1563+ config = config ,
1564+ )
1565+ if config .wait_for_completion and not operation .done :
1566+ operation = _agent_engines_utils ._await_operation (
1567+ operation_name = operation .name ,
1568+ get_operation_fn = self ._get_memory_operation ,
1569+ poll_interval_seconds = 0.5 ,
1570+ )
1571+ if operation .error :
1572+ raise RuntimeError (f"Failed to ingest events: { operation .error } " )
1573+ return operation
1574+
14191575
14201576class AsyncMemories (_api_module .BaseModule ):
14211577
@@ -2092,6 +2248,71 @@ async def _purge(
20922248 self ._api_client ._verify_response (return_value )
20932249 return return_value
20942250
2251+ async def _ingest_events (
2252+ self ,
2253+ * ,
2254+ config : Optional [types .IngestEventsConfigOrDict ] = None ,
2255+ name : str ,
2256+ stream_id : Optional [str ] = None ,
2257+ direct_contents_source : Optional [
2258+ types .IngestionDirectContentsSourceOrDict
2259+ ] = None ,
2260+ scope : Optional [dict [str , str ]] = None ,
2261+ generation_trigger_config : Optional [types .GenerationTriggerConfigOrDict ] = None ,
2262+ ) -> types .MemoryBankIngestEventsOperation :
2263+ """
2264+ Ingest events into a Memory Bank.
2265+ """
2266+
2267+ parameter_model = types ._IngestEventsRequestParameters (
2268+ config = config ,
2269+ name = name ,
2270+ stream_id = stream_id ,
2271+ direct_contents_source = direct_contents_source ,
2272+ scope = scope ,
2273+ generation_trigger_config = generation_trigger_config ,
2274+ )
2275+
2276+ request_url_dict : Optional [dict [str , str ]]
2277+ if not self ._api_client .vertexai :
2278+ raise ValueError ("This method is only supported in the Vertex AI client." )
2279+ else :
2280+ request_dict = _IngestEventsRequestParameters_to_vertex (parameter_model )
2281+ request_url_dict = request_dict .get ("_url" )
2282+ if request_url_dict :
2283+ path = "{name}/memories:ingestEvents" .format_map (request_url_dict )
2284+ else :
2285+ path = "{name}/memories:ingestEvents"
2286+
2287+ query_params = request_dict .get ("_query" )
2288+ if query_params :
2289+ path = f"{ path } ?{ urlencode (query_params )} "
2290+ # TODO: remove the hack that pops config.
2291+ request_dict .pop ("config" , None )
2292+
2293+ http_options : Optional [types .HttpOptions ] = None
2294+ if (
2295+ parameter_model .config is not None
2296+ and parameter_model .config .http_options is not None
2297+ ):
2298+ http_options = parameter_model .config .http_options
2299+
2300+ request_dict = _common .convert_to_dict (request_dict )
2301+ request_dict = _common .encode_unserializable_types (request_dict )
2302+
2303+ response = await self ._api_client .async_request (
2304+ "post" , path , request_dict , http_options
2305+ )
2306+
2307+ response_dict = {} if not response .body else json .loads (response .body )
2308+
2309+ return_value = types .MemoryBankIngestEventsOperation ._from_response (
2310+ response = response_dict , kwargs = parameter_model .model_dump ()
2311+ )
2312+
2313+ self ._api_client ._verify_response (return_value )
2314+ return return_value
2315+
20952316 _revisions = None
20962317
20972318 @property
0 commit comments