Skip to content

Commit c150d1e

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Add retrieve profiles
PiperOrigin-RevId: 893649750
1 parent 9df74eb commit c150d1e

3 files changed

Lines changed: 168 additions & 0 deletions

File tree

src/genai/converters/_memories_converters.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ export function retrieveAgentEngineMemoriesConfigToVertex(
408408
common.setValueByPath(parentObject, ['filterGroups'], transformedList);
409409
}
410410

411+
const fromMemoryTypes = common.getValueByPath(fromObject, ['memoryTypes']);
412+
if (parentObject !== undefined && fromMemoryTypes != null) {
413+
common.setValueByPath(parentObject, ['memoryTypes'], fromMemoryTypes);
414+
}
415+
411416
return toObject;
412417
}
413418

@@ -456,6 +461,24 @@ export function retrieveAgentEngineMemoriesRequestParametersToVertex(
456461
return toObject;
457462
}
458463

464+
export function retrieveMemoryProfilesRequestParametersToVertex(
465+
fromObject: types.RetrieveMemoryProfilesRequestParameters,
466+
): Record<string, unknown> {
467+
const toObject: Record<string, unknown> = {};
468+
469+
const fromName = common.getValueByPath(fromObject, ['name']);
470+
if (fromName != null) {
471+
common.setValueByPath(toObject, ['_url', 'name'], fromName);
472+
}
473+
474+
const fromScope = common.getValueByPath(fromObject, ['scope']);
475+
if (fromScope != null) {
476+
common.setValueByPath(toObject, ['scope'], fromScope);
477+
}
478+
479+
return toObject;
480+
}
481+
459482
export function rollbackAgentEngineMemoryRequestParametersToVertex(
460483
fromObject: types.RollbackAgentEngineMemoryRequestParameters,
461484
): Record<string, unknown> {

src/genai/memories.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,48 @@ export class Memories extends BaseModule {
354354
}
355355
}
356356

