Skip to content

Commit 365a14a

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Add ingest_events method for Memory Bank.
feat: Add Agent Engine-level configuration for generation_trigger_config. PiperOrigin-RevId: 899735868
1 parent 7904635 commit 365a14a

File tree

3 files changed

+185
-0
lines changed

3 files changed

+185
-0
lines changed

src/genai/converters/_memories_converters.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,70 @@ export function getAgentEngineMemoryRequestParametersToVertex(
317317
return toObject;
318318
}
319319

320+
export function ingestEventsConfigToVertex(
321+
fromObject: types.IngestEventsConfig,
322+
parentObject: Record<string, unknown>,
323+
): Record<string, unknown> {
324+
const toObject: Record<string, unknown> = {};
325+
326+
const fromForceFlush = common.getValueByPath(fromObject, ['forceFlush']);
327+
if (parentObject !== undefined && fromForceFlush != null) {
328+
common.setValueByPath(parentObject, ['forceFlush'], fromForceFlush);
329+
}
330+
331+
return toObject;
332+
}
333+
334+
export function ingestEventsRequestParametersToVertex(
335+
fromObject: types.IngestEventsRequestParameters,
336+
): Record<string, unknown> {
337+
const toObject: Record<string, unknown> = {};
338+
339+
const fromName = common.getValueByPath(fromObject, ['name']);
340+
if (fromName != null) {
341+
common.setValueByPath(toObject, ['_url', 'name'], fromName);
342+
}
343+
344+
const fromStreamId = common.getValueByPath(fromObject, ['streamId']);
345+
if (fromStreamId != null) {
346+
common.setValueByPath(toObject, ['streamId'], fromStreamId);
347+
}
348+
349+
const fromDirectContentsSource = common.getValueByPath(fromObject, [
350+
'directContentsSource',
351+
]);
352+
if (fromDirectContentsSource != null) {
353+
common.setValueByPath(
354+
toObject,
355+
['directContentsSource'],
356+
fromDirectContentsSource,
357+
);
358+
}
359+
360+
const fromScope = common.getValueByPath(fromObject, ['scope']);
361+
if (fromScope != null) {
362+
common.setValueByPath(toObject, ['scope'], fromScope);
363+
}
364+
365+
const fromGenerationTriggerConfig = common.getValueByPath(fromObject, [
366+
'generationTriggerConfig',
367+
]);
368+
if (fromGenerationTriggerConfig != null) {
369+
common.setValueByPath(
370+
toObject,
371+
['generationTriggerConfig'],
372+
fromGenerationTriggerConfig,
373+
);
374+
}
375+
376+
const fromConfig = common.getValueByPath(fromObject, ['config']);
377+
if (fromConfig != null) {
378+
ingestEventsConfigToVertex(fromConfig, toObject);
379+
}
380+
381+
return toObject;
382+
}
383+
320384
export function listAgentEngineMemoryConfigToVertex(
321385
fromObject: types.ListAgentEngineMemoryConfig,
322386
parentObject: Record<string, unknown>,

src/genai/memories.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,45 @@ export class Memories extends BaseModule {
180180
}
181181
}
182182

