@mastra/agent-builder 1.0.0-beta.2 → 1.0.0-beta.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @mastra/agent-builder
2
2
 
3
+ ## 1.0.0-beta.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`ac0d2f4`](https://github.com/mastra-ai/mastra/commit/ac0d2f4ff8831f72c1c66c2be809706d17f65789), [`1a0d3fc`](https://github.com/mastra-ai/mastra/commit/1a0d3fc811482c9c376cdf79ee615c23bae9b2d6), [`85a628b`](https://github.com/mastra-ai/mastra/commit/85a628b1224a8f64cd82ea7f033774bf22df7a7e), [`c237233`](https://github.com/mastra-ai/mastra/commit/c23723399ccedf7f5744b3f40997b79246bfbe64), [`15f9e21`](https://github.com/mastra-ai/mastra/commit/15f9e216177201ea6e3f6d0bfb063fcc0953444f), [`ff94dea`](https://github.com/mastra-ai/mastra/commit/ff94dea935f4e34545c63bcb6c29804732698809), [`5b2ff46`](https://github.com/mastra-ai/mastra/commit/5b2ff4651df70c146523a7fca773f8eb0a2272f8), [`db41688`](https://github.com/mastra-ai/mastra/commit/db4168806d007417e2e60b4f68656dca4e5f40c9), [`5ca599d`](https://github.com/mastra-ai/mastra/commit/5ca599d0bb59a1595f19f58473fcd67cc71cef58), [`bff1145`](https://github.com/mastra-ai/mastra/commit/bff114556b3cbadad9b2768488708f8ad0e91475), [`5c8ca24`](https://github.com/mastra-ai/mastra/commit/5c8ca247094e0cc2cdbd7137822fb47241f86e77), [`e191844`](https://github.com/mastra-ai/mastra/commit/e1918444ca3f80e82feef1dad506cd4ec6e2875f), [`22553f1`](https://github.com/mastra-ai/mastra/commit/22553f11c63ee5e966a9c034a349822249584691), [`7237163`](https://github.com/mastra-ai/mastra/commit/72371635dbf96a87df4b073cc48fc655afbdce3d), [`2500740`](https://github.com/mastra-ai/mastra/commit/2500740ea23da067d6e50ec71c625ab3ce275e64), [`873ecbb`](https://github.com/mastra-ai/mastra/commit/873ecbb517586aa17d2f1e99283755b3ebb2863f), [`97fee86`](https://github.com/mastra-ai/mastra/commit/97fee863b3dcca8b998faa016741e57ddff0acc9), [`4f9bbe5`](https://github.com/mastra-ai/mastra/commit/4f9bbe5968f42c86f4930b8193de3c3c17e5bd36), [`02e51fe`](https://github.com/mastra-ai/mastra/commit/02e51feddb3d4155cfbcc42624fd0d0970d032c0), [`8f3fa3a`](https://github.com/mastra-ai/mastra/commit/8f3fa3a652bb77da092f913ec51ae46e3a7e27dc), [`cd29ad2`](https://github.com/mastra-ai/mastra/commit/cd29ad23a255534e8191f249593849ed29160886), [`bdf4d8c`](https://github.com/mastra-ai/mastra/commit/bdf4d8cdc656d8a2c21d81834bfa3bfa70f56c16), [`854e3da`](https://github.com/mastra-ai/mastra/commit/854e3dad5daac17a91a20986399d3a51f54bf68b), [`ce18d38`](https://github.com/mastra-ai/mastra/commit/ce18d38678c65870350d123955014a8432075fd9), [`cccf9c8`](https://github.com/mastra-ai/mastra/commit/cccf9c8b2d2dfc1a5e63919395b83d78c89682a0), [`61a5705`](https://github.com/mastra-ai/mastra/commit/61a570551278b6743e64243b3ce7d73de915ca8a), [`db70a48`](https://github.com/mastra-ai/mastra/commit/db70a48aeeeeb8e5f92007e8ede52c364ce15287), [`f0fdc14`](https://github.com/mastra-ai/mastra/commit/f0fdc14ee233d619266b3d2bbdeea7d25cfc6d13), [`db18bc9`](https://github.com/mastra-ai/mastra/commit/db18bc9c3825e2c1a0ad9a183cc9935f6691bfa1), [`9b37b56`](https://github.com/mastra-ai/mastra/commit/9b37b565e1f2a76c24f728945cc740c2b09be9da), [`41a23c3`](https://github.com/mastra-ai/mastra/commit/41a23c32f9877d71810f37e24930515df2ff7a0f), [`5d171ad`](https://github.com/mastra-ai/mastra/commit/5d171ad9ef340387276b77c2bb3e83e83332d729), [`f03ae60`](https://github.com/mastra-ai/mastra/commit/f03ae60500fe350c9d828621006cdafe1975fdd8), [`d1e74a0`](https://github.com/mastra-ai/mastra/commit/d1e74a0a293866dece31022047f5dbab65a304d0), [`39e7869`](https://github.com/mastra-ai/mastra/commit/39e7869bc7d0ee391077ce291474d8a84eedccff), [`5761926`](https://github.com/mastra-ai/mastra/commit/57619260c4a2cdd598763abbacd90de594c6bc76), [`c900fdd`](https://github.com/mastra-ai/mastra/commit/c900fdd504c41348efdffb205cfe80d48c38fa33), [`604a79f`](https://github.com/mastra-ai/mastra/commit/604a79fecf276e26a54a3fe01bb94e65315d2e0e), [`887f0b4`](https://github.com/mastra-ai/mastra/commit/887f0b4746cdbd7cb7d6b17ac9f82aeb58037ea5), [`2562143`](https://github.com/mastra-ai/mastra/commit/256214336b4faa78646c9c1776612393790d8784), [`ef11a61`](https://github.com/mastra-ai/mastra/commit/ef11a61920fa0ed08a5b7ceedd192875af119749), [`ce32589`](https://github.com/mastra-ai/mastra/commit/ce325896358daa1088715ea13aac9eca596a4871)]:
8
+ - @mastra/core@1.0.0-beta.6
9
+ - @mastra/memory@1.0.0-beta.3
10
+
3
11
  ## 1.0.0-beta.2
