@mastra/agent-builder 0.0.0-main-test-05-11-2025-2-20251106053353 → 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';
@@ -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
  }
@@ -3189,6 +3209,7 @@ var AgentBuilder = class extends Agent {
3189
3209
  ${config.instructions}` : "";
3190
3210
  const combinedInstructions = additionalInstructions + AgentBuilderDefaults.DEFAULT_INSTRUCTIONS(config.projectPath);
3191
3211
  const agentConfig = {
3212
+ id: "agent-builder",
3192
3213
  name: "agent-builder",
3193
3214
  description: "An AI agent specialized in generating Mastra agents, tools, and workflows from natural language requirements.",
3194
3215
  instructions: combinedInstructions,
@@ -3200,15 +3221,14 @@ ${config.instructions}` : "";
3200
3221
  };
3201
3222
  },
3202
3223
  memory: new Memory({
3203
- options: AgentBuilderDefaults.DEFAULT_MEMORY_CONFIG,
3204
- processors: [
3205
- // use the write to disk processor to debug the agent's context
3206
- // new WriteToDiskProcessor({ prefix: 'before-filter' }),
3207
- new ToolSummaryProcessor({ summaryModel: config.summaryModel || config.model }),
3208
- new TokenLimiter(1e5)
3209
- // new WriteToDiskProcessor({ prefix: 'after-filter' }),
3210
- ]
3211
- })
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
+ ]
3212
3232
  };
3213
3233
  super(agentConfig);
3214
3234
  this.builderConfig = config;
@@ -5072,6 +5092,7 @@ var planningIterationStep = createStep({
5072
5092
  try {
5073
5093
  const model = await resolveModel({ requestContext });
5074
5094
  const planningAgent = new Agent({
5095
+ id: "workflow-planning-agent",
5075
5096
  model,
5076
5097
  instructions: taskPlanningPrompts.planningAgent.instructions({
5077
5098
  storedQAPairs
@@ -5802,6 +5823,7 @@ var workflowResearchStep = createStep({
5802
5823
  try {
5803
5824
  const model = await resolveModel({ requestContext });
5804
5825
  const researchAgent = new Agent({
5826
+ id: "workflow-research-agent",
5805
5827
  model,
5806
5828
  instructions: workflowBuilderPrompts.researchAgent.instructions,
5807
5829
  name: "Workflow Research Agent"