183+
async ingestEventsInternal(
184+
params: types.IngestEventsRequestParameters,
185+
): Promise<types.MemoryBankIngestEventsOperation> {
186+
let response: Promise<types.MemoryBankIngestEventsOperation>;
187+
188+
let path: string = '';
189+
let queryParams: Record<string, string> = {};
190+
if (this.apiClient.isVertexAI()) {
191+
const body = converters.ingestEventsRequestParametersToVertex(params);
192+
path = common.formatMap(
193+
'{name}/memories:ingestEvents',
194+
body['_url'] as Record<string, unknown>,
195+
);
196+
queryParams = body['_query'] as Record<string, string>;
197+
delete body['_url'];
198+
delete body['_query'];
199+
delete body['config'];
200+
201+
response = this.apiClient
202+
.request({
203+
path: path,
204+
queryParams: queryParams,
205+
body: JSON.stringify(body),
206+
httpMethod: 'POST',
207+
httpOptions: params.config?.httpOptions,
208+
abortSignal: params.config?.abortSignal,
209+
})
210+
.then((httpResponse) => {
211+
return httpResponse.json();
212+
}) as Promise<types.MemoryBankIngestEventsOperation>;
213+
214+
return response.then((resp) => {
215+
return resp as types.MemoryBankIngestEventsOperation;
216+
});
217+
} else {
218+
throw new Error('This method is only supported by the Vertex AI.');
219+
}
220+
}
221+
183222
async listInternal(
184223
params: types.ListAgentEngineMemoryRequestParameters,
185224
): Promise<types.ListReasoningEnginesMemoriesResponse> {

src/genai/types/common.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,28 @@ export declare interface MemoryBankCustomizationConfig {
507507
disableNaturalLanguageMemories?: boolean;
508508
}
509509

510+
/** Represents the active rule that determines when to flush the buffer. */
511+
export declare interface MemoryGenerationTriggerConfigGenerationTriggerRule {
512+
/** Specifies to trigger generation when the event count reaches this limit. */
513+
eventCount?: number;
514+
/** Specifies to trigger generation at a fixed interval. The duration must have a minute-level granularity. */
515+
fixedInterval?: string;
516+
/** Specifies to trigger generation if the stream is inactive for the specified duration after the most recent event. The duration must have a minute-level granularity. */
517+
idleDuration?: string;
518+
}
519+
520+
/** The configuration for triggering memory generation for ingested events. */
521+
export declare interface MemoryGenerationTriggerConfig {
522+
/** Optional. Represents the active rule that determines when to flush the buffer. If not set, then the stream will be force flushed immediately. */
523+
generationRule?: MemoryGenerationTriggerConfigGenerationTriggerRule;
524+
}
525+
510526
/** Configuration for how to generate memories. */
511527
export declare interface ReasoningEngineContextSpecMemoryBankConfigGenerationConfig {
512528
/** Optional. The model used to generate memories. Format: `projects/{project}/locations/{location}/publishers/google/models/{model}`. */
513529
model?: string;
530+
/** Optional. Specifies the default trigger configuration for generating memories using `IngestEvents`. */
531+
generationTriggerConfig?: MemoryGenerationTriggerConfig;
514532
}
515533

516534
/** Configuration for how to perform similarity search on memories. */
@@ -1340,6 +1358,70 @@ export declare interface GetAgentEngineMemoryRequestParameters {
13401358
config?: GetAgentEngineMemoryConfig;
13411359
}
13421360

1361+
/** The direct contents source event for ingesting events. */
1362+
export declare interface IngestionDirectContentsSourceEvent {
1363+
/** Required. The content of the event. */
1364+
content?: genaiTypes.Content;
1365+
/** Optional. A unique identifier for the event. If an event with the same event_id is ingested multiple times, it will be de-duplicated. */
1366+
eventId?: string;
1367+
/** Optional. The time at which the event occurred. If provided, this timestamp will be used for ordering events within a stream. If not provided, the server-side ingestion time will be used. */
1368+
eventTime?: string;
1369+
}
1370+
1371+
/** The direct contents source for ingesting events. */
1372+
export declare interface IngestionDirectContentsSource {
1373+
/** Required. The events to ingest. */
1374+
events?: IngestionDirectContentsSourceEvent[];
1375+
}
1376+
1377+
/** Config for ingesting events. */
1378+
export declare interface IngestEventsConfig {
1379+
/** Used to override HTTP request options. */
1380+
httpOptions?: genaiTypes.HttpOptions;
1381+
/** Abort signal which can be used to cancel the request.
1382+
1383+
NOTE: AbortSignal is a client-only operation. Using it to cancel an
1384+
operation will not cancel the request in the service. You will still
1385+
be charged usage for any applicable operations.
1386+
*/
1387+
abortSignal?: AbortSignal;
1388+
/** Waits for the underlying memory generation operation to complete
1389+
before returning. Defaults to false. */
1390+
waitForCompletion?: boolean;
1391+
/** Optional. Forces a flush of all pending events in the stream and triggers memory generation immediately bypassing any conditions configured in the `generation_trigger_config`. */
1392+
forceFlush?: boolean;
1393+
}
1394+
1395+
/** Parameters for purging agent engine memories. */
1396+
export declare interface IngestEventsRequestParameters {
1397+
/** Name of the Agent Engine to ingest events into. */
1398+
name: string;
1399+
/** The ID of the stream to ingest events into. */
1400+
streamId?: string;
1401+
/** The direct memories source of the events that should be ingested. */
1402+
directContentsSource?: IngestionDirectContentsSource;
1403+
/** The scope of the memories that should be generated from the stream.
1404+
1405+
Memories will be consolidated across memories with the same scope. Scope
1406+
values cannot contain the wildcard character '*'. */
1407+
scope?: Record<string, string>;
1408+
/** The configuration for the memory generation trigger. */
1409+
generationTriggerConfig?: MemoryGenerationTriggerConfig;
1410+
config?: IngestEventsConfig;
1411+
}
1412+
1413+
/** Operation that ingests events into a memory bank. */
1414+
export declare interface MemoryBankIngestEventsOperation {
1415+
/** The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`. */
1416+
name?: string;
1417+
/** Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any. */
1418+
metadata?: Record<string, unknown>;
1419+
/** If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available. */
1420+
done?: boolean;
1421+
/** The error result of the operation in case of failure or cancellation. */
1422+
error?: Record<string, unknown>;
1423+
}
1424+
13431425
/** Config for listing agent engine memories. */
13441426
export declare interface ListAgentEngineMemoryConfig {
13451427
/** Used to override HTTP request options. */

0 commit comments

Comments
 (0)