4
12
 
5
13
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EAIV,qBAAqB,EACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAExE,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAK3E,OAAO,KAAK,EAAE,kBAAkB,EAAwB,MAAM,UAAU,CAAC;AA+BzE,qBAAa,YAAa,SAAQ,KAAK;IACrC,OAAO,CAAC,aAAa,CAAqB;IAE1C;;OAEG;gBACS,MAAM,EAAE,kBAAkB;IAiCtC;;;OAGG;IACH,cAAc,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E,gBAAgB,EAC1B,aAAa,CAAC,EAAE,qBAAqB,CAAC,MAAM,CAAC,GAC5C,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IA2B/B,QAAQ,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,EACpD,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,CAAC,EAAE,qBAAqB,CAAC,MAAM,CAAC,GACtC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;CA0B5E"}
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Agent, tryGenerateWithJsonFallback, tryStreamWithJsonFallback } from '@mastra/core/agent';
2
2
  import { Memory } from '@mastra/memory';
3
- import { TokenLimiter } from '@mastra/memory/processors';
4
3
  import { exec as exec$1, execFile as execFile$1, spawn as spawn$1 } from 'child_process';
5
4
  import { mkdtemp, rm, readFile, writeFile, readdir, mkdir, copyFile, stat } from 'fs/promises';
6
5
  import { join, resolve, basename, extname, dirname, isAbsolute, relative } from 'path';
@@ -11,7 +10,6 @@ import { existsSync, readFileSync } from 'fs';
11
10
  import { createRequire } from 'module';
12
11
  import { promisify } from 'util';
13
12
  import { ModelRouterLanguageModel } from '@mastra/core/llm';
14
- import { MemoryProcessor } from '@mastra/core/memory';
15
13
  import { tmpdir } from 'os';
16
14
  import { openai } from '@ai-sdk/openai';
17
15
  import { createStep, createWorkflow } from '@mastra/core/workflows';
@@ -3084,11 +3082,12 @@ export const mastra = new Mastra({
3084
3082
  }
3085
3083
  }
3086
3084
  };
