@@ -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 ,
@@ -713,6 +759,69 @@ def get(
713759 self ._api_client ._verify_response (return_value )
714760 return return_value
715761
762+ def _ingest_events (
763+ self ,
764+ * ,
765+ config : Optional [types .IngestEventsConfigOrDict ] = None ,
766+ name : str ,
767+ stream_id : Optional [str ] = None ,
768+ direct_contents_source : Optional [
769+ types .IngestionDirectContentsSourceOrDict
770+ ] = None ,
771+ scope : Optional [dict [str , str ]] = None ,
772+ generation_trigger_config : Optional [types .GenerationTriggerConfigOrDict ] = None ,
773+ ) -> types .MemoryBankIngestEventsOperation :
774+ """
775+ Ingest events into a Memory Bank.
776+ """
777+
778+ parameter_model = types ._IngestEventsRequestParameters (
779+ config = config ,
780+ name = name ,
781+ stream_id = stream_id ,
782+ direct_contents_source = direct_contents_source ,
783+ scope = scope ,
784+ generation_trigger_config = generation_trigger_config ,
785+ )
786+
787+ request_url_dict : Optional [dict [str , str ]]
788+ if not self ._api_client .vertexai :
789+ raise ValueError ("This method is only supported in the Vertex AI client." )
790+ else :
791+ request_dict = _IngestEventsRequestParameters_to_vertex (parameter_model )
792+ request_url_dict = request_dict .get ("_url" )
793+ if request_url_dict :
794+ path = "{name}/memories:ingestEvents" .format_map (request_url_dict )
795+ else :
796+ path = "{name}/memories:ingestEvents"
797+
798+ query_params = request_dict .get ("_query" )
799+ if query_params :
800+ path = f"{ path } ?{ urlencode (query_params )} "
801+ # TODO: remove the hack that pops config.
802+ request_dict .pop ("config" , None )
803+
804+ http_options : Optional [types .HttpOptions ] = None
805+ if (
806+ parameter_model .config is not None
807+ and parameter_model .config .http_options is not None
808+ ):
809+ http_options = parameter_model .config .http_options
810+
811+ request_dict = _common .convert_to_dict (request_dict )
812+ request_dict = _common .encode_unserializable_types (request_dict )
813+
814+ response = self ._api_client .request ("post" , path , request_dict , http_options )
815+
816+ response_dict = {} if not response .body else json .loads (response .body )
817+
818+ return_value = types .MemoryBankIngestEventsOperation ._from_response (
819+ response = response_dict , kwargs = parameter_model .model_dump ()
820+ )
821+
822+ self ._api_client ._verify_response (return_value )
823+ return return_value
824+
716825 def _list (
717826 self ,
718827 * ,
@@ -1416,6 +1525,55 @@ 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+ generation_trigger_config : Optional [types .GenerationTriggerConfigOrDict ] = None ,
1538+ config : Optional [types .IngestEventsConfigOrDict ] = None ,
1539+ ) -> types .MemoryBankIngestEventsOperation :
1540+ """Ingests events into an Agent Engine.
1541+
1542+ Args:
1543+ name (str):
1544+ Required. The name of the Agent Engine to ingest events into.
1545+ scope (dict[str, str]):
1546+ Required. The scope of the events to ingest. For example,
1547+ {"user_id": "123"}.
1548+ config (IngestEventsConfig):
1549+ Optional. The configuration for the ingest events operation.
1550+
1551+ Returns:
1552+ AgentEngineIngestEventsOperation:
1553+ The operation for ingesting the events.
1554+ """
1555+ if config is None :
1556+ config = types .IngestEventsConfig ()
1557+ elif isinstance (config , dict ):
1558+ config = types .IngestEventsConfig .model_validate (config )
1559+ operation = self ._ingest_events (
1560+ name = name ,
1561+ scope = scope ,
1562+ stream_id = stream_id ,
1563+ generation_trigger_config = generation_trigger_config ,
1564+ direct_contents_source = direct_contents_source ,
1565+ config = config ,
1566+ )
1567+ if config .wait_for_completion and not operation .done :
1568+ operation = _agent_engines_utils ._await_operation (
1569+ operation_name = operation .name ,
1570+ get_operation_fn = self ._get_memory_operation ,
1571+ poll_interval_seconds = 0.5 ,
1572+ )
1573+ if operation .error :
1574+ raise RuntimeError (f"Failed to ingest events: { operation .error } " )
1575+ return operation
1576+
14191577
14201578class AsyncMemories (_api_module .BaseModule ):
14211579
@@ -1679,6 +1837,71 @@ async def get(
16791837 self ._api_client ._verify_response (return_value )
16801838 return return_value
16811839
1840+ async def _ingest_events (
1841+ self ,
1842+ * ,
1843+ config : Optional [types .IngestEventsConfigOrDict ] = None ,
1844+ name : str ,
1845+ stream_id : Optional [str ] = None ,
1846+ direct_contents_source : Optional [
1847+ types .IngestionDirectContentsSourceOrDict
1848+ ] = None ,
1849+ scope : Optional [dict [str , str ]] = None ,
1850+ generation_trigger_config : Optional [types .GenerationTriggerConfigOrDict ] = None ,
1851+ ) -> types .MemoryBankIngestEventsOperation :
1852+ """
1853+ Ingest events into a Memory Bank.
1854+ """
1855+
1856+ parameter_model = types ._IngestEventsRequestParameters (
1857+ config = config ,
1858+ name = name ,
1859+ stream_id = stream_id ,
1860+ direct_contents_source = direct_contents_source ,
1861+ scope = scope ,
1862+ generation_trigger_config = generation_trigger_config ,
1863+ )
1864+
1865+ request_url_dict : Optional [dict [str , str ]]
1866+ if not self ._api_client .vertexai :
1867+ raise ValueError ("This method is only supported in the Vertex AI client." )
1868+ else :
1869+ request_dict = _IngestEventsRequestParameters_to_vertex (parameter_model )
1870+ request_url_dict = request_dict .get ("_url" )
1871+ if request_url_dict :
1872+ path = "{name}/memories:ingestEvents" .format_map (request_url_dict )
1873+ else :
1874+ path = "{name}/memories:ingestEvents"
1875+
1876+ query_params = request_dict .get ("_query" )
1877+ if query_params :
1878+ path = f"{ path } ?{ urlencode (query_params )} "
1879+ # TODO: remove the hack that pops config.
1880+ request_dict .pop ("config" , None )
1881+
1882+ http_options : Optional [types .HttpOptions ] = None
1883+ if (
1884+ parameter_model .config is not None
1885+ and parameter_model .config .http_options is not None
1886+ ):
1887+ http_options = parameter_model .config .http_options
1888+
1889+ request_dict = _common .convert_to_dict (request_dict )
1890+ request_dict = _common .encode_unserializable_types (request_dict )
1891+
1892+ response = await self ._api_client .async_request (
1893+ "post" , path , request_dict , http_options
1894+ )
1895+
1896+ response_dict = {} if not response .body else json .loads (response .body )
1897+
1898+ return_value = types .MemoryBankIngestEventsOperation ._from_response (
1899+ response = response_dict , kwargs = parameter_model .model_dump ()
1900+ )
1901+
1902+ self ._api_client ._verify_response (return_value )
1903+ return return_value
1904+
16821905 async def _list (
16831906 self ,
16841907 * ,
0 commit comments