357+
async retrieveProfiles(
358+
params: types.RetrieveMemoryProfilesRequestParameters,
359+
): Promise<types.RetrieveProfilesResponse> {
360+
let response: Promise<types.RetrieveProfilesResponse>;
361+
362+
let path: string = '';
363+
let queryParams: Record<string, string> = {};
364+
if (this.apiClient.isVertexAI()) {
365+
const body =
366+
converters.retrieveMemoryProfilesRequestParametersToVertex(params);
367+
path = common.formatMap(
368+
'{name}/memories:retrieveProfiles',
369+
body['_url'] as Record<string, unknown>,
370+
);
371+
queryParams = body['_query'] as Record<string, string>;
372+
delete body['_url'];
373+
delete body['_query'];
374+
delete body['config'];
375+
376+
response = this.apiClient
377+
.request({
378+
path: path,
379+
queryParams: queryParams,
380+
body: JSON.stringify(body),
381+
httpMethod: 'POST',
382+
httpOptions: params.config?.httpOptions,
383+
abortSignal: params.config?.abortSignal,
384+
})
385+
.then((httpResponse) => {
386+
return httpResponse.json();
387+
}) as Promise<types.RetrieveProfilesResponse>;
388+
389+
return response.then((resp) => {
390+
const typedResp = new types.RetrieveProfilesResponse();
391+
Object.assign(typedResp, resp);
392+
return typedResp;
393+
});
394+
} else {
395+
throw new Error('This method is only supported by the Vertex AI.');
396+
}
397+
}
398+
357399
async rollbackInternal(
358400
params: types.RollbackAgentEngineMemoryRequestParameters,
359401
): Promise<types.AgentEngineRollbackMemoryOperation> {

src/genai/types/common.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ export enum ManagedTopicEnum {
6666
EXPLICIT_INSTRUCTIONS = 'EXPLICIT_INSTRUCTIONS',
6767
}
6868

69+
/** The type of the memory. */
70+
export enum MemoryType {
71+
/**
72+
* Represents an unspecified memory type. This value should not be used.
73+
*/
74+
MEMORY_TYPE_UNSPECIFIED = 'MEMORY_TYPE_UNSPECIFIED',
75+
/**
76+
* Indicates belonging to a collection of natural language memories.
77+
*/
78+
NATURAL_LANGUAGE_COLLECTION = 'NATURAL_LANGUAGE_COLLECTION',
79+
/**
80+
* Indicates belonging to a structured profile.
81+
*/
82+
STRUCTURED_PROFILE = 'STRUCTURED_PROFILE',
83+
}
84+
6985
/** Operator to apply to the filter. If not set, then EQUAL will be used. */
7086
export enum Operator {
7187
/**
@@ -449,6 +465,8 @@ export declare interface MemoryBankCustomizationConfig {
449465
scopeKeys?: string[];
450466
/** Optional. Represents configuration for customizing how memories are consolidated together. */
451467
consolidationConfig?: MemoryBankCustomizationConfigConsolidationConfig;
468+
/** Optional. Indicates whether natural language memory generation should be disabled for all requests. By default, natural language memory generation is enabled. Set this to `true` when you only want to generate structured memories. */
469+
disableNaturalLanguageMemories?: boolean;
452470
}
453471

454472
/** Configuration for how to generate memories. */
@@ -483,6 +501,24 @@ export declare interface ReasoningEngineContextSpecMemoryBankConfigTtlConfig {
483501
memoryRevisionDefaultTtl?: string;
484502
}
485503

504+
/** Represents the OpenAPI schema of the structured memories. */
505+
export declare interface StructuredMemoryConfigSchemaConfig {
506+
/** Required. Represents the ID of the schema. Must be 1-63 characters, start with a lowercase letter, and consist of lowercase letters, numbers, and hyphens. */
507+
id?: string;
508+
/** Required. Represents the OpenAPI schema of the structured memories. The schema `type` cannot be `ARRAY` when `memory_type` is `STRUCTURED_PROFILE`. */
509+
schema?: genaiTypes.Schema;
510+
/** Optional. Represents the type of the structured memories associated with the schema. If not set, then `STRUCTURED_PROFILE` will be used. */
511+
memoryType?: MemoryType;
512+
}
513+
514+
/** Represents configuration for organizing structured memories for a particular scope. */
515+
export declare interface StructuredMemoryConfig {
516+
/** Optional. Represents the scope keys (i.e. 'user_id') for which to use this config. A request's scope must include all of the provided keys for the config to be used (order does not matter). If empty, then the config will be used for all requests that do not have a more specific config. Only one default config is allowed per Memory Bank. */
517+
scopeKeys?: string[];
518+
/** Optional. Represents configuration of the structured memories' schemas. */
519+
schemaConfigs?: StructuredMemoryConfigSchemaConfig[];
520+
}
521+
486522
/** Specification for a Memory Bank. */
487523
export declare interface ReasoningEngineContextSpecMemoryBankConfig {
488524
/** Optional. Configuration for how to customize Memory Bank behavior for a particular scope. */
@@ -495,6 +531,8 @@ export declare interface ReasoningEngineContextSpecMemoryBankConfig {
495531
similaritySearchConfig?: ReasoningEngineContextSpecMemoryBankConfigSimilaritySearchConfig;
496532
/** Optional. Configuration for automatic TTL ("time-to-live") of the memories in the Memory Bank. If not set, TTL will not be applied automatically. The TTL can be explicitly set by modifying the `expire_time` of each Memory resource. */
497533
ttlConfig?: ReasoningEngineContextSpecMemoryBankConfigTtlConfig;
534+
/** Optional. Configuration for organizing structured memories for a particular scope. */
535+
structuredMemoryConfigs?: StructuredMemoryConfig[];
498536
}
499537

500538
/** Configuration for how Agent Engine sub-resources should manage context. */
@@ -996,6 +1034,14 @@ export declare interface CreateAgentEngineMemoryRequestParameters {
9961034
config?: AgentEngineMemoryConfig;
9971035
}
9981036

1037+
/** Represents the structured value of the memory. */
1038+
export declare interface MemoryStructuredContent {
1039+
/** Required. Represents the structured value of the memory. */
1040+
data?: Record<string, unknown>;
1041+
/** Required. Represents the schema ID for which this structured memory belongs to. */
1042+
schemaId?: string;
1043+
}
1044+
9991045
/** A memory. */
10001046
export declare interface Memory {
10011047
/** Output only. Timestamp when this Memory was created. */
@@ -1028,6 +1074,10 @@ export declare interface Memory {
10281074
ttl?: string;
10291075
/** Output only. Timestamp when this Memory was most recently updated. */
10301076
updateTime?: string;
1077+
/** Optional. Represents the type of the memory. If not set, the `NATURAL_LANGUAGE_COLLECTION` type is used. If `STRUCTURED_COLLECTION` or `STRUCTURED_PROFILE` is used, then `structured_data` must be provided. */
1078+
memoryType?: MemoryType;
1079+
/** Optional. Represents the structured content of the memory. */
1080+
structuredContent?: MemoryStructuredContent;
10311081
}
10321082

10331083
/** Operation that has an agent engine memory as a response. */
@@ -1347,6 +1397,11 @@ export declare interface RetrieveAgentEngineMemoriesConfig {
13471397
metadata.author = "agent 321"))`.
13481398
*/
13491399
filterGroups?: MemoryConjunctionFilter[];
1400+
/** Specifies the types of memories to retrieve. If this field is empty
1401+
or not provided, the request will default to retrieving only memories of
1402+
type `NATURAL_LANGUAGE_COLLECTION`. If populated, the request will
1403+
retrieve memories matching any of the specified `MemoryType` values. */
1404+
memoryTypes?: MemoryType[];
13501405
}
13511406

13521407
/** Parameters for retrieving agent engine memories. */
@@ -1382,6 +1437,48 @@ export class RetrieveMemoriesResponse {
13821437
retrievedMemories?: RetrieveMemoriesResponseRetrievedMemory[];
13831438
}
13841439

1440+
/** Config for retrieving memory profiles. */
1441+
export declare interface RetrieveMemoryProfilesConfig {
1442+
/** Used to override HTTP request options. */
1443+
httpOptions?: genaiTypes.HttpOptions;
1444+
/** Abort signal which can be used to cancel the request.
1445+
1446+
NOTE: AbortSignal is a client-only operation. Using it to cancel an
1447+
operation will not cancel the request in the service. You will still
1448+
be charged usage for any applicable operations.
1449+
*/
1450+
abortSignal?: AbortSignal;
1451+
}
1452+
1453+
/** Parameters for retrieving agent engine memory profiles. */
1454+
export declare interface RetrieveMemoryProfilesRequestParameters {
1455+
/** Name of the agent engine to retrieve memory profiles from. */
1456+
name: string;
1457+
/** The scope of the memories to retrieve.
1458+
1459+
A memory must have exactly the same scope as the scope provided here to be
1460+
retrieved (i.e. same keys and values). Order does not matter, but it is
1461+
case-sensitive. */
1462+
scope: Record<string, string>;
1463+
config?: RetrieveMemoryProfilesConfig;
1464+
}
1465+
1466+
/** A memory profile. */
1467+
export declare interface MemoryProfile {
1468+
/** Represents the ID of the schema. This ID corresponds to the `schema_id` defined inside the SchemaConfig, under StructuredMemoryCustomizationConfig. */
1469+
schemaId?: string;
1470+
/** Represents the profile data. */
1471+
profile?: Record<string, unknown>;
1472+
}
1473+
1474+
/** The response for retrieving memory profiles. */
1475+
export class RetrieveProfilesResponse {
1476+
/** The memory profiles. */
1477+
memoryProfiles?: Record<string, MemoryProfile>;
1478+
/** The retrieved structured profiles, which match the schemas under the requested scope. The key is the ID of the schema that the profile is linked with, which corresponds to the `schema_id` defined inside the `SchemaConfig`, under `StructuredMemoryCustomizationConfig`. */
1479+
profiles?: Record<string, MemoryProfile>;
1480+
}
1481+
13851482
/** Config for rolling back a memory. */
13861483
export declare interface RollbackAgentEngineMemoryConfig {
13871484
/** Used to override HTTP request options. */
@@ -1561,6 +1658,10 @@ export declare interface GetAgentEngineMemoryRevisionRequestParameters {
15611658
export declare interface IntermediateExtractedMemory {
15621659
/** Output only. The fact of the extracted memory. */
15631660
fact?: string;
1661+
/** Output only. Represents the structured value of the extracted memory. */
1662+
structuredData?: Record<string, unknown>;
1663+
/** Output only. Represents the explanation of why the information was extracted from the source content. */
1664+
context?: string;
15641665
}
15651666

15661667
/** A memory revision. */
@@ -1577,6 +1678,8 @@ export declare interface MemoryRevision {
15771678
labels?: Record<string, string>;
15781679
/** Identifier. The resource name of the Memory Revision. Format: `projects/{project}/locations/{location}/reasoningEngines/{reasoning_engine}/memories/{memory}/revisions/{memory_revision}` */
15791680
name?: string;
1681+
/** Output only. Represents the structured value of the memory at the time of revision creation. */
1682+
structuredData?: Record<string, unknown>;
15801683
}
15811684

15821685
/** Config for listing Agent Engine memory revisions. */

0 commit comments

Comments
 (0)