3087
- var ToolSummaryProcessor = class extends MemoryProcessor {
3085
+ var ToolSummaryProcessor = class {
3086
+ id = "tool-summary-processor";
3087
+ name = "ToolSummaryProcessor";
3088
3088
  summaryAgent;
3089
3089
  summaryCache = /* @__PURE__ */ new Map();
3090
3090
  constructor({ summaryModel }) {
3091
- super({ name: "ToolSummaryProcessor" });
3092
3091
  this.summaryAgent = new Agent({
3093
3092
  id: "tool-summary-agent",
3094
3093
  name: "Tool Summary Agent",
@@ -3125,30 +3124,37 @@ var ToolSummaryProcessor = class extends MemoryProcessor {
3125
3124
  keys: Array.from(this.summaryCache.keys())
3126
3125
  };
3127
3126
  }
3128
- async process(messages) {
3127
+ async processInput({
3128
+ messages,
3129
+ messageList: _messageList
3130
+ }) {
3129
3131
  const summaryTasks = [];
3130
3132
  for (const message of messages) {
3131
- if (message.role === "tool" && Array.isArray(message.content) && message.content.length > 0 && message.content?.some((content) => content.type === "tool-result")) {
3132
- for (const content of message.content) {
3133
- if (content.type === "tool-result") {
3134
- const assistantMessageWithToolCall = messages.find(
3135
- (message2) => message2.role === "assistant" && Array.isArray(message2.content) && message2.content.length > 0 && message2.content?.some(
3136
- (assistantContent) => assistantContent.type === "tool-call" && assistantContent.toolCallId === content.toolCallId
3137
- )
3138
- );
3139
- const toolCall = Array.isArray(assistantMessageWithToolCall?.content) ? assistantMessageWithToolCall?.content.find(
3140
- (assistantContent) => assistantContent.type === "tool-call" && assistantContent.toolCallId === content.toolCallId
3141
- ) : null;
3142
- const cacheKey = this.createCacheKey(toolCall);
3133
+ if (message.content.format === 2 && message.content.parts) {
3134
+ for (let partIndex = 0; partIndex < message.content.parts.length; partIndex++) {
3135
+ const part = message.content.parts[partIndex];
3136
+ if (part && part.type === "tool-invocation" && part.toolInvocation?.state === "result") {
3137
+ const cacheKey = this.createCacheKey(part.toolInvocation);
3143
3138
  const cachedSummary = this.summaryCache.get(cacheKey);
3144
3139
  if (cachedSummary) {
3145
- content.result = `Tool call summary: ${cachedSummary}`;
3140
+ message.content.parts[partIndex] = {
3141
+ type: "tool-invocation",
3142
+ toolInvocation: {
3143
+ state: "result",
3144
+ step: part.toolInvocation.step,
3145
+ toolCallId: part.toolInvocation.toolCallId,
3146
+ toolName: part.toolInvocation.toolName,
3147
+ args: part.toolInvocation.args,
3148
+ result: `Tool call summary: ${cachedSummary}`
3149
+ }
3150
+ };
3146
3151
  } else {
3147
3152
  const summaryPromise = this.summaryAgent.generate(
3148
- `Summarize the following tool call: ${JSON.stringify(toolCall)} and result: ${JSON.stringify(content)}`
3153
+ `Summarize the following tool call: ${JSON.stringify(part.toolInvocation)}`
3149
3154
  );
3150
3155
  summaryTasks.push({
3151
- content,
3156
+ message,
3157
+ partIndex,
3152
3158
  promise: summaryPromise,
3153
3159
  cacheKey
3154
3160
  });
@@ -3166,10 +3172,24 @@ var ToolSummaryProcessor = class extends MemoryProcessor {
3166
3172
  const summaryResult = result.value;
3167
3173
  const summaryText = summaryResult.text;
3168
3174
  this.summaryCache.set(task.cacheKey, summaryText);
3169
- task.content.result = `Tool call summary: ${summaryText}`;
3175
+ if (task.message.content.format === 2 && task.message.content.parts) {
3176
+ const part = task.message.content.parts[task.partIndex];
3177
+ if (part && part.type === "tool-invocation" && part.toolInvocation?.state === "result") {
3178
+ task.message.content.parts[task.partIndex] = {
3179
+ type: "tool-invocation",
3180
+ toolInvocation: {
3181
+ state: "result",
3182
+ step: part.toolInvocation.step,
3183
+ toolCallId: part.toolInvocation.toolCallId,
3184
+ toolName: part.toolInvocation.toolName,
3185
+ args: part.toolInvocation.args,
3186
+ result: `Tool call summary: ${summaryText}`
3187
+ }
3188
+ };
3189
+ }
3190
+ }
3170
3191
  } else if (result.status === "rejected") {
3171
3192
  console.warn(`Failed to generate summary for tool call:`, result.reason);
3172
- task.content.result = `Tool call summary: [Summary generation failed]`;
3173
3193
  }
3174
3194
  });
3175
3195
  }
@@ -3201,15 +3221,14 @@ ${config.instructions}` : "";
3201
3221
  };
3202
3222
  },
3203
3223
  memory: new Memory({
3204
- options: AgentBuilderDefaults.DEFAULT_MEMORY_CONFIG,
3205
- processors: [
3206
- // use the write to disk processor to debug the agent's context
3207
- // new WriteToDiskProcessor({ prefix: 'before-filter' }),
3208
- new ToolSummaryProcessor({ summaryModel: config.summaryModel || config.model }),
3209
- new TokenLimiter(1e5)
3210
- // new WriteToDiskProcessor({ prefix: 'after-filter' }),
3211
- ]
3212
- })
3224
+ options: AgentBuilderDefaults.DEFAULT_MEMORY_CONFIG
3225
+ }),
3226
+ inputProcessors: [
3227
+ // use the write to disk processor to debug the agent's context
3228
+ // new WriteToDiskProcessor({ prefix: 'before-filter' }),
3229
+ new ToolSummaryProcessor({ summaryModel: config.summaryModel || config.model })
3230
+ // new WriteToDiskProcessor({ prefix: 'after-filter' }),
3231
+ ]
3213
3232
  };
3214
3233
  super(agentConfig);
3215
3234
  this.builderConfig = config;