@voltagent/core 2.6.5 → 2.6.6
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.
- package/dist/index.d.mts +52 -6
- package/dist/index.d.ts +52 -6
- package/dist/index.js +164 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +164 -87
- package/dist/index.mjs.map +1 -1
- package/docs/agents/memory/in-memory.md +8 -4
- package/docs/agents/memory/overview.md +18 -10
- package/docs/agents/memory/semantic-search.md +21 -13
- package/docs/agents/memory/working-memory.md +16 -8
- package/docs/agents/memory.md +8 -4
- package/docs/agents/overview.md +10 -4
- package/docs/agents/voltagent-instance.md +2 -1
- package/docs/api/api-reference.md +18 -3
- package/docs/api/endpoints/agents.md +44 -17
- package/docs/ui/ai-sdk-integration.md +52 -28
- package/docs/ui/assistant-ui.md +4 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -8390,6 +8390,35 @@ interface AgentEvalConfig {
|
|
|
8390
8390
|
sampling?: AgentEvalSamplingPolicy;
|
|
8391
8391
|
redact?: (payload: AgentEvalPayload) => AgentEvalPayload;
|
|
8392
8392
|
}
|
|
8393
|
+
/**
|
|
8394
|
+
* Common generate options - internal version that includes historyEntryId
|
|
8395
|
+
* Not exposed directly to users
|
|
8396
|
+
*/
|
|
8397
|
+
interface CommonSemanticMemoryOptions {
|
|
8398
|
+
enabled?: boolean;
|
|
8399
|
+
semanticLimit?: number;
|
|
8400
|
+
semanticThreshold?: number;
|
|
8401
|
+
mergeStrategy?: "prepend" | "append" | "interleave";
|
|
8402
|
+
}
|
|
8403
|
+
interface CommonRuntimeMemoryBehaviorOptions {
|
|
8404
|
+
contextLimit?: number;
|
|
8405
|
+
semanticMemory?: CommonSemanticMemoryOptions;
|
|
8406
|
+
conversationPersistence?: AgentConversationPersistenceOptions;
|
|
8407
|
+
}
|
|
8408
|
+
interface CommonRuntimeMemoryEnvelope {
|
|
8409
|
+
conversationId?: string;
|
|
8410
|
+
userId?: string;
|
|
8411
|
+
options?: CommonRuntimeMemoryBehaviorOptions;
|
|
8412
|
+
}
|
|
8413
|
+
type SemanticMemoryOptions = CommonSemanticMemoryOptions;
|
|
8414
|
+
type RuntimeMemoryEnvelope = CommonRuntimeMemoryEnvelope;
|
|
8415
|
+
interface CommonResolvedRuntimeMemoryOptions {
|
|
8416
|
+
userId?: string;
|
|
8417
|
+
conversationId?: string;
|
|
8418
|
+
contextLimit?: number;
|
|
8419
|
+
semanticMemory?: CommonSemanticMemoryOptions;
|
|
8420
|
+
conversationPersistence?: AgentConversationPersistenceOptions;
|
|
8421
|
+
}
|
|
8393
8422
|
/**
|
|
8394
8423
|
* Agent status information
|
|
8395
8424
|
*/
|
|
@@ -8459,6 +8488,8 @@ type OperationContext = {
|
|
|
8459
8488
|
userId?: string;
|
|
8460
8489
|
/** Optional conversation identifier associated with this operation */
|
|
8461
8490
|
conversationId?: string;
|
|
8491
|
+
/** Resolved runtime memory options (memory envelope preferred, legacy as fallback) */
|
|
8492
|
+
resolvedMemory?: CommonResolvedRuntimeMemoryOptions;
|
|
8462
8493
|
/** Workspace configured on the executing agent (if any). */
|
|
8463
8494
|
workspace?: Workspace;
|
|
8464
8495
|
/** User-managed context map for this operation */
|
|
@@ -9177,7 +9208,17 @@ interface GenerateObjectResultWithContext<T> extends GenerateObjectResult<T> {
|
|
|
9177
9208
|
* Extends AI SDK's CallSettings for full compatibility
|
|
9178
9209
|
*/
|
|
9179
9210
|
interface BaseGenerationOptions<TProviderOptions extends ProviderOptions$1 = ProviderOptions$1> extends Partial<CallSettings> {
|
|
9211
|
+
/**
|
|
9212
|
+
* Runtime memory envelope for per-call memory identity and behavior overrides.
|
|
9213
|
+
*/
|
|
9214
|
+
memory?: RuntimeMemoryEnvelope;
|
|
9215
|
+
/**
|
|
9216
|
+
* @deprecated Use `memory.userId` instead.
|
|
9217
|
+
*/
|
|
9180
9218
|
userId?: string;
|
|
9219
|
+
/**
|
|
9220
|
+
* @deprecated Use `memory.conversationId` instead.
|
|
9221
|
+
*/
|
|
9181
9222
|
conversationId?: string;
|
|
9182
9223
|
context?: ContextInput;
|
|
9183
9224
|
elicitation?: (request: unknown) => Promise<unknown>;
|
|
@@ -9185,13 +9226,17 @@ interface BaseGenerationOptions<TProviderOptions extends ProviderOptions$1 = Pro
|
|
|
9185
9226
|
parentOperationContext?: OperationContext;
|
|
9186
9227
|
parentSpan?: Span;
|
|
9187
9228
|
inheritParentSpan?: boolean;
|
|
9229
|
+
/**
|
|
9230
|
+
* @deprecated Use `memory.options.contextLimit` instead.
|
|
9231
|
+
*/
|
|
9188
9232
|
contextLimit?: number;
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9193
|
-
|
|
9194
|
-
|
|
9233
|
+
/**
|
|
9234
|
+
* @deprecated Use `memory.options.semanticMemory` instead.
|
|
9235
|
+
*/
|
|
9236
|
+
semanticMemory?: SemanticMemoryOptions;
|
|
9237
|
+
/**
|
|
9238
|
+
* @deprecated Use `memory.options.conversationPersistence` instead.
|
|
9239
|
+
*/
|
|
9195
9240
|
conversationPersistence?: AgentConversationPersistenceOptions;
|
|
9196
9241
|
maxSteps?: number;
|
|
9197
9242
|
feedback?: boolean | AgentFeedbackOptions;
|
|
@@ -9321,6 +9366,7 @@ declare class Agent {
|
|
|
9321
9366
|
*/
|
|
9322
9367
|
private normalizeConversationPersistenceOptions;
|
|
9323
9368
|
private resolveConversationPersistenceOptions;
|
|
9369
|
+
private resolveMemoryRuntimeOptions;
|
|
9324
9370
|
private getConversationPersistenceOptionsForContext;
|
|
9325
9371
|
/**
|
|
9326
9372
|
* Create only the OperationContext (sync)
|
package/dist/index.d.ts
CHANGED
|
@@ -8390,6 +8390,35 @@ interface AgentEvalConfig {
|
|
|
8390
8390
|
sampling?: AgentEvalSamplingPolicy;
|
|
8391
8391
|
redact?: (payload: AgentEvalPayload) => AgentEvalPayload;
|
|
8392
8392
|
}
|
|
8393
|
+
/**
|
|
8394
|
+
* Common generate options - internal version that includes historyEntryId
|
|
8395
|
+
* Not exposed directly to users
|
|
8396
|
+
*/
|
|
8397
|
+
interface CommonSemanticMemoryOptions {
|
|
8398
|
+
enabled?: boolean;
|
|
8399
|
+
semanticLimit?: number;
|
|
8400
|
+
semanticThreshold?: number;
|
|
8401
|
+
mergeStrategy?: "prepend" | "append" | "interleave";
|
|
8402
|
+
}
|
|
8403
|
+
interface CommonRuntimeMemoryBehaviorOptions {
|
|
8404
|
+
contextLimit?: number;
|
|
8405
|
+
semanticMemory?: CommonSemanticMemoryOptions;
|
|
8406
|
+
conversationPersistence?: AgentConversationPersistenceOptions;
|
|
8407
|
+
}
|
|
8408
|
+
interface CommonRuntimeMemoryEnvelope {
|
|
8409
|
+
conversationId?: string;
|
|
8410
|
+
userId?: string;
|
|
8411
|
+
options?: CommonRuntimeMemoryBehaviorOptions;
|
|
8412
|
+
}
|
|
8413
|
+
type SemanticMemoryOptions = CommonSemanticMemoryOptions;
|
|
8414
|
+
type RuntimeMemoryEnvelope = CommonRuntimeMemoryEnvelope;
|
|
8415
|
+
interface CommonResolvedRuntimeMemoryOptions {
|
|
8416
|
+
userId?: string;
|
|
8417
|
+
conversationId?: string;
|
|
8418
|
+
contextLimit?: number;
|
|
8419
|
+
semanticMemory?: CommonSemanticMemoryOptions;
|
|
8420
|
+
conversationPersistence?: AgentConversationPersistenceOptions;
|
|
8421
|
+
}
|
|
8393
8422
|
/**
|
|
8394
8423
|
* Agent status information
|
|
8395
8424
|
*/
|
|
@@ -8459,6 +8488,8 @@ type OperationContext = {
|
|
|
8459
8488
|
userId?: string;
|
|
8460
8489
|
/** Optional conversation identifier associated with this operation */
|
|
8461
8490
|
conversationId?: string;
|
|
8491
|
+
/** Resolved runtime memory options (memory envelope preferred, legacy as fallback) */
|
|
8492
|
+
resolvedMemory?: CommonResolvedRuntimeMemoryOptions;
|
|
8462
8493
|
/** Workspace configured on the executing agent (if any). */
|
|
8463
8494
|
workspace?: Workspace;
|
|
8464
8495
|
/** User-managed context map for this operation */
|
|
@@ -9177,7 +9208,17 @@ interface GenerateObjectResultWithContext<T> extends GenerateObjectResult<T> {
|
|
|
9177
9208
|
* Extends AI SDK's CallSettings for full compatibility
|
|
9178
9209
|
*/
|
|
9179
9210
|
interface BaseGenerationOptions<TProviderOptions extends ProviderOptions$1 = ProviderOptions$1> extends Partial<CallSettings> {
|
|
9211
|
+
/**
|
|
9212
|
+
* Runtime memory envelope for per-call memory identity and behavior overrides.
|
|
9213
|
+
*/
|
|
9214
|
+
memory?: RuntimeMemoryEnvelope;
|
|
9215
|
+
/**
|
|
9216
|
+
* @deprecated Use `memory.userId` instead.
|
|
9217
|
+
*/
|
|
9180
9218
|
userId?: string;
|
|
9219
|
+
/**
|
|
9220
|
+
* @deprecated Use `memory.conversationId` instead.
|
|
9221
|
+
*/
|
|
9181
9222
|
conversationId?: string;
|
|
9182
9223
|
context?: ContextInput;
|
|
9183
9224
|
elicitation?: (request: unknown) => Promise<unknown>;
|
|
@@ -9185,13 +9226,17 @@ interface BaseGenerationOptions<TProviderOptions extends ProviderOptions$1 = Pro
|
|
|
9185
9226
|
parentOperationContext?: OperationContext;
|
|
9186
9227
|
parentSpan?: Span;
|
|
9187
9228
|
inheritParentSpan?: boolean;
|
|
9229
|
+
/**
|
|
9230
|
+
* @deprecated Use `memory.options.contextLimit` instead.
|
|
9231
|
+
*/
|
|
9188
9232
|
contextLimit?: number;
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9193
|
-
|
|
9194
|
-
|
|
9233
|
+
/**
|
|
9234
|
+
* @deprecated Use `memory.options.semanticMemory` instead.
|
|
9235
|
+
*/
|
|
9236
|
+
semanticMemory?: SemanticMemoryOptions;
|
|
9237
|
+
/**
|
|
9238
|
+
* @deprecated Use `memory.options.conversationPersistence` instead.
|
|
9239
|
+
*/
|
|
9195
9240
|
conversationPersistence?: AgentConversationPersistenceOptions;
|
|
9196
9241
|
maxSteps?: number;
|
|
9197
9242
|
feedback?: boolean | AgentFeedbackOptions;
|
|
@@ -9321,6 +9366,7 @@ declare class Agent {
|
|
|
9321
9366
|
*/
|
|
9322
9367
|
private normalizeConversationPersistenceOptions;
|
|
9323
9368
|
private resolveConversationPersistenceOptions;
|
|
9369
|
+
private resolveMemoryRuntimeOptions;
|
|
9324
9370
|
private getConversationPersistenceOptionsForContext;
|
|
9325
9371
|
/**
|
|
9326
9372
|
* Create only the OperationContext (sync)
|
package/dist/index.js
CHANGED
|
@@ -30033,6 +30033,14 @@ var DEFAULT_CONVERSATION_PERSISTENCE_OPTIONS = {
|
|
|
30033
30033
|
};
|
|
30034
30034
|
var isRecord4 = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null, "isRecord");
|
|
30035
30035
|
var hasNonEmptyString2 = /* @__PURE__ */ __name((value) => typeof value === "string" && value.trim().length > 0, "hasNonEmptyString");
|
|
30036
|
+
var firstNonBlank = /* @__PURE__ */ __name((...values) => {
|
|
30037
|
+
for (const value of values) {
|
|
30038
|
+
if (hasNonEmptyString2(value)) {
|
|
30039
|
+
return value;
|
|
30040
|
+
}
|
|
30041
|
+
}
|
|
30042
|
+
return void 0;
|
|
30043
|
+
}, "firstNonBlank");
|
|
30036
30044
|
var isAssistantContentPart = /* @__PURE__ */ __name((value) => {
|
|
30037
30045
|
if (!isRecord4(value)) {
|
|
30038
30046
|
return false;
|
|
@@ -30470,7 +30478,8 @@ var Agent = class {
|
|
|
30470
30478
|
this
|
|
30471
30479
|
);
|
|
30472
30480
|
const { messages, uiMessages, modelName, tools, maxSteps } = await this.prepareExecution(effectiveInput, oc, options);
|
|
30473
|
-
const
|
|
30481
|
+
const resolvedMemory = this.resolveMemoryRuntimeOptions(options, oc);
|
|
30482
|
+
const contextLimit = resolvedMemory.contextLimit;
|
|
30474
30483
|
addModelAttributesToSpan(
|
|
30475
30484
|
rootSpan,
|
|
30476
30485
|
modelName,
|
|
@@ -30516,6 +30525,7 @@ var Agent = class {
|
|
|
30516
30525
|
const {
|
|
30517
30526
|
userId,
|
|
30518
30527
|
conversationId,
|
|
30528
|
+
memory: _memory,
|
|
30519
30529
|
context: context8,
|
|
30520
30530
|
// Explicitly exclude to prevent collision with AI SDK's future 'context' field
|
|
30521
30531
|
parentAgentId,
|
|
@@ -30524,6 +30534,8 @@ var Agent = class {
|
|
|
30524
30534
|
feedback: _feedback,
|
|
30525
30535
|
maxSteps: userMaxSteps,
|
|
30526
30536
|
tools: userTools,
|
|
30537
|
+
contextLimit: _contextLimit,
|
|
30538
|
+
semanticMemory: _semanticMemory,
|
|
30527
30539
|
conversationPersistence: _conversationPersistence,
|
|
30528
30540
|
output,
|
|
30529
30541
|
providerOptions,
|
|
@@ -30954,7 +30966,8 @@ var Agent = class {
|
|
|
30954
30966
|
oc,
|
|
30955
30967
|
options
|
|
30956
30968
|
);
|
|
30957
|
-
const
|
|
30969
|
+
const resolvedMemory = this.resolveMemoryRuntimeOptions(options, oc);
|
|
30970
|
+
const contextLimit = resolvedMemory.contextLimit;
|
|
30958
30971
|
if (oc.traceContext) {
|
|
30959
30972
|
const rootSpan2 = oc.traceContext.getRootSpan();
|
|
30960
30973
|
addModelAttributesToSpan(
|
|
@@ -30994,6 +31007,7 @@ var Agent = class {
|
|
|
30994
31007
|
const {
|
|
30995
31008
|
userId,
|
|
30996
31009
|
conversationId,
|
|
31010
|
+
memory: _memory,
|
|
30997
31011
|
context: context8,
|
|
30998
31012
|
// Explicitly exclude to prevent collision with AI SDK's future 'context' field
|
|
30999
31013
|
parentAgentId,
|
|
@@ -31003,6 +31017,8 @@ var Agent = class {
|
|
|
31003
31017
|
maxSteps: userMaxSteps,
|
|
31004
31018
|
tools: userTools,
|
|
31005
31019
|
onFinish: userOnFinish,
|
|
31020
|
+
contextLimit: _contextLimit,
|
|
31021
|
+
semanticMemory: _semanticMemory,
|
|
31006
31022
|
conversationPersistence: _conversationPersistence,
|
|
31007
31023
|
output,
|
|
31008
31024
|
providerOptions,
|
|
@@ -31656,6 +31672,7 @@ var Agent = class {
|
|
|
31656
31672
|
const {
|
|
31657
31673
|
userId,
|
|
31658
31674
|
conversationId,
|
|
31675
|
+
memory: _memory,
|
|
31659
31676
|
context: context8,
|
|
31660
31677
|
// Explicitly exclude to prevent collision with AI SDK's future 'context' field
|
|
31661
31678
|
parentAgentId,
|
|
@@ -31664,6 +31681,8 @@ var Agent = class {
|
|
|
31664
31681
|
feedback: _feedback,
|
|
31665
31682
|
maxSteps: userMaxSteps,
|
|
31666
31683
|
tools: userTools,
|
|
31684
|
+
contextLimit: _contextLimit,
|
|
31685
|
+
semanticMemory: _semanticMemory,
|
|
31667
31686
|
conversationPersistence: _conversationPersistence,
|
|
31668
31687
|
output: _output,
|
|
31669
31688
|
providerOptions,
|
|
@@ -31945,6 +31964,7 @@ var Agent = class {
|
|
|
31945
31964
|
const {
|
|
31946
31965
|
userId,
|
|
31947
31966
|
conversationId,
|
|
31967
|
+
memory: _memory,
|
|
31948
31968
|
context: context8,
|
|
31949
31969
|
// Explicitly exclude to prevent collision with AI SDK's future 'context' field
|
|
31950
31970
|
parentAgentId,
|
|
@@ -31954,6 +31974,8 @@ var Agent = class {
|
|
|
31954
31974
|
maxSteps: userMaxSteps,
|
|
31955
31975
|
tools: userTools,
|
|
31956
31976
|
onFinish: userOnFinish,
|
|
31977
|
+
contextLimit: _contextLimit,
|
|
31978
|
+
semanticMemory: _semanticMemory,
|
|
31957
31979
|
conversationPersistence: _conversationPersistence,
|
|
31958
31980
|
output: _output,
|
|
31959
31981
|
providerOptions,
|
|
@@ -32331,15 +32353,44 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
32331
32353
|
};
|
|
32332
32354
|
}
|
|
32333
32355
|
resolveConversationPersistenceOptions(options) {
|
|
32334
|
-
|
|
32356
|
+
const resolvedMemory = this.resolveMemoryRuntimeOptions(options);
|
|
32357
|
+
if (!resolvedMemory.conversationPersistence) {
|
|
32335
32358
|
return { ...this.conversationPersistence };
|
|
32336
32359
|
}
|
|
32360
|
+
const conversationPersistence = resolvedMemory.conversationPersistence;
|
|
32337
32361
|
return this.normalizeConversationPersistenceOptions({
|
|
32338
|
-
mode:
|
|
32339
|
-
debounceMs:
|
|
32340
|
-
flushOnToolResult:
|
|
32362
|
+
mode: conversationPersistence.mode ?? this.conversationPersistence.mode,
|
|
32363
|
+
debounceMs: conversationPersistence.debounceMs ?? this.conversationPersistence.debounceMs,
|
|
32364
|
+
flushOnToolResult: conversationPersistence.flushOnToolResult ?? this.conversationPersistence.flushOnToolResult
|
|
32341
32365
|
});
|
|
32342
32366
|
}
|
|
32367
|
+
resolveMemoryRuntimeOptions(options, operationContext) {
|
|
32368
|
+
const memory = options?.memory;
|
|
32369
|
+
const memoryOptions = memory?.options;
|
|
32370
|
+
const contextResolvedMemory = operationContext?.resolvedMemory;
|
|
32371
|
+
const parentResolvedMemory = options?.parentOperationContext?.resolvedMemory;
|
|
32372
|
+
const parentUserId = parentResolvedMemory?.userId ?? options?.parentOperationContext?.userId;
|
|
32373
|
+
const parentConversationId = parentResolvedMemory?.conversationId ?? options?.parentOperationContext?.conversationId;
|
|
32374
|
+
return {
|
|
32375
|
+
userId: firstNonBlank(
|
|
32376
|
+
contextResolvedMemory?.userId,
|
|
32377
|
+
operationContext?.userId,
|
|
32378
|
+
memory?.userId,
|
|
32379
|
+
options?.userId,
|
|
32380
|
+
parentUserId
|
|
32381
|
+
),
|
|
32382
|
+
conversationId: firstNonBlank(
|
|
32383
|
+
contextResolvedMemory?.conversationId,
|
|
32384
|
+
operationContext?.conversationId,
|
|
32385
|
+
memory?.conversationId,
|
|
32386
|
+
options?.conversationId,
|
|
32387
|
+
parentConversationId
|
|
32388
|
+
),
|
|
32389
|
+
contextLimit: contextResolvedMemory?.contextLimit ?? memoryOptions?.contextLimit ?? options?.contextLimit ?? parentResolvedMemory?.contextLimit,
|
|
32390
|
+
semanticMemory: contextResolvedMemory?.semanticMemory ?? memoryOptions?.semanticMemory ?? options?.semanticMemory ?? parentResolvedMemory?.semanticMemory,
|
|
32391
|
+
conversationPersistence: contextResolvedMemory?.conversationPersistence ?? memoryOptions?.conversationPersistence ?? options?.conversationPersistence ?? parentResolvedMemory?.conversationPersistence
|
|
32392
|
+
};
|
|
32393
|
+
}
|
|
32343
32394
|
getConversationPersistenceOptionsForContext(oc) {
|
|
32344
32395
|
const fromContext = oc.systemContext.get(CONVERSATION_PERSISTENCE_OPTIONS_KEY);
|
|
32345
32396
|
if (fromContext) {
|
|
@@ -32356,6 +32407,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
32356
32407
|
createOperationContext(input, options) {
|
|
32357
32408
|
const operationId = randomUUID();
|
|
32358
32409
|
const startTimeDate = /* @__PURE__ */ new Date();
|
|
32410
|
+
const resolvedMemory = this.resolveMemoryRuntimeOptions(options);
|
|
32359
32411
|
const runtimeContext = toContextMap(options?.context);
|
|
32360
32412
|
const parentContext = options?.parentOperationContext?.context;
|
|
32361
32413
|
let context8;
|
|
@@ -32393,16 +32445,16 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
32393
32445
|
}
|
|
32394
32446
|
const logger = this.getContextualLogger(options?.parentAgentId).child({
|
|
32395
32447
|
operationId,
|
|
32396
|
-
userId:
|
|
32397
|
-
conversationId:
|
|
32448
|
+
userId: resolvedMemory.userId,
|
|
32449
|
+
conversationId: resolvedMemory.conversationId,
|
|
32398
32450
|
executionId: operationId
|
|
32399
32451
|
});
|
|
32400
32452
|
const observability = this.getObservability();
|
|
32401
32453
|
const traceContext = new AgentTraceContext(observability, this.name, {
|
|
32402
32454
|
agentId: this.id,
|
|
32403
32455
|
agentName: this.name,
|
|
32404
|
-
userId:
|
|
32405
|
-
conversationId:
|
|
32456
|
+
userId: resolvedMemory.userId,
|
|
32457
|
+
conversationId: resolvedMemory.conversationId,
|
|
32406
32458
|
operationId,
|
|
32407
32459
|
parentSpan: options?.parentSpan,
|
|
32408
32460
|
inheritParentSpan: options?.inheritParentSpan ?? this.inheritParentSpan,
|
|
@@ -32444,8 +32496,9 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
32444
32496
|
logger,
|
|
32445
32497
|
conversationSteps: options?.parentOperationContext?.conversationSteps || [],
|
|
32446
32498
|
abortController,
|
|
32447
|
-
userId:
|
|
32448
|
-
conversationId:
|
|
32499
|
+
userId: resolvedMemory.userId,
|
|
32500
|
+
conversationId: resolvedMemory.conversationId,
|
|
32501
|
+
resolvedMemory: { ...resolvedMemory },
|
|
32449
32502
|
workspace: this.workspace,
|
|
32450
32503
|
parentAgentId: options?.parentAgentId,
|
|
32451
32504
|
traceContext,
|
|
@@ -32951,62 +33004,22 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
32951
33004
|
async prepareMessages(input, oc, options, buffer, runtimeToolkits = []) {
|
|
32952
33005
|
const resolvedInput = await this.validateIncomingUIMessages(input, oc);
|
|
32953
33006
|
const messages = [];
|
|
32954
|
-
const
|
|
32955
|
-
|
|
32956
|
-
|
|
32957
|
-
if (typeof systemMessage === "string") {
|
|
32958
|
-
return [
|
|
32959
|
-
{
|
|
32960
|
-
id: randomUUID(),
|
|
32961
|
-
role: "system",
|
|
32962
|
-
parts: [
|
|
32963
|
-
{
|
|
32964
|
-
type: "text",
|
|
32965
|
-
text: systemMessage
|
|
32966
|
-
}
|
|
32967
|
-
]
|
|
32968
|
-
}
|
|
32969
|
-
];
|
|
32970
|
-
}
|
|
32971
|
-
if (Array.isArray(systemMessage)) {
|
|
32972
|
-
return convertModelMessagesToUIMessages(systemMessage);
|
|
32973
|
-
}
|
|
32974
|
-
return convertModelMessagesToUIMessages([systemMessage]);
|
|
32975
|
-
})();
|
|
32976
|
-
for (const systemUIMessage of systemMessagesAsUI) {
|
|
32977
|
-
messages.push(systemUIMessage);
|
|
32978
|
-
}
|
|
32979
|
-
const instructionText = systemMessagesAsUI.flatMap(
|
|
32980
|
-
(msg) => msg.parts.flatMap(
|
|
32981
|
-
(part) => part.type === "text" && typeof part.text === "string" ? [part.text] : []
|
|
32982
|
-
)
|
|
32983
|
-
).join("\n\n");
|
|
32984
|
-
if (instructionText) {
|
|
32985
|
-
oc.traceContext.setInstructions(instructionText);
|
|
32986
|
-
}
|
|
32987
|
-
}
|
|
32988
|
-
const middlewareRetryFeedback = this.consumeMiddlewareRetryFeedback(oc);
|
|
32989
|
-
if (middlewareRetryFeedback) {
|
|
32990
|
-
messages.push({
|
|
32991
|
-
id: randomUUID(),
|
|
32992
|
-
role: "system",
|
|
32993
|
-
parts: [{ type: "text", text: middlewareRetryFeedback }]
|
|
32994
|
-
});
|
|
32995
|
-
}
|
|
32996
|
-
const canIUseMemory = options?.userId && options.conversationId;
|
|
33007
|
+
const resolvedMemory = this.resolveMemoryRuntimeOptions(options, oc);
|
|
33008
|
+
const canIUseMemory = Boolean(resolvedMemory.userId);
|
|
33009
|
+
const memoryContextMessages = [];
|
|
32997
33010
|
if (canIUseMemory) {
|
|
32998
|
-
const useSemanticSearch =
|
|
33011
|
+
const useSemanticSearch = resolvedMemory.semanticMemory?.enabled ?? this.hasSemanticSearchSupport();
|
|
32999
33012
|
const currentQuery = useSemanticSearch ? this.extractUserQuery(resolvedInput) : void 0;
|
|
33000
|
-
const semanticLimit =
|
|
33001
|
-
const semanticThreshold =
|
|
33002
|
-
const mergeStrategy =
|
|
33013
|
+
const semanticLimit = resolvedMemory.semanticMemory?.semanticLimit ?? 5;
|
|
33014
|
+
const semanticThreshold = resolvedMemory.semanticMemory?.semanticThreshold ?? 0.7;
|
|
33015
|
+
const mergeStrategy = resolvedMemory.semanticMemory?.mergeStrategy ?? "append";
|
|
33003
33016
|
const isSemanticSearch = useSemanticSearch && currentQuery;
|
|
33004
33017
|
const traceContext = oc.traceContext;
|
|
33005
33018
|
if (traceContext) {
|
|
33006
33019
|
const spanInput = {
|
|
33007
33020
|
query: isSemanticSearch ? currentQuery : resolvedInput,
|
|
33008
|
-
userId:
|
|
33009
|
-
conversationId:
|
|
33021
|
+
userId: resolvedMemory.userId,
|
|
33022
|
+
conversationId: resolvedMemory.conversationId
|
|
33010
33023
|
};
|
|
33011
33024
|
const memoryReadSpan = traceContext.createChildSpan("memory.read", "memory", {
|
|
33012
33025
|
label: isSemanticSearch ? "Semantic Memory Read" : "Memory Context Read",
|
|
@@ -33028,7 +33041,7 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33028
33041
|
oc,
|
|
33029
33042
|
oc.userId,
|
|
33030
33043
|
oc.conversationId,
|
|
33031
|
-
|
|
33044
|
+
resolvedMemory.contextLimit,
|
|
33032
33045
|
{
|
|
33033
33046
|
useSemanticSearch: true,
|
|
33034
33047
|
currentQuery,
|
|
@@ -33048,9 +33061,12 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33048
33061
|
inputForMemory,
|
|
33049
33062
|
oc.userId,
|
|
33050
33063
|
oc.conversationId,
|
|
33051
|
-
|
|
33064
|
+
resolvedMemory.contextLimit
|
|
33052
33065
|
);
|
|
33053
33066
|
oc.conversationId = result.conversationId;
|
|
33067
|
+
if (oc.resolvedMemory) {
|
|
33068
|
+
oc.resolvedMemory.conversationId = result.conversationId;
|
|
33069
|
+
}
|
|
33054
33070
|
buffer.ingestUIMessages(result.messages, true);
|
|
33055
33071
|
return result.messages;
|
|
33056
33072
|
});
|
|
@@ -33063,8 +33079,11 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33063
33079
|
});
|
|
33064
33080
|
if (isSemanticSearch && !oc.conversationId) {
|
|
33065
33081
|
oc.conversationId = randomUUID();
|
|
33082
|
+
if (oc.resolvedMemory) {
|
|
33083
|
+
oc.resolvedMemory.conversationId = oc.conversationId;
|
|
33084
|
+
}
|
|
33066
33085
|
}
|
|
33067
|
-
|
|
33086
|
+
memoryContextMessages.push(...memoryResult);
|
|
33068
33087
|
if (isSemanticSearch && oc.userId && oc.conversationId) {
|
|
33069
33088
|
try {
|
|
33070
33089
|
const inputForMemory = typeof resolvedInput === "string" ? resolvedInput : Array.isArray(resolvedInput) && resolvedInput[0]?.parts ? resolvedInput : convertModelMessagesToUIMessages(resolvedInput);
|
|
@@ -33080,6 +33099,51 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33080
33099
|
}
|
|
33081
33100
|
}
|
|
33082
33101
|
}
|
|
33102
|
+
const systemMessage = await this.getSystemMessage(resolvedInput, oc, options, runtimeToolkits);
|
|
33103
|
+
if (systemMessage) {
|
|
33104
|
+
const systemMessagesAsUI = (() => {
|
|
33105
|
+
if (typeof systemMessage === "string") {
|
|
33106
|
+
return [
|
|
33107
|
+
{
|
|
33108
|
+
id: randomUUID(),
|
|
33109
|
+
role: "system",
|
|
33110
|
+
parts: [
|
|
33111
|
+
{
|
|
33112
|
+
type: "text",
|
|
33113
|
+
text: systemMessage
|
|
33114
|
+
}
|
|
33115
|
+
]
|
|
33116
|
+
}
|
|
33117
|
+
];
|
|
33118
|
+
}
|
|
33119
|
+
if (Array.isArray(systemMessage)) {
|
|
33120
|
+
return convertModelMessagesToUIMessages(systemMessage);
|
|
33121
|
+
}
|
|
33122
|
+
return convertModelMessagesToUIMessages([systemMessage]);
|
|
33123
|
+
})();
|
|
33124
|
+
for (const systemUIMessage of systemMessagesAsUI) {
|
|
33125
|
+
messages.push(systemUIMessage);
|
|
33126
|
+
}
|
|
33127
|
+
const instructionText = systemMessagesAsUI.flatMap(
|
|
33128
|
+
(msg) => msg.parts.flatMap(
|
|
33129
|
+
(part) => part.type === "text" && typeof part.text === "string" ? [part.text] : []
|
|
33130
|
+
)
|
|
33131
|
+
).join("\n\n");
|
|
33132
|
+
if (instructionText) {
|
|
33133
|
+
oc.traceContext.setInstructions(instructionText);
|
|
33134
|
+
}
|
|
33135
|
+
}
|
|
33136
|
+
const middlewareRetryFeedback = this.consumeMiddlewareRetryFeedback(oc);
|
|
33137
|
+
if (middlewareRetryFeedback) {
|
|
33138
|
+
messages.push({
|
|
33139
|
+
id: randomUUID(),
|
|
33140
|
+
role: "system",
|
|
33141
|
+
parts: [{ type: "text", text: middlewareRetryFeedback }]
|
|
33142
|
+
});
|
|
33143
|
+
}
|
|
33144
|
+
if (memoryContextMessages.length > 0) {
|
|
33145
|
+
messages.push(...memoryContextMessages);
|
|
33146
|
+
}
|
|
33083
33147
|
if (typeof resolvedInput === "string") {
|
|
33084
33148
|
messages.push({
|
|
33085
33149
|
id: randomUUID(),
|
|
@@ -33147,6 +33211,9 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33147
33211
|
*/
|
|
33148
33212
|
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: legacy system message assembly
|
|
33149
33213
|
async getSystemMessage(input, oc, options, runtimeToolkits = []) {
|
|
33214
|
+
const resolvedMemory = this.resolveMemoryRuntimeOptions(options, oc);
|
|
33215
|
+
const workingMemoryConversationId = oc.conversationId ?? resolvedMemory.conversationId;
|
|
33216
|
+
const workingMemoryUserId = oc.userId ?? resolvedMemory.userId;
|
|
33150
33217
|
const promptHelper = VoltOpsClient.createPromptHelperWithFallback(
|
|
33151
33218
|
this.id,
|
|
33152
33219
|
this.name,
|
|
@@ -33204,13 +33271,14 @@ Metadata: ${(0, import_utils33.safeStringify)(metadata)}`;
|
|
|
33204
33271
|
retrieverContext = await this.getRetrieverContext(input, oc);
|
|
33205
33272
|
}
|
|
33206
33273
|
let workingMemoryContext = null;
|
|
33207
|
-
|
|
33274
|
+
const workingMemoryLookup = workingMemoryConversationId || workingMemoryUserId ? {
|
|
33275
|
+
...workingMemoryConversationId ? { conversationId: workingMemoryConversationId } : {},
|
|
33276
|
+
...workingMemoryUserId ? { userId: workingMemoryUserId } : {}
|
|
33277
|
+
} : void 0;
|
|
33278
|
+
if (this.hasWorkingMemorySupport() && workingMemoryLookup) {
|
|
33208
33279
|
const memory = this.memoryManager.getMemory();
|
|
33209
33280
|
if (memory) {
|
|
33210
|
-
const workingMemoryInstructions = await memory.getWorkingMemoryInstructions(
|
|
33211
|
-
conversationId: options.conversationId,
|
|
33212
|
-
userId: options.userId
|
|
33213
|
-
});
|
|
33281
|
+
const workingMemoryInstructions = await memory.getWorkingMemoryInstructions(workingMemoryLookup);
|
|
33214
33282
|
if (workingMemoryInstructions) {
|
|
33215
33283
|
workingMemoryContext = `
|
|
33216
33284
|
|
|
@@ -33218,10 +33286,7 @@ ${workingMemoryInstructions}`;
|
|
|
33218
33286
|
}
|
|
33219
33287
|
if (oc.traceContext) {
|
|
33220
33288
|
const rootSpan = oc.traceContext.getRootSpan();
|
|
33221
|
-
const workingMemoryContent = await memory.getWorkingMemory(
|
|
33222
|
-
conversationId: options.conversationId,
|
|
33223
|
-
userId: options.userId
|
|
33224
|
-
});
|
|
33289
|
+
const workingMemoryContent = await memory.getWorkingMemory(workingMemoryLookup);
|
|
33225
33290
|
if (workingMemoryContent) {
|
|
33226
33291
|
rootSpan.setAttribute("agent.workingMemory.content", workingMemoryContent);
|
|
33227
33292
|
rootSpan.setAttribute("agent.workingMemory.enabled", true);
|
|
@@ -33868,6 +33933,7 @@ ${retrieverContext}`;
|
|
|
33868
33933
|
* Prepare tools with execution context
|
|
33869
33934
|
*/
|
|
33870
33935
|
async prepareTools(adHocTools, oc, maxSteps, options) {
|
|
33936
|
+
const resolvedMemory = this.resolveMemoryRuntimeOptions(options, oc);
|
|
33871
33937
|
const hooks = this.getMergedHooks(options);
|
|
33872
33938
|
const createToolExecuteFunction = this.createToolExecutionFactory(oc, hooks);
|
|
33873
33939
|
const runtimeTools = [...adHocTools];
|
|
@@ -33877,12 +33943,12 @@ ${retrieverContext}`;
|
|
|
33877
33943
|
currentHistoryEntryId: oc.operationId,
|
|
33878
33944
|
operationContext: oc,
|
|
33879
33945
|
maxSteps,
|
|
33880
|
-
conversationId:
|
|
33881
|
-
userId:
|
|
33946
|
+
conversationId: resolvedMemory.conversationId,
|
|
33947
|
+
userId: resolvedMemory.userId
|
|
33882
33948
|
});
|
|
33883
33949
|
runtimeTools.push(delegateTool);
|
|
33884
33950
|
}
|
|
33885
|
-
const workingMemoryTools = this.createWorkingMemoryTools(options);
|
|
33951
|
+
const workingMemoryTools = this.createWorkingMemoryTools(options, oc);
|
|
33886
33952
|
if (workingMemoryTools.length > 0) {
|
|
33887
33953
|
runtimeTools.push(...workingMemoryTools);
|
|
33888
33954
|
}
|
|
@@ -35660,11 +35726,21 @@ ${retrieverContext}`;
|
|
|
35660
35726
|
execute: /* @__PURE__ */ __name(async (args, options2) => {
|
|
35661
35727
|
const prompt = args.prompt || args;
|
|
35662
35728
|
const oc = options2;
|
|
35729
|
+
const resolvedMemory = options2?.resolvedMemory;
|
|
35730
|
+
const memoryBehaviorOverrides = resolvedMemory ? {
|
|
35731
|
+
...resolvedMemory.contextLimit !== void 0 ? { contextLimit: resolvedMemory.contextLimit } : {},
|
|
35732
|
+
...resolvedMemory.semanticMemory !== void 0 ? { semanticMemory: resolvedMemory.semanticMemory } : {},
|
|
35733
|
+
...resolvedMemory.conversationPersistence !== void 0 ? { conversationPersistence: resolvedMemory.conversationPersistence } : {}
|
|
35734
|
+
} : void 0;
|
|
35735
|
+
const memory = resolvedMemory || options2?.conversationId || options2?.userId ? {
|
|
35736
|
+
conversationId: resolvedMemory?.conversationId ?? options2?.conversationId,
|
|
35737
|
+
userId: resolvedMemory?.userId ?? options2?.userId,
|
|
35738
|
+
...memoryBehaviorOverrides && Object.keys(memoryBehaviorOverrides).length > 0 ? { options: memoryBehaviorOverrides } : {}
|
|
35739
|
+
} : void 0;
|
|
35663
35740
|
const result = await this.generateText(prompt, {
|
|
35664
35741
|
// Pass through the operation context if available
|
|
35665
35742
|
parentOperationContext: oc,
|
|
35666
|
-
|
|
35667
|
-
userId: options2?.userId
|
|
35743
|
+
...memory ? { memory } : {}
|
|
35668
35744
|
});
|
|
35669
35745
|
return {
|
|
35670
35746
|
text: result.text,
|
|
@@ -35699,10 +35775,11 @@ ${retrieverContext}`;
|
|
|
35699
35775
|
/**
|
|
35700
35776
|
* Create working memory tools if configured
|
|
35701
35777
|
*/
|
|
35702
|
-
createWorkingMemoryTools(options) {
|
|
35778
|
+
createWorkingMemoryTools(options, operationContext) {
|
|
35703
35779
|
if (!this.hasWorkingMemorySupport()) {
|
|
35704
35780
|
return [];
|
|
35705
35781
|
}
|
|
35782
|
+
const resolvedMemory = this.resolveMemoryRuntimeOptions(options, operationContext);
|
|
35706
35783
|
const memoryManager = this.memoryManager;
|
|
35707
35784
|
const memory = memoryManager.getMemory();
|
|
35708
35785
|
if (!memory) {
|
|
@@ -35716,8 +35793,8 @@ ${retrieverContext}`;
|
|
|
35716
35793
|
parameters: import_zod7.z.object({}),
|
|
35717
35794
|
execute: /* @__PURE__ */ __name(async () => {
|
|
35718
35795
|
const content = await memory.getWorkingMemory({
|
|
35719
|
-
conversationId:
|
|
35720
|
-
userId:
|
|
35796
|
+
conversationId: resolvedMemory.conversationId,
|
|
35797
|
+
userId: resolvedMemory.userId
|
|
35721
35798
|
});
|
|
35722
35799
|
return content || "No working memory content found.";
|
|
35723
35800
|
}, "execute")
|
|
@@ -35738,8 +35815,8 @@ ${retrieverContext}`;
|
|
|
35738
35815
|
parameters: import_zod7.z.object({ ...baseParams, ...modeParam }),
|
|
35739
35816
|
execute: /* @__PURE__ */ __name(async ({ content, mode }, oc) => {
|
|
35740
35817
|
await memory.updateWorkingMemory({
|
|
35741
|
-
conversationId:
|
|
35742
|
-
userId:
|
|
35818
|
+
conversationId: resolvedMemory.conversationId,
|
|
35819
|
+
userId: resolvedMemory.userId,
|
|
35743
35820
|
content,
|
|
35744
35821
|
options: {
|
|
35745
35822
|
mode
|
|
@@ -35747,8 +35824,8 @@ ${retrieverContext}`;
|
|
|
35747
35824
|
});
|
|
35748
35825
|
if (oc?.traceContext) {
|
|
35749
35826
|
const finalContent = await memory.getWorkingMemory({
|
|
35750
|
-
conversationId:
|
|
35751
|
-
userId:
|
|
35827
|
+
conversationId: resolvedMemory.conversationId,
|
|
35828
|
+
userId: resolvedMemory.userId
|
|
35752
35829
|
});
|
|
35753
35830
|
const rootSpan = oc.traceContext.getRootSpan();
|
|
35754
35831
|
rootSpan.setAttribute("agent.workingMemory.finalContent", finalContent || "");
|
|
@@ -35765,8 +35842,8 @@ ${retrieverContext}`;
|
|
|
35765
35842
|
parameters: import_zod7.z.object({}),
|
|
35766
35843
|
execute: /* @__PURE__ */ __name(async (_, oc) => {
|
|
35767
35844
|
await memory.clearWorkingMemory({
|
|
35768
|
-
conversationId:
|
|
35769
|
-
userId:
|
|
35845
|
+
conversationId: resolvedMemory.conversationId,
|
|
35846
|
+
userId: resolvedMemory.userId
|
|
35770
35847
|
});
|
|
35771
35848
|
if (oc?.traceContext) {
|
|
35772
35849
|
const rootSpan = oc.traceContext.getRootSpan();
|