@voltagent/core 1.1.18 → 1.1.19
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.js +201 -217
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +201 -217
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6580,184 +6580,6 @@ var BackgroundQueue = class {
|
|
|
6580
6580
|
}
|
|
6581
6581
|
};
|
|
6582
6582
|
|
|
6583
|
-
// src/agent/message-normalizer.ts
|
|
6584
|
-
var WORKING_MEMORY_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
6585
|
-
"update_working_memory",
|
|
6586
|
-
"get_working_memory",
|
|
6587
|
-
"clear_working_memory"
|
|
6588
|
-
]);
|
|
6589
|
-
var isObject = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null, "isObject");
|
|
6590
|
-
var safeClone = /* @__PURE__ */ __name((value) => {
|
|
6591
|
-
if (!isObject(value) && !Array.isArray(value)) {
|
|
6592
|
-
return value;
|
|
6593
|
-
}
|
|
6594
|
-
const structuredCloneImpl = globalThis.structuredClone;
|
|
6595
|
-
if (typeof structuredCloneImpl === "function") {
|
|
6596
|
-
return structuredCloneImpl(value);
|
|
6597
|
-
}
|
|
6598
|
-
try {
|
|
6599
|
-
return JSON.parse(JSON.stringify(value));
|
|
6600
|
-
} catch (_error) {
|
|
6601
|
-
if (Array.isArray(value)) {
|
|
6602
|
-
return value.slice();
|
|
6603
|
-
}
|
|
6604
|
-
return { ...value };
|
|
6605
|
-
}
|
|
6606
|
-
}, "safeClone");
|
|
6607
|
-
var normalizeText = /* @__PURE__ */ __name((part) => {
|
|
6608
|
-
const text = typeof part.text === "string" ? part.text : "";
|
|
6609
|
-
if (!text.trim()) {
|
|
6610
|
-
return null;
|
|
6611
|
-
}
|
|
6612
|
-
const normalized = {
|
|
6613
|
-
type: "text",
|
|
6614
|
-
text
|
|
6615
|
-
};
|
|
6616
|
-
if (isObject(part.providerMetadata)) {
|
|
6617
|
-
normalized.providerMetadata = safeClone(part.providerMetadata);
|
|
6618
|
-
}
|
|
6619
|
-
return normalized;
|
|
6620
|
-
}, "normalizeText");
|
|
6621
|
-
var normalizeReasoning = /* @__PURE__ */ __name((part) => {
|
|
6622
|
-
const text = typeof part.text === "string" ? part.text : "";
|
|
6623
|
-
if (!text.trim()) {
|
|
6624
|
-
return null;
|
|
6625
|
-
}
|
|
6626
|
-
const normalized = {
|
|
6627
|
-
type: "reasoning",
|
|
6628
|
-
text
|
|
6629
|
-
};
|
|
6630
|
-
if (part.reasoningId) {
|
|
6631
|
-
normalized.reasoningId = part.reasoningId;
|
|
6632
|
-
}
|
|
6633
|
-
if (part.reasoningConfidence !== void 0) {
|
|
6634
|
-
normalized.reasoningConfidence = part.reasoningConfidence;
|
|
6635
|
-
}
|
|
6636
|
-
if (isObject(part.providerMetadata)) {
|
|
6637
|
-
normalized.providerMetadata = safeClone(part.providerMetadata);
|
|
6638
|
-
}
|
|
6639
|
-
return normalized;
|
|
6640
|
-
}, "normalizeReasoning");
|
|
6641
|
-
var toolNameFromType = /* @__PURE__ */ __name((type) => {
|
|
6642
|
-
if (typeof type !== "string") return void 0;
|
|
6643
|
-
if (!type.startsWith("tool-")) return void 0;
|
|
6644
|
-
return type.slice("tool-".length);
|
|
6645
|
-
}, "toolNameFromType");
|
|
6646
|
-
var isWorkingMemoryTool = /* @__PURE__ */ __name((part) => {
|
|
6647
|
-
const toolName = toolNameFromType(part.type);
|
|
6648
|
-
if (!toolName) return false;
|
|
6649
|
-
return WORKING_MEMORY_TOOL_NAMES.has(toolName);
|
|
6650
|
-
}, "isWorkingMemoryTool");
|
|
6651
|
-
var normalizeToolPart = /* @__PURE__ */ __name((part) => {
|
|
6652
|
-
if (isWorkingMemoryTool(part)) {
|
|
6653
|
-
return null;
|
|
6654
|
-
}
|
|
6655
|
-
const toolName = toolNameFromType(part.type);
|
|
6656
|
-
if (!toolName) {
|
|
6657
|
-
return safeClone(part);
|
|
6658
|
-
}
|
|
6659
|
-
const normalized = {
|
|
6660
|
-
type: `tool-${toolName}`
|
|
6661
|
-
};
|
|
6662
|
-
if (part.toolCallId) normalized.toolCallId = part.toolCallId;
|
|
6663
|
-
if (part.state) normalized.state = part.state;
|
|
6664
|
-
if (part.input !== void 0) normalized.input = safeClone(part.input);
|
|
6665
|
-
if (part.output !== void 0) normalized.output = safeClone(part.output);
|
|
6666
|
-
if (part.providerExecuted !== void 0) normalized.providerExecuted = part.providerExecuted;
|
|
6667
|
-
if (part.isError !== void 0) normalized.isError = part.isError;
|
|
6668
|
-
if (part.errorText !== void 0) normalized.errorText = part.errorText;
|
|
6669
|
-
return normalized;
|
|
6670
|
-
}, "normalizeToolPart");
|
|
6671
|
-
var normalizeGenericPart = /* @__PURE__ */ __name((part) => {
|
|
6672
|
-
switch (part.type) {
|
|
6673
|
-
case "text":
|
|
6674
|
-
return normalizeText(part);
|
|
6675
|
-
case "reasoning":
|
|
6676
|
-
return normalizeReasoning(part);
|
|
6677
|
-
case "step-start":
|
|
6678
|
-
return { type: "step-start" };
|
|
6679
|
-
case "file": {
|
|
6680
|
-
if (!isObject(part) || !part.url) {
|
|
6681
|
-
return null;
|
|
6682
|
-
}
|
|
6683
|
-
const cloned = safeClone(part);
|
|
6684
|
-
if (cloned.providerMetadata) {
|
|
6685
|
-
cloned.providerMetadata = safeClone(cloned.providerMetadata);
|
|
6686
|
-
}
|
|
6687
|
-
return cloned;
|
|
6688
|
-
}
|
|
6689
|
-
default:
|
|
6690
|
-
if (typeof part.type === "string" && part.type.startsWith("tool-")) {
|
|
6691
|
-
return normalizeToolPart(part);
|
|
6692
|
-
}
|
|
6693
|
-
return safeClone(part);
|
|
6694
|
-
}
|
|
6695
|
-
}, "normalizeGenericPart");
|
|
6696
|
-
var pruneEmptyToolRuns = /* @__PURE__ */ __name((parts) => {
|
|
6697
|
-
const cleaned = [];
|
|
6698
|
-
for (const part of parts) {
|
|
6699
|
-
if (typeof part.type === "string" && part.type.startsWith("tool-")) {
|
|
6700
|
-
const hasPendingState = part.state === "input-available";
|
|
6701
|
-
const hasResult = part.state === "output-available" || part.output !== void 0;
|
|
6702
|
-
if (!hasPendingState && !hasResult && part.input == null) {
|
|
6703
|
-
continue;
|
|
6704
|
-
}
|
|
6705
|
-
}
|
|
6706
|
-
cleaned.push(part);
|
|
6707
|
-
}
|
|
6708
|
-
return cleaned;
|
|
6709
|
-
}, "pruneEmptyToolRuns");
|
|
6710
|
-
var collapseRedundantStepStarts = /* @__PURE__ */ __name((parts) => {
|
|
6711
|
-
const result = [];
|
|
6712
|
-
for (const part of parts) {
|
|
6713
|
-
if (part.type === "step-start") {
|
|
6714
|
-
const prev = result.at(-1);
|
|
6715
|
-
if (!prev || prev.type === "step-start") {
|
|
6716
|
-
continue;
|
|
6717
|
-
}
|
|
6718
|
-
}
|
|
6719
|
-
result.push(part);
|
|
6720
|
-
}
|
|
6721
|
-
return result;
|
|
6722
|
-
}, "collapseRedundantStepStarts");
|
|
6723
|
-
var sanitizeMessage = /* @__PURE__ */ __name((message) => {
|
|
6724
|
-
const sanitizedParts = [];
|
|
6725
|
-
for (const part of message.parts) {
|
|
6726
|
-
const normalized = normalizeGenericPart(part);
|
|
6727
|
-
if (!normalized) {
|
|
6728
|
-
continue;
|
|
6729
|
-
}
|
|
6730
|
-
sanitizedParts.push(normalized);
|
|
6731
|
-
}
|
|
6732
|
-
const pruned = collapseRedundantStepStarts(pruneEmptyToolRuns(sanitizedParts));
|
|
6733
|
-
const effectiveParts = pruned.filter((part) => {
|
|
6734
|
-
if (part.type === "text") {
|
|
6735
|
-
return typeof part.text === "string" && part.text.trim().length > 0;
|
|
6736
|
-
}
|
|
6737
|
-
if (part.type === "reasoning") {
|
|
6738
|
-
return typeof part.text === "string" && part.text.trim().length > 0;
|
|
6739
|
-
}
|
|
6740
|
-
if (typeof part.type === "string" && part.type.startsWith("tool-")) {
|
|
6741
|
-
return Boolean(part.toolCallId);
|
|
6742
|
-
}
|
|
6743
|
-
if (part.type === "file") {
|
|
6744
|
-
return Boolean(part.url);
|
|
6745
|
-
}
|
|
6746
|
-
return true;
|
|
6747
|
-
});
|
|
6748
|
-
if (!effectiveParts.length) {
|
|
6749
|
-
return null;
|
|
6750
|
-
}
|
|
6751
|
-
const clonedMetadata = isObject(message.metadata) ? safeClone(message.metadata) : message.metadata;
|
|
6752
|
-
return {
|
|
6753
|
-
...message,
|
|
6754
|
-
parts: effectiveParts,
|
|
6755
|
-
...clonedMetadata ? { metadata: clonedMetadata } : {}
|
|
6756
|
-
};
|
|
6757
|
-
}, "sanitizeMessage");
|
|
6758
|
-
var sanitizeMessagesForPersistence = /* @__PURE__ */ __name((messages) => messages.map((message) => sanitizeMessage(message)).filter((message) => Boolean(message)), "sanitizeMessagesForPersistence");
|
|
6759
|
-
var sanitizeMessageForPersistence = /* @__PURE__ */ __name((message) => sanitizeMessage(message), "sanitizeMessageForPersistence");
|
|
6760
|
-
|
|
6761
6583
|
// src/memory/manager/memory-manager.ts
|
|
6762
6584
|
var MemoryManager = class {
|
|
6763
6585
|
static {
|
|
@@ -6820,19 +6642,10 @@ var MemoryManager = class {
|
|
|
6820
6642
|
const memoryLogger = context5.logger.child({
|
|
6821
6643
|
operation: "write"
|
|
6822
6644
|
});
|
|
6823
|
-
const sanitizedMessage = sanitizeMessageForPersistence(message);
|
|
6824
|
-
if (!sanitizedMessage) {
|
|
6825
|
-
memoryLogger.debug("[Memory] Skipped persisting empty message after sanitization", {
|
|
6826
|
-
event: LogEvents.MEMORY_OPERATION_COMPLETED,
|
|
6827
|
-
operation: "write",
|
|
6828
|
-
reason: "sanitized-empty"
|
|
6829
|
-
});
|
|
6830
|
-
return;
|
|
6831
|
-
}
|
|
6832
6645
|
const trace8 = context5.traceContext;
|
|
6833
|
-
const spanInput = { userId, conversationId, message
|
|
6646
|
+
const spanInput = { userId, conversationId, message };
|
|
6834
6647
|
const writeSpan = trace8.createChildSpan("memory.write", "memory", {
|
|
6835
|
-
label:
|
|
6648
|
+
label: message.role === "user" ? "Persist User Message" : "Persist Assistant Message",
|
|
6836
6649
|
attributes: {
|
|
6837
6650
|
"memory.operation": "write",
|
|
6838
6651
|
input: (0, import_internal4.safeStringify)(spanInput)
|
|
@@ -6851,14 +6664,9 @@ var MemoryManager = class {
|
|
|
6851
6664
|
metadata: {}
|
|
6852
6665
|
});
|
|
6853
6666
|
}
|
|
6854
|
-
await this.conversationMemory?.saveMessageWithContext(
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
conversationId,
|
|
6858
|
-
{
|
|
6859
|
-
logger: memoryLogger
|
|
6860
|
-
}
|
|
6861
|
-
);
|
|
6667
|
+
await this.conversationMemory?.saveMessageWithContext(message, userId, conversationId, {
|
|
6668
|
+
logger: memoryLogger
|
|
6669
|
+
});
|
|
6862
6670
|
}
|
|
6863
6671
|
});
|
|
6864
6672
|
trace8.endChildSpan(writeSpan, "completed", {
|
|
@@ -9334,24 +9142,14 @@ var MemoryPersistQueue = class {
|
|
|
9334
9142
|
this.logger?.debug?.("[MemoryPersistQueue] nothing-to-persist", payload2);
|
|
9335
9143
|
return;
|
|
9336
9144
|
}
|
|
9337
|
-
const sanitized = sanitizeMessagesForPersistence(pending);
|
|
9338
|
-
if (sanitized.length === 0) {
|
|
9339
|
-
this.logger?.debug?.("[MemoryPersistQueue] sanitized-all", {
|
|
9340
|
-
conversationId: oc.conversationId,
|
|
9341
|
-
userId: oc.userId,
|
|
9342
|
-
dropped: pending.length
|
|
9343
|
-
});
|
|
9344
|
-
return;
|
|
9345
|
-
}
|
|
9346
9145
|
const payload = {
|
|
9347
9146
|
conversationId: oc.conversationId,
|
|
9348
9147
|
userId: oc.userId,
|
|
9349
|
-
count:
|
|
9350
|
-
|
|
9351
|
-
ids: sanitized.map((msg) => msg.id)
|
|
9148
|
+
count: pending.length,
|
|
9149
|
+
ids: pending.map((msg) => msg.id)
|
|
9352
9150
|
};
|
|
9353
9151
|
this.logger?.debug?.("[MemoryPersistQueue] persisting", payload);
|
|
9354
|
-
for (const message of
|
|
9152
|
+
for (const message of pending) {
|
|
9355
9153
|
try {
|
|
9356
9154
|
await this.memoryManager.saveMessage(oc, message, oc.userId, oc.conversationId);
|
|
9357
9155
|
} catch (error) {
|
|
@@ -9393,6 +9191,172 @@ var MemoryPersistQueue = class {
|
|
|
9393
9191
|
}
|
|
9394
9192
|
};
|
|
9395
9193
|
|
|
9194
|
+
// src/agent/message-normalizer.ts
|
|
9195
|
+
var WORKING_MEMORY_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
9196
|
+
"update_working_memory",
|
|
9197
|
+
"get_working_memory",
|
|
9198
|
+
"clear_working_memory"
|
|
9199
|
+
]);
|
|
9200
|
+
var isObject = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null, "isObject");
|
|
9201
|
+
var safeClone = /* @__PURE__ */ __name((value) => {
|
|
9202
|
+
if (!isObject(value) && !Array.isArray(value)) {
|
|
9203
|
+
return value;
|
|
9204
|
+
}
|
|
9205
|
+
const structuredCloneImpl = globalThis.structuredClone;
|
|
9206
|
+
if (typeof structuredCloneImpl === "function") {
|
|
9207
|
+
return structuredCloneImpl(value);
|
|
9208
|
+
}
|
|
9209
|
+
try {
|
|
9210
|
+
return JSON.parse(JSON.stringify(value));
|
|
9211
|
+
} catch (_error) {
|
|
9212
|
+
if (Array.isArray(value)) {
|
|
9213
|
+
return value.slice();
|
|
9214
|
+
}
|
|
9215
|
+
return { ...value };
|
|
9216
|
+
}
|
|
9217
|
+
}, "safeClone");
|
|
9218
|
+
var normalizeText = /* @__PURE__ */ __name((part) => {
|
|
9219
|
+
const text = typeof part.text === "string" ? part.text : "";
|
|
9220
|
+
if (!text.trim()) {
|
|
9221
|
+
return null;
|
|
9222
|
+
}
|
|
9223
|
+
return {
|
|
9224
|
+
type: "text",
|
|
9225
|
+
text
|
|
9226
|
+
};
|
|
9227
|
+
}, "normalizeText");
|
|
9228
|
+
var normalizeReasoning = /* @__PURE__ */ __name((part) => {
|
|
9229
|
+
const text = typeof part.text === "string" ? part.text : "";
|
|
9230
|
+
if (!text.trim()) {
|
|
9231
|
+
return null;
|
|
9232
|
+
}
|
|
9233
|
+
const normalized = {
|
|
9234
|
+
type: "reasoning",
|
|
9235
|
+
text
|
|
9236
|
+
};
|
|
9237
|
+
if (part.reasoningId) {
|
|
9238
|
+
normalized.reasoningId = part.reasoningId;
|
|
9239
|
+
}
|
|
9240
|
+
if (part.reasoningConfidence !== void 0) {
|
|
9241
|
+
normalized.reasoningConfidence = part.reasoningConfidence;
|
|
9242
|
+
}
|
|
9243
|
+
return normalized;
|
|
9244
|
+
}, "normalizeReasoning");
|
|
9245
|
+
var toolNameFromType = /* @__PURE__ */ __name((type) => {
|
|
9246
|
+
if (typeof type !== "string") return void 0;
|
|
9247
|
+
if (!type.startsWith("tool-")) return void 0;
|
|
9248
|
+
return type.slice("tool-".length);
|
|
9249
|
+
}, "toolNameFromType");
|
|
9250
|
+
var isWorkingMemoryTool = /* @__PURE__ */ __name((part) => {
|
|
9251
|
+
const toolName = toolNameFromType(part.type);
|
|
9252
|
+
if (!toolName) return false;
|
|
9253
|
+
return WORKING_MEMORY_TOOL_NAMES.has(toolName);
|
|
9254
|
+
}, "isWorkingMemoryTool");
|
|
9255
|
+
var normalizeToolPart = /* @__PURE__ */ __name((part) => {
|
|
9256
|
+
if (isWorkingMemoryTool(part)) {
|
|
9257
|
+
return null;
|
|
9258
|
+
}
|
|
9259
|
+
const toolName = toolNameFromType(part.type);
|
|
9260
|
+
if (!toolName) {
|
|
9261
|
+
return safeClone(part);
|
|
9262
|
+
}
|
|
9263
|
+
const normalized = {
|
|
9264
|
+
type: `tool-${toolName}`
|
|
9265
|
+
};
|
|
9266
|
+
if (part.toolCallId) normalized.toolCallId = part.toolCallId;
|
|
9267
|
+
if (part.state) normalized.state = part.state;
|
|
9268
|
+
if (part.input !== void 0) normalized.input = safeClone(part.input);
|
|
9269
|
+
if (part.output !== void 0) normalized.output = safeClone(part.output);
|
|
9270
|
+
if (part.providerExecuted !== void 0) normalized.providerExecuted = part.providerExecuted;
|
|
9271
|
+
if (part.isError !== void 0) normalized.isError = part.isError;
|
|
9272
|
+
if (part.errorText !== void 0) normalized.errorText = part.errorText;
|
|
9273
|
+
return normalized;
|
|
9274
|
+
}, "normalizeToolPart");
|
|
9275
|
+
var sanitizeMessagesForModel = /* @__PURE__ */ __name((messages) => messages.map((message) => sanitizeMessageForModel(message)).filter((message) => Boolean(message)), "sanitizeMessagesForModel");
|
|
9276
|
+
var sanitizeMessageForModel = /* @__PURE__ */ __name((message) => {
|
|
9277
|
+
const sanitizedParts = [];
|
|
9278
|
+
for (const part of message.parts) {
|
|
9279
|
+
const normalized = normalizeGenericPart(part);
|
|
9280
|
+
if (!normalized) {
|
|
9281
|
+
continue;
|
|
9282
|
+
}
|
|
9283
|
+
sanitizedParts.push(normalized);
|
|
9284
|
+
}
|
|
9285
|
+
const pruned = collapseRedundantStepStarts(pruneEmptyToolRuns(sanitizedParts));
|
|
9286
|
+
const effectiveParts = pruned.filter((part) => {
|
|
9287
|
+
if (part.type === "text") {
|
|
9288
|
+
return typeof part.text === "string" && part.text.trim().length > 0;
|
|
9289
|
+
}
|
|
9290
|
+
if (part.type === "reasoning") {
|
|
9291
|
+
return typeof part.text === "string" && part.text.trim().length > 0;
|
|
9292
|
+
}
|
|
9293
|
+
if (typeof part.type === "string" && part.type.startsWith("tool-")) {
|
|
9294
|
+
return Boolean(part.toolCallId);
|
|
9295
|
+
}
|
|
9296
|
+
if (part.type === "file") {
|
|
9297
|
+
return Boolean(part.url);
|
|
9298
|
+
}
|
|
9299
|
+
return true;
|
|
9300
|
+
});
|
|
9301
|
+
if (!effectiveParts.length) {
|
|
9302
|
+
return null;
|
|
9303
|
+
}
|
|
9304
|
+
return {
|
|
9305
|
+
...message,
|
|
9306
|
+
parts: effectiveParts,
|
|
9307
|
+
...message.metadata ? { metadata: safeClone(message.metadata) } : {}
|
|
9308
|
+
};
|
|
9309
|
+
}, "sanitizeMessageForModel");
|
|
9310
|
+
var normalizeGenericPart = /* @__PURE__ */ __name((part) => {
|
|
9311
|
+
switch (part.type) {
|
|
9312
|
+
case "text":
|
|
9313
|
+
return normalizeText(part);
|
|
9314
|
+
case "reasoning":
|
|
9315
|
+
return normalizeReasoning(part);
|
|
9316
|
+
case "step-start":
|
|
9317
|
+
return { type: "step-start" };
|
|
9318
|
+
case "file": {
|
|
9319
|
+
if (!isObject(part) || !part.url) {
|
|
9320
|
+
return null;
|
|
9321
|
+
}
|
|
9322
|
+
const cloned = safeClone(part);
|
|
9323
|
+
return cloned;
|
|
9324
|
+
}
|
|
9325
|
+
default:
|
|
9326
|
+
if (typeof part.type === "string" && part.type.startsWith("tool-")) {
|
|
9327
|
+
return normalizeToolPart(part);
|
|
9328
|
+
}
|
|
9329
|
+
return safeClone(part);
|
|
9330
|
+
}
|
|
9331
|
+
}, "normalizeGenericPart");
|
|
9332
|
+
var pruneEmptyToolRuns = /* @__PURE__ */ __name((parts) => {
|
|
9333
|
+
const cleaned = [];
|
|
9334
|
+
for (const part of parts) {
|
|
9335
|
+
if (typeof part.type === "string" && part.type.startsWith("tool-")) {
|
|
9336
|
+
const hasPendingState = part.state === "input-available";
|
|
9337
|
+
const hasResult = part.state === "output-available" || part.output !== void 0;
|
|
9338
|
+
if (!hasPendingState && !hasResult && part.input == null) {
|
|
9339
|
+
continue;
|
|
9340
|
+
}
|
|
9341
|
+
}
|
|
9342
|
+
cleaned.push(part);
|
|
9343
|
+
}
|
|
9344
|
+
return cleaned;
|
|
9345
|
+
}, "pruneEmptyToolRuns");
|
|
9346
|
+
var collapseRedundantStepStarts = /* @__PURE__ */ __name((parts) => {
|
|
9347
|
+
const result = [];
|
|
9348
|
+
for (const part of parts) {
|
|
9349
|
+
if (part.type === "step-start") {
|
|
9350
|
+
const prev = result.at(-1);
|
|
9351
|
+
if (!prev || prev.type === "step-start") {
|
|
9352
|
+
continue;
|
|
9353
|
+
}
|
|
9354
|
+
}
|
|
9355
|
+
result.push(part);
|
|
9356
|
+
}
|
|
9357
|
+
return result;
|
|
9358
|
+
}, "collapseRedundantStepStarts");
|
|
9359
|
+
|
|
9396
9360
|
// src/agent/subagent/index.ts
|
|
9397
9361
|
var import_utils11 = require("@voltagent/internal/utils");
|
|
9398
9362
|
var import_zod2 = require("zod");
|
|
@@ -10146,7 +10110,11 @@ var Agent = class {
|
|
|
10146
10110
|
return await oc.traceContext.withSpan(rootSpan, async () => {
|
|
10147
10111
|
const buffer = this.getConversationBuffer(oc);
|
|
10148
10112
|
const persistQueue = this.getMemoryPersistQueue(oc);
|
|
10149
|
-
const { messages, model, tools, maxSteps } = await this.prepareExecution(
|
|
10113
|
+
const { messages, uiMessages, model, tools, maxSteps } = await this.prepareExecution(
|
|
10114
|
+
input,
|
|
10115
|
+
oc,
|
|
10116
|
+
options
|
|
10117
|
+
);
|
|
10150
10118
|
const modelName = this.getModelName();
|
|
10151
10119
|
const contextLimit = options?.contextLimit;
|
|
10152
10120
|
addModelAttributesToSpan(
|
|
@@ -10161,6 +10129,7 @@ var Agent = class {
|
|
|
10161
10129
|
rootSpan.setAttribute("agent.context", (0, import_utils12.safeStringify)(contextMap));
|
|
10162
10130
|
}
|
|
10163
10131
|
rootSpan.setAttribute("agent.messages", (0, import_utils12.safeStringify)(messages));
|
|
10132
|
+
rootSpan.setAttribute("agent.messages.ui", (0, import_utils12.safeStringify)(uiMessages));
|
|
10164
10133
|
const agentState = this.getFullState();
|
|
10165
10134
|
rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils12.safeStringify)(agentState));
|
|
10166
10135
|
methodLogger.debug(
|
|
@@ -10285,7 +10254,11 @@ var Agent = class {
|
|
|
10285
10254
|
const methodLogger = oc.logger;
|
|
10286
10255
|
const buffer = this.getConversationBuffer(oc);
|
|
10287
10256
|
const persistQueue = this.getMemoryPersistQueue(oc);
|
|
10288
|
-
const { messages, model, tools, maxSteps } = await this.prepareExecution(
|
|
10257
|
+
const { messages, uiMessages, model, tools, maxSteps } = await this.prepareExecution(
|
|
10258
|
+
input,
|
|
10259
|
+
oc,
|
|
10260
|
+
options
|
|
10261
|
+
);
|
|
10289
10262
|
const modelName = this.getModelName();
|
|
10290
10263
|
const contextLimit = options?.contextLimit;
|
|
10291
10264
|
if (oc.traceContext) {
|
|
@@ -10302,6 +10275,7 @@ var Agent = class {
|
|
|
10302
10275
|
rootSpan2.setAttribute("agent.context", (0, import_utils12.safeStringify)(contextMap));
|
|
10303
10276
|
}
|
|
10304
10277
|
rootSpan2.setAttribute("agent.messages", (0, import_utils12.safeStringify)(messages));
|
|
10278
|
+
rootSpan2.setAttribute("agent.messages.ui", (0, import_utils12.safeStringify)(uiMessages));
|
|
10305
10279
|
const agentState = this.getFullState();
|
|
10306
10280
|
rootSpan2.setAttribute("agent.stateSnapshot", (0, import_utils12.safeStringify)(agentState));
|
|
10307
10281
|
}
|
|
@@ -10500,7 +10474,7 @@ var Agent = class {
|
|
|
10500
10474
|
const methodLogger = oc.logger;
|
|
10501
10475
|
const rootSpan = oc.traceContext.getRootSpan();
|
|
10502
10476
|
return await oc.traceContext.withSpan(rootSpan, async () => {
|
|
10503
|
-
const { messages, model } = await this.prepareExecution(input, oc, options);
|
|
10477
|
+
const { messages, uiMessages, model } = await this.prepareExecution(input, oc, options);
|
|
10504
10478
|
const modelName = this.getModelName();
|
|
10505
10479
|
const schemaName = schema.description || "unknown";
|
|
10506
10480
|
addModelAttributesToSpan(
|
|
@@ -10515,6 +10489,7 @@ var Agent = class {
|
|
|
10515
10489
|
rootSpan.setAttribute("agent.context", (0, import_utils12.safeStringify)(contextMap));
|
|
10516
10490
|
}
|
|
10517
10491
|
rootSpan.setAttribute("agent.messages", (0, import_utils12.safeStringify)(messages));
|
|
10492
|
+
rootSpan.setAttribute("agent.messages.ui", (0, import_utils12.safeStringify)(uiMessages));
|
|
10518
10493
|
const agentState = this.getFullState();
|
|
10519
10494
|
rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils12.safeStringify)(agentState));
|
|
10520
10495
|
methodLogger.debug(
|
|
@@ -10636,7 +10611,7 @@ var Agent = class {
|
|
|
10636
10611
|
const rootSpan = oc.traceContext.getRootSpan();
|
|
10637
10612
|
return await oc.traceContext.withSpan(rootSpan, async () => {
|
|
10638
10613
|
const methodLogger = oc.logger;
|
|
10639
|
-
const { messages, model } = await this.prepareExecution(input, oc, options);
|
|
10614
|
+
const { messages, uiMessages, model } = await this.prepareExecution(input, oc, options);
|
|
10640
10615
|
const modelName = this.getModelName();
|
|
10641
10616
|
const schemaName = schema.description || "unknown";
|
|
10642
10617
|
addModelAttributesToSpan(
|
|
@@ -10651,6 +10626,7 @@ var Agent = class {
|
|
|
10651
10626
|
rootSpan.setAttribute("agent.context", (0, import_utils12.safeStringify)(contextMap));
|
|
10652
10627
|
}
|
|
10653
10628
|
rootSpan.setAttribute("agent.messages", (0, import_utils12.safeStringify)(messages));
|
|
10629
|
+
rootSpan.setAttribute("agent.messages.ui", (0, import_utils12.safeStringify)(uiMessages));
|
|
10654
10630
|
const agentState = this.getFullState();
|
|
10655
10631
|
rootSpan.setAttribute("agent.stateSnapshot", (0, import_utils12.safeStringify)(agentState));
|
|
10656
10632
|
methodLogger.debug(
|
|
@@ -10811,13 +10787,20 @@ var Agent = class {
|
|
|
10811
10787
|
const agentToolList = await this.resolveValue(this.tools, oc);
|
|
10812
10788
|
const buffer = this.getConversationBuffer(oc);
|
|
10813
10789
|
const uiMessages = await this.prepareMessages(input, oc, options, buffer);
|
|
10814
|
-
const
|
|
10790
|
+
const sanitizedUIMessages = sanitizeMessagesForModel(uiMessages);
|
|
10791
|
+
const messages = (0, import_ai.convertToModelMessages)(sanitizedUIMessages);
|
|
10815
10792
|
const maxSteps = options?.maxSteps ?? this.calculateMaxSteps();
|
|
10816
10793
|
const agentToolsArray = Array.isArray(agentToolList) ? agentToolList : [];
|
|
10817
10794
|
const optionToolsArray = options?.tools || [];
|
|
10818
10795
|
const mergedTools = [...agentToolsArray, ...optionToolsArray];
|
|
10819
10796
|
const tools = await this.prepareTools(mergedTools, oc, maxSteps, options);
|
|
10820
|
-
return {
|
|
10797
|
+
return {
|
|
10798
|
+
messages,
|
|
10799
|
+
uiMessages: sanitizedUIMessages,
|
|
10800
|
+
model,
|
|
10801
|
+
tools,
|
|
10802
|
+
maxSteps
|
|
10803
|
+
};
|
|
10821
10804
|
}
|
|
10822
10805
|
/**
|
|
10823
10806
|
* Create execution context
|
|
@@ -11122,10 +11105,11 @@ var Agent = class {
|
|
|
11122
11105
|
buffer.ingestUIMessages(result.messages, true);
|
|
11123
11106
|
return result.messages;
|
|
11124
11107
|
});
|
|
11108
|
+
const retrievedMessagesCount = Array.isArray(memoryResult) ? memoryResult.length : 0;
|
|
11125
11109
|
traceContext.endChildSpan(memoryReadSpan, "completed", {
|
|
11126
11110
|
output: memoryResult,
|
|
11127
11111
|
attributes: {
|
|
11128
|
-
"memory.message_count":
|
|
11112
|
+
"memory.message_count": retrievedMessagesCount
|
|
11129
11113
|
}
|
|
11130
11114
|
});
|
|
11131
11115
|
if (isSemanticSearch && !oc.conversationId) {
|