@voltagent/core 1.1.16 → 1.1.17

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 CHANGED
@@ -3475,6 +3475,8 @@ declare class Agent {
3475
3475
  * Create step handler for memory and hooks
3476
3476
  */
3477
3477
  private createStepHandler;
3478
+ private buildSyntheticToolMessages;
3479
+ private collectToolResultIds;
3478
3480
  /**
3479
3481
  * Add step to history - now only tracks in conversation steps
3480
3482
  */
package/dist/index.d.ts CHANGED
@@ -3475,6 +3475,8 @@ declare class Agent {
3475
3475
  * Create step handler for memory and hooks
3476
3476
  */
3477
3477
  private createStepHandler;
3478
+ private buildSyntheticToolMessages;
3479
+ private collectToolResultIds;
3478
3480
  /**
3479
3481
  * Add step to history - now only tracks in conversation steps
3480
3482
  */
package/dist/index.js CHANGED
@@ -11331,10 +11331,76 @@ ${toolkit.instructions}`;
11331
11331
  if (responseMessages && responseMessages.length > 0) {
11332
11332
  buffer.addModelMessages(responseMessages, "response");
11333
11333
  }
11334
+ const syntheticToolMessages = this.buildSyntheticToolMessages(event, responseMessages);
11335
+ if (syntheticToolMessages.length > 0) {
11336
+ buffer.addModelMessages(syntheticToolMessages, "response");
11337
+ }
11334
11338
  const hooks = this.getMergedHooks(options);
11335
11339
  await hooks.onStepFinish?.({ agent: this, step: event, context: oc });
11336
11340
  };
11337
11341
  }
11342
+ buildSyntheticToolMessages(step, responseMessages) {
11343
+ if (!Array.isArray(step.content) || step.content.length === 0) {
11344
+ return [];
11345
+ }
11346
+ const existingToolResultIds = this.collectToolResultIds(responseMessages);
11347
+ const syntheticMessages = [];
11348
+ for (const part of step.content) {
11349
+ if (!part || typeof part !== "object") {
11350
+ continue;
11351
+ }
11352
+ if (part.type !== "tool-result") {
11353
+ continue;
11354
+ }
11355
+ const toolCallId = typeof part.toolCallId === "string" ? part.toolCallId : void 0;
11356
+ if (!toolCallId || existingToolResultIds.has(toolCallId)) {
11357
+ continue;
11358
+ }
11359
+ const role = part.providerExecuted ? "assistant" : "tool";
11360
+ const contentPart = {
11361
+ type: "tool-result",
11362
+ toolCallId,
11363
+ toolName: part.toolName,
11364
+ output: part.output
11365
+ };
11366
+ if ("input" in part) {
11367
+ contentPart.input = part.input;
11368
+ }
11369
+ if ("providerExecuted" in part) {
11370
+ contentPart.providerExecuted = part.providerExecuted;
11371
+ }
11372
+ if ("dynamic" in part) {
11373
+ contentPart.dynamic = part.dynamic;
11374
+ }
11375
+ if ("preliminary" in part) {
11376
+ contentPart.preliminary = part.preliminary;
11377
+ }
11378
+ syntheticMessages.push({
11379
+ role,
11380
+ content: [contentPart]
11381
+ });
11382
+ existingToolResultIds.add(toolCallId);
11383
+ }
11384
+ return syntheticMessages;
11385
+ }
11386
+ collectToolResultIds(messages) {
11387
+ const ids = /* @__PURE__ */ new Set();
11388
+ if (!messages) {
11389
+ return ids;
11390
+ }
11391
+ for (const message of messages) {
11392
+ if (!message || typeof message !== "object") {
11393
+ continue;
11394
+ }
11395
+ const content = Array.isArray(message.content) ? message.content : [];
11396
+ for (const part of content) {
11397
+ if (part && typeof part === "object" && part.type === "tool-result" && typeof part.toolCallId === "string") {
11398
+ ids.add(part.toolCallId);
11399
+ }
11400
+ }
11401
+ }
11402
+ return ids;
11403
+ }
11338
11404
  /**
11339
11405
  * Add step to history - now only tracks in conversation steps
11340
11406
  */