@mastra/agent-builder 0.0.0-main-test-05-11-2025-2-20251106025330 → 0.0.0-main-test-2-20251127211532

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 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';
@@ -913,6 +911,7 @@ export const weatherAgent = new Agent({
913
911
  tools: { weatherTool },
914
912
  memory: new Memory({
915
913
  storage: new LibSQLStore({
914
+ id: 'mastra-memory-storage',
916
915
  url: 'file:../mastra.db', // ask user what database to use, use this as the default
917
916
  }),
918
917
  }),
@@ -1080,6 +1079,7 @@ export const mastra = new Mastra({
1080
1079
  workflows: { weatherWorkflow },
1081
1080
  agents: { weatherAgent },
1082
1081
  storage: new LibSQLStore({
1082
+ id: 'mastra-storage',
1083
1083
  // stores observability, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
1084
1084
  url: ":memory:",
1085
1085
  }),
@@ -3082,11 +3082,12 @@ export const mastra = new Mastra({
3082
3082
  }
3083
3083
  }
3084
3084
  };
3085
- var ToolSummaryProcessor = class extends MemoryProcessor {
3085
+ var ToolSummaryProcessor = class {
3086
+ id = "tool-summary-processor";
3087
+ name = "ToolSummaryProcessor";
3086
3088
  summaryAgent;
3087
3089
  summaryCache = /* @__PURE__ */ new Map();
3088
3090
  constructor({ summaryModel }) {
3089
- super({ name: "ToolSummaryProcessor" });
3090
3091
  this.summaryAgent = new Agent({
3091
3092
  id: "tool-summary-agent",
3092
3093
  name: "Tool Summary Agent",
@@ -3123,30 +3124,37 @@ var ToolSummaryProcessor = class extends MemoryProcessor {
3123
3124
  keys: Array.from(this.summaryCache.keys())
3124
3125
  };
3125
3126
  }
3126
- async process(messages) {
3127
+ async processInput({
3128
+ messages,
3129
+ messageList: _messageList
3130
+ }) {
3127
3131
  const summaryTasks = [];
3128
3132
  for (const message of messages) {
3129
- if (message.role === "tool" && Array.isArray(message.content) && message.content.length > 0 && message.content?.some((content) => content.type === "tool-result")) {
3130
- for (const content of message.content) {
3131
- if (content.type === "tool-result") {
3132
- const assistantMessageWithToolCall = messages.find(
3133
- (message2) => message2.role === "assistant" && Array.isArray(message2.content) && message2.content.length > 0 && message2.content?.some(
3134
- (assistantContent) => assistantContent.type === "tool-call" && assistantContent.toolCallId === content.toolCallId
3135
- )
3136
- );
3137
- const toolCall = Array.isArray(assistantMessageWithToolCall?.content) ? assistantMessageWithToolCall?.content.find(
3138
- (assistantContent) => assistantContent.type === "tool-call" && assistantContent.toolCallId === content.toolCallId
3139
- ) : null;
3140
- 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);
3141
3138
  const cachedSummary = this.summaryCache.get(cacheKey);
3142
3139
  if (cachedSummary) {
3143
- 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
+ };
3144
3151
  } else {
3145
3152
  const summaryPromise = this.summaryAgent.generate(
3146
- `Summarize the following tool call: ${JSON.stringify(toolCall)} and result: ${JSON.stringify(content)}`
3153
+ `Summarize the following tool call: ${JSON.stringify(part.toolInvocation)}`
3147
3154
  );
3148
3155
  summaryTasks.push({
3149
- content,
3156
+ message,
3157
+ partIndex,
3150
3158
  promise: summaryPromise,
3151
3159
  cacheKey
3152
3160
  });
@@ -3164,10 +3172,24 @@ var ToolSummaryProcessor = class extends MemoryProcessor {
3164
3172
  const summaryResult = result.value;
3165
3173
  const summaryText = summaryResult.text;
3166
3174
  this.summaryCache.set(task.cacheKey, summaryText);
3167
- 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
+ }
3168
3191
  } else if (result.status === "rejected") {
3169
3192
  console.warn(`Failed to generate summary for tool call:`, result.reason);
3170
- task.content.result = `Tool call summary: [Summary generation failed]`;
3171
3193
  }
3172
3194
  });
3173
3195
  }
@@ -3187,6 +3209,7 @@ var AgentBuilder = class extends Agent {
3187
3209
  ${config.instructions}` : "";
3188
3210
  const combinedInstructions = additionalInstructions + AgentBuilderDefaults.DEFAULT_INSTRUCTIONS(config.projectPath);
3189
3211
  const agentConfig = {
3212
+ id: "agent-builder",
3190
3213
  name: "agent-builder",
3191
3214
  description: "An AI agent specialized in generating Mastra agents, tools, and workflows from natural language requirements.",
3192
3215
  instructions: combinedInstructions,
@@ -3198,15 +3221,14 @@ ${config.instructions}` : "";
3198
3221
  };
3199
3222
  },
3200
3223
  memory: new Memory({
3201
- options: AgentBuilderDefaults.DEFAULT_MEMORY_CONFIG,
3202
- processors: [
3203
- // use the write to disk processor to debug the agent's context
3204
- // new WriteToDiskProcessor({ prefix: 'before-filter' }),
3205
- new ToolSummaryProcessor({ summaryModel: config.summaryModel || config.model }),
3206
- new TokenLimiter(1e5)
3207
- // new WriteToDiskProcessor({ prefix: 'after-filter' }),
3208
- ]
3209
- })
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
+ ]
3210
3232
  };
3211
3233
  super(agentConfig);
3212
3234
  this.builderConfig = config;
@@ -5070,6 +5092,7 @@ var planningIterationStep = createStep({
5070
5092
  try {
5071
5093
  const model = await resolveModel({ requestContext });
5072
5094
  const planningAgent = new Agent({
5095
+ id: "workflow-planning-agent",
5073
5096
  model,
5074
5097
  instructions: taskPlanningPrompts.planningAgent.instructions({
5075
5098
  storedQAPairs
@@ -5410,7 +5433,7 @@ export const mastra = new Mastra({
5410
5433
  sendEmailWorkflow, // Use camelCase for keys
5411
5434
  dataProcessingWorkflow
5412
5435
  },
5413
- storage: new LibSQLStore({ url: 'file:./mastra.db' }), // Required for suspend/resume
5436
+ storage: new LibSQLStore({ id: 'mastra-storage', url: 'file:./mastra.db' }), // Required for suspend/resume
5414
5437
  });
5415
5438
  \`\`\`
5416
5439
 
@@ -5800,6 +5823,7 @@ var workflowResearchStep = createStep({
5800
5823
  try {
5801
5824
  const model = await resolveModel({ requestContext });
5802
5825
  const researchAgent = new Agent({
5826
+ id: "workflow-research-agent",
5803
5827
  model,
5804
5828
  instructions: workflowBuilderPrompts.researchAgent.instructions,
5805
5829
  name: "Workflow Research Agent"