@mastra/agent-builder 0.0.0-just-snapshot-20251014192224 → 0.0.0-main-test-05-11-2025-2-20251105214713

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
@@ -501,11 +501,11 @@ async function renameAndCopyFile(sourceFile, targetFile) {
501
501
  var isValidMastraLanguageModel = (model) => {
502
502
  return model && typeof model === "object" && typeof model.modelId === "string";
503
503
  };
504
- var resolveTargetPath = (inputData, runtimeContext) => {
504
+ var resolveTargetPath = (inputData, requestContext) => {
505
505
  if (inputData.targetPath) {
506
506
  return inputData.targetPath;
507
507
  }
508
- const contextPath = runtimeContext.get("targetPath");
508
+ const contextPath = requestContext.get("targetPath");
509
509
  if (contextPath) {
510
510
  return contextPath;
511
511
  }
@@ -674,13 +674,13 @@ var createModelInstance = async (provider, modelId, version = "v2") => {
674
674
  }
675
675
  };
676
676
  var resolveModel = async ({
677
- runtimeContext,
677
+ requestContext,
678
678
  defaultModel = "openai/gpt-4.1",
679
679
  projectPath
680
680
  }) => {
681
- const modelFromContext = runtimeContext.get("model");
681
+ const modelFromContext = requestContext.get("model");
682
682
  if (modelFromContext) {
683
- console.info("Using model from runtime context");
683
+ console.info("Using model from request context");
684
684
  if (isValidMastraLanguageModel(modelFromContext)) {
685
685
  return modelFromContext;
686
686
  }
@@ -688,13 +688,13 @@ var resolveModel = async ({
688
688
  'Invalid model provided. Model must be a MastraLanguageModel instance (e.g., openai("gpt-4"), anthropic("claude-3-5-sonnet"), etc.)'
689
689
  );
690
690
  }
691
- const selectedModel = runtimeContext.get("selectedModel");
691
+ const selectedModel = requestContext.get("selectedModel");
692
692
  if (selectedModel?.provider && selectedModel?.modelId && projectPath) {
693
693
  console.info(`Resolving selected model: ${selectedModel.provider}/${selectedModel.modelId}`);
694
694
  const version = await detectAISDKVersion(projectPath);
695
695
  const modelInstance = await createModelInstance(selectedModel.provider, selectedModel.modelId, version);
696
696
  if (modelInstance) {
697
- runtimeContext.set("model", modelInstance);
697
+ requestContext.set("model", modelInstance);
698
698
  return modelInstance;
699
699
  }
700
700
  }
@@ -868,7 +868,7 @@ You have access to an enhanced set of tools based on production coding agent pat
868
868
  ### Task Management
869
869
  - **taskManager**: Create and track multi-step coding tasks with states (pending, in_progress, completed, blocked). Use this for complex projects that require systematic progress tracking.
870
870
 
871
- ### Code Discovery & Analysis
871
+ ### Code Discovery & Analysis
872
872
  - **codeAnalyzer**: Analyze codebase structure, discover definitions (functions, classes, interfaces), map dependencies, and understand architectural patterns.
873
873
  - **smartSearch**: Intelligent search with context awareness, pattern matching, and relevance scoring.
874
874
 
@@ -906,6 +906,7 @@ import { LibSQLStore } from '@mastra/libsql';
906
906
  import { weatherTool } from '../tools/weather-tool';
907
907
 
908
908
  export const weatherAgent = new Agent({
909
+ id: 'weather-agent',
909
910
  name: 'Weather Agent',
910
911
  instructions: \${instructions},
911
912
  model: openai('gpt-4o-mini'),
@@ -940,8 +941,8 @@ export const weatherTool = createTool({
940
941
  conditions: z.string(),
941
942
  location: z.string(),
942
943
  }),
943
- execute: async ({ context }) => {
944
- return await getWeather(context.location);
944
+ execute: async (inputData) => {
945
+ return await getWeather(inputData.location);
945
946
  },
946
947
  });
947
948
  \`\`\`
@@ -959,7 +960,7 @@ const fetchWeather = createStep({
959
960
  city: z.string().describe('The city to get the weather for'),
960
961
  }),
961
962
  outputSchema: forecastSchema,
962
- execute: async ({ inputData }) => {
963
+ execute: async (inputData) => {
963
964
  if (!inputData) {
964
965
  throw new Error('Input data not found');
965
966
  }
@@ -1013,7 +1014,8 @@ const planActivities = createStep({
1013
1014
  outputSchema: z.object({
1014
1015
  activities: z.string(),
1015
1016
  }),
1016
- execute: async ({ inputData, mastra }) => {
1017
+ execute: async (inputData, context) => {
1018
+ const mastra = context?.mastra;
1017
1019
  const forecast = inputData;
1018
1020
 
1019
1021
  if (!forecast) {
@@ -1078,7 +1080,7 @@ export const mastra = new Mastra({
1078
1080
  workflows: { weatherWorkflow },
1079
1081
  agents: { weatherAgent },
1080
1082
  storage: new LibSQLStore({
1081
- // stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
1083
+ // stores observability, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
1082
1084
  url: ":memory:",
1083
1085
  }),
1084
1086
  logger: new PinoLogger({
@@ -1122,8 +1124,8 @@ export const mastra = new Mastra({
1122
1124
  }).optional(),
1123
1125
  error: z.string().optional()
1124
1126
  }),
1125
- execute: async ({ context }) => {
1126
- return await _AgentBuilderDefaults.readFile({ ...context, projectPath });
1127
+ execute: async (inputData) => {
1128
+ return await _AgentBuilderDefaults.readFile({ ...inputData, projectPath });
1127
1129
  }
1128
1130
  }),
1129
1131
  writeFile: createTool({
@@ -1142,8 +1144,8 @@ export const mastra = new Mastra({
1142
1144
  message: z.string(),
1143
1145
  error: z.string().optional()
1144
1146
  }),
1145
- execute: async ({ context }) => {
1146
- return await _AgentBuilderDefaults.writeFile({ ...context, projectPath });
1147
+ execute: async (inputData) => {
1148
+ return await _AgentBuilderDefaults.writeFile({ ...inputData, projectPath });
1147
1149
  }
1148
1150
  }),
1149
1151
  listDirectory: createTool({
@@ -1174,8 +1176,8 @@ export const mastra = new Mastra({
1174
1176
  message: z.string(),
1175
1177
  error: z.string().optional()
1176
1178
  }),
1177
- execute: async ({ context }) => {
1178
- return await _AgentBuilderDefaults.listDirectory({ ...context, projectPath });
1179
+ execute: async (inputData) => {
1180
+ return await _AgentBuilderDefaults.listDirectory({ ...inputData, projectPath });
1179
1181
  }
1180
1182
  }),
1181
1183
  executeCommand: createTool({
@@ -1199,10 +1201,10 @@ export const mastra = new Mastra({
1199
1201
  executionTime: z.number().optional(),
1200
1202
  error: z.string().optional()
1201
1203
  }),
1202
- execute: async ({ context }) => {
1204
+ execute: async (inputData) => {
1203
1205
  return await _AgentBuilderDefaults.executeCommand({
1204
- ...context,
1205
- workingDirectory: context.workingDirectory || projectPath
1206
+ ...inputData,
1207
+ workingDirectory: inputData.workingDirectory || projectPath
1206
1208
  });
1207
1209
  }
1208
1210
  }),
@@ -1240,8 +1242,8 @@ export const mastra = new Mastra({
1240
1242
  ),
1241
1243
  message: z.string()
1242
1244
  }),
1243
- execute: async ({ context }) => {
1244
- return await _AgentBuilderDefaults.manageTaskList(context);
1245
+ execute: async (inputData) => {
1246
+ return await _AgentBuilderDefaults.manageTaskList(inputData);
1245
1247
  }
1246
1248
  }),
1247
1249
  // Advanced File Operations
@@ -1275,8 +1277,8 @@ export const mastra = new Mastra({
1275
1277
  ),
1276
1278
  message: z.string()
1277
1279
  }),
1278
- execute: async ({ context }) => {
1279
- return await _AgentBuilderDefaults.performMultiEdit({ ...context, projectPath });
1280
+ execute: async (inputData) => {
1281
+ return await _AgentBuilderDefaults.performMultiEdit({ ...inputData, projectPath });
1280
1282
  }
1281
1283
  }),
1282
1284
  replaceLines: createTool({
@@ -1300,8 +1302,8 @@ export const mastra = new Mastra({
1300
1302
  backup: z.string().optional(),
1301
1303
  error: z.string().optional()
1302
1304
  }),
1303
- execute: async ({ context }) => {
1304
- return await _AgentBuilderDefaults.replaceLines({ ...context, projectPath });
1305
+ execute: async (inputData) => {
1306
+ return await _AgentBuilderDefaults.replaceLines({ ...inputData, projectPath });
1305
1307
  }
1306
1308
  }),
1307
1309
  // File diagnostics tool to help debug line replacement issues
@@ -1329,8 +1331,8 @@ export const mastra = new Mastra({
1329
1331
  message: z.string(),
1330
1332
  error: z.string().optional()
1331
1333
  }),
1332
- execute: async ({ context }) => {
1333
- return await _AgentBuilderDefaults.showFileLines({ ...context, projectPath });
1334
+ execute: async (inputData) => {
1335
+ return await _AgentBuilderDefaults.showFileLines({ ...inputData, projectPath });
1334
1336
  }
1335
1337
  }),
1336
1338
  // Enhanced Pattern Search
@@ -1373,8 +1375,8 @@ export const mastra = new Mastra({
1373
1375
  patterns: z.array(z.string())
1374
1376
  })
1375
1377
  }),
1376
- execute: async ({ context }) => {
1377
- return await _AgentBuilderDefaults.performSmartSearch(context, projectPath);
1378
+ execute: async (inputData) => {
1379
+ return await _AgentBuilderDefaults.performSmartSearch(inputData, projectPath);
1378
1380
  }
1379
1381
  }),
1380
1382
  validateCode: createTool({
@@ -1407,8 +1409,8 @@ export const mastra = new Mastra({
1407
1409
  validationsFailed: z.array(z.string())
1408
1410
  })
1409
1411
  }),
1410
- execute: async ({ context }) => {
1411
- const { projectPath: validationProjectPath, validationType, files } = context;
1412
+ execute: async (inputData) => {
1413
+ const { projectPath: validationProjectPath, validationType, files } = inputData;
1412
1414
  const targetPath = validationProjectPath || projectPath;
1413
1415
  return await _AgentBuilderDefaults.validateCode({
1414
1416
  projectPath: targetPath,
@@ -1447,8 +1449,8 @@ export const mastra = new Mastra({
1447
1449
  suggestions: z.array(z.string()).optional(),
1448
1450
  error: z.string().optional()
1449
1451
  }),
1450
- execute: async ({ context }) => {
1451
- return await _AgentBuilderDefaults.webSearch(context);
1452
+ execute: async (inputData) => {
1453
+ return await _AgentBuilderDefaults.webSearch(inputData);
1452
1454
  }
1453
1455
  }),
1454
1456
  // Task Completion Signaling
@@ -1477,8 +1479,8 @@ export const mastra = new Mastra({
1477
1479
  summary: z.string(),
1478
1480
  confidence: z.number().min(0).max(100)
1479
1481
  }),
1480
- execute: async ({ context }) => {
1481
- return await _AgentBuilderDefaults.signalCompletion(context);
1482
+ execute: async (inputData) => {
1483
+ return await _AgentBuilderDefaults.signalCompletion(inputData);
1482
1484
  }
1483
1485
  }),
1484
1486
  manageProject: createTool({
@@ -1503,8 +1505,8 @@ export const mastra = new Mastra({
1503
1505
  details: z.string().optional(),
1504
1506
  error: z.string().optional()
1505
1507
  }),
1506
- execute: async ({ context }) => {
1507
- const { action, features, packages } = context;
1508
+ execute: async (inputData) => {
1509
+ const { action, features, packages } = inputData;
1508
1510
  try {
1509
1511
  switch (action) {
1510
1512
  case "create":
@@ -1565,8 +1567,8 @@ export const mastra = new Mastra({
1565
1567
  stdout: z.array(z.string()).optional().describe("Server output lines captured during startup"),
1566
1568
  error: z.string().optional()
1567
1569
  }),
1568
- execute: async ({ context }) => {
1569
- const { action, port } = context;
1570
+ execute: async (inputData) => {
1571
+ const { action, port } = inputData;
1570
1572
  try {
1571
1573
  switch (action) {
1572
1574
  case "start":
@@ -1651,8 +1653,8 @@ export const mastra = new Mastra({
1651
1653
  url: z.string(),
1652
1654
  method: z.string()
1653
1655
  }),
1654
- execute: async ({ context }) => {
1655
- const { method, url, baseUrl, headers, body, timeout } = context;
1656
+ execute: async (inputData) => {
1657
+ const { method, url, baseUrl, headers, body, timeout } = inputData;
1656
1658
  try {
1657
1659
  return await _AgentBuilderDefaults.makeHttpRequest({
1658
1660
  method,
@@ -1707,7 +1709,7 @@ export const mastra = new Mastra({
1707
1709
  /**
1708
1710
  * Get tools for a specific mode
1709
1711
  */
1710
- static async getToolsForMode(projectPath, mode = "code-editor") {
1712
+ static async listToolsForMode(projectPath, mode = "code-editor") {
1711
1713
  const allTools = await _AgentBuilderDefaults.DEFAULT_TOOLS(projectPath);
1712
1714
  if (mode === "template") {
1713
1715
  return _AgentBuilderDefaults.filterToolsForTemplateBuilder(allTools);
@@ -3086,7 +3088,8 @@ var ToolSummaryProcessor = class extends MemoryProcessor {
3086
3088
  constructor({ summaryModel }) {
3087
3089
  super({ name: "ToolSummaryProcessor" });
3088
3090
  this.summaryAgent = new Agent({
3089
- name: "ToolSummaryAgent",
3091
+ id: "tool-summary-agent",
3092
+ name: "Tool Summary Agent",
3090
3093
  description: "A summary agent that summarizes tool calls and results",
3091
3094
  instructions: "You are a summary agent that summarizes tool calls and results",
3092
3095
  model: summaryModel
@@ -3190,7 +3193,7 @@ ${config.instructions}` : "";
3190
3193
  model: config.model,
3191
3194
  tools: async () => {
3192
3195
  return {
3193
- ...await AgentBuilderDefaults.getToolsForMode(config.projectPath, config.mode),
3196
+ ...await AgentBuilderDefaults.listToolsForMode(config.projectPath, config.mode),
3194
3197
  ...config.tools || {}
3195
3198
  };
3196
3199
  },
@@ -3214,7 +3217,7 @@ ${config.instructions}` : "";
3214
3217
  */
3215
3218
  generateLegacy = async (messages, generateOptions = {}) => {
3216
3219
  const { maxSteps, ...baseOptions } = generateOptions;
3217
- const originalInstructions = await this.getInstructions({ runtimeContext: generateOptions?.runtimeContext });
3220
+ const originalInstructions = await this.getInstructions({ requestContext: generateOptions?.requestContext });
3218
3221
  const additionalInstructions = baseOptions.instructions;
3219
3222
  let enhancedInstructions = originalInstructions;
3220
3223
  if (additionalInstructions) {
@@ -3243,7 +3246,7 @@ ${additionalInstructions}`;
3243
3246
  */
3244
3247
  streamLegacy = async (messages, streamOptions = {}) => {
3245
3248
  const { maxSteps, ...baseOptions } = streamOptions;
3246
- const originalInstructions = await this.getInstructions({ runtimeContext: streamOptions?.runtimeContext });
3249
+ const originalInstructions = await this.getInstructions({ requestContext: streamOptions?.requestContext });
3247
3250
  const additionalInstructions = baseOptions.instructions;
3248
3251
  let enhancedInstructions = originalInstructions;
3249
3252
  if (additionalInstructions) {
@@ -3272,7 +3275,7 @@ ${additionalInstructions}`;
3272
3275
  */
3273
3276
  async stream(messages, streamOptions) {
3274
3277
  const { ...baseOptions } = streamOptions || {};
3275
- const originalInstructions = await this.getInstructions({ runtimeContext: streamOptions?.runtimeContext });
3278
+ const originalInstructions = await this.getInstructions({ requestContext: streamOptions?.requestContext });
3276
3279
  const additionalInstructions = baseOptions.instructions;
3277
3280
  let enhancedInstructions = originalInstructions;
3278
3281
  if (additionalInstructions) {
@@ -3296,7 +3299,7 @@ ${additionalInstructions}`;
3296
3299
  }
3297
3300
  async generate(messages, options) {
3298
3301
  const { ...baseOptions } = options || {};
3299
- const originalInstructions = await this.getInstructions({ runtimeContext: options?.runtimeContext });
3302
+ const originalInstructions = await this.getInstructions({ requestContext: options?.requestContext });
3300
3303
  const additionalInstructions = baseOptions.instructions;
3301
3304
  let enhancedInstructions = originalInstructions;
3302
3305
  if (additionalInstructions) {
@@ -3404,14 +3407,15 @@ var discoverUnitsStep = createStep({
3404
3407
  description: "Discover template units by analyzing the templates directory structure",
3405
3408
  inputSchema: CloneTemplateResultSchema,
3406
3409
  outputSchema: DiscoveryResultSchema,
3407
- execute: async ({ inputData, runtimeContext }) => {
3410
+ execute: async ({ inputData, requestContext }) => {
3408
3411
  const { templateDir } = inputData;
3409
- const targetPath = resolveTargetPath(inputData, runtimeContext);
3412
+ const targetPath = resolveTargetPath(inputData, requestContext);
3410
3413
  const tools = await AgentBuilderDefaults.DEFAULT_TOOLS(templateDir);
3411
3414
  console.info("targetPath", targetPath);
3412
- const model = await resolveModel({ runtimeContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
3415
+ const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
3413
3416
  try {
3414
3417
  const agent = new Agent({
3418
+ id: "mastra-project-discoverer",
3415
3419
  model,
3416
3420
  instructions: `You are an expert at analyzing Mastra projects.
3417
3421
 
@@ -3548,8 +3552,8 @@ var prepareBranchStep = createStep({
3548
3552
  description: "Create or switch to integration branch before modifications",
3549
3553
  inputSchema: PrepareBranchInputSchema,
3550
3554
  outputSchema: PrepareBranchResultSchema,
3551
- execute: async ({ inputData, runtimeContext }) => {
3552
- const targetPath = resolveTargetPath(inputData, runtimeContext);
3555
+ execute: async ({ inputData, requestContext }) => {
3556
+ const targetPath = resolveTargetPath(inputData, requestContext);
3553
3557
  try {
3554
3558
  const branchName = `feat/install-template-${inputData.slug}`;
3555
3559
  await gitCheckoutBranch(branchName, targetPath);
@@ -3573,10 +3577,10 @@ var packageMergeStep = createStep({
3573
3577
  description: "Merge template package.json dependencies into target project",
3574
3578
  inputSchema: PackageMergeInputSchema,
3575
3579
  outputSchema: PackageMergeResultSchema,
3576
- execute: async ({ inputData, runtimeContext }) => {
3580
+ execute: async ({ inputData, requestContext }) => {
3577
3581
  console.info("Package merge step starting...");
3578
3582
  const { slug, packageInfo } = inputData;
3579
- const targetPath = resolveTargetPath(inputData, runtimeContext);
3583
+ const targetPath = resolveTargetPath(inputData, requestContext);
3580
3584
  try {
3581
3585
  const targetPkgPath = join(targetPath, "package.json");
3582
3586
  let targetPkgRaw = "{}";
@@ -3650,9 +3654,9 @@ var installStep = createStep({
3650
3654
  description: "Install packages based on merged package.json",
3651
3655
  inputSchema: InstallInputSchema,
3652
3656
  outputSchema: InstallResultSchema,
3653
- execute: async ({ inputData, runtimeContext }) => {
3657
+ execute: async ({ inputData, requestContext }) => {
3654
3658
  console.info("Running install step...");
3655
- const targetPath = resolveTargetPath(inputData, runtimeContext);
3659
+ const targetPath = resolveTargetPath(inputData, requestContext);
3656
3660
  try {
3657
3661
  await spawnSWPM(targetPath, "install", []);
3658
3662
  const lock = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock"].map((f) => join(targetPath, f)).find((f) => existsSync(f));
@@ -3678,10 +3682,10 @@ var programmaticFileCopyStep = createStep({
3678
3682
  description: "Programmatically copy template files to target project based on ordered units",
3679
3683
  inputSchema: FileCopyInputSchema,
3680
3684
  outputSchema: FileCopyResultSchema,
3681
- execute: async ({ inputData, runtimeContext }) => {
3685
+ execute: async ({ inputData, requestContext }) => {
3682
3686
  console.info("Programmatic file copy step starting...");
3683
3687
  const { orderedUnits, templateDir, commitSha, slug } = inputData;
3684
- const targetPath = resolveTargetPath(inputData, runtimeContext);
3688
+ const targetPath = resolveTargetPath(inputData, requestContext);
3685
3689
  try {
3686
3690
  const copiedFiles = [];
3687
3691
  const conflicts = [];
@@ -4030,12 +4034,12 @@ var intelligentMergeStep = createStep({
4030
4034
  description: "Use AgentBuilder to intelligently merge template files",
4031
4035
  inputSchema: IntelligentMergeInputSchema,
4032
4036
  outputSchema: IntelligentMergeResultSchema,
4033
- execute: async ({ inputData, runtimeContext }) => {
4037
+ execute: async ({ inputData, requestContext }) => {
4034
4038
  console.info("Intelligent merge step starting...");
4035
4039
  const { conflicts, copiedFiles, commitSha, slug, templateDir, branchName } = inputData;
4036
- const targetPath = resolveTargetPath(inputData, runtimeContext);
4040
+ const targetPath = resolveTargetPath(inputData, requestContext);
4037
4041
  try {
4038
- const model = await resolveModel({ runtimeContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
4042
+ const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
4039
4043
  const copyFileTool = createTool({
4040
4044
  id: "copy-file",
4041
4045
  description: "Copy a file from template to target project (use only for edge cases - most files are already copied programmatically).",
@@ -4048,9 +4052,9 @@ var intelligentMergeStep = createStep({
4048
4052
  message: z.string(),
4049
4053
  error: z.string().optional()
4050
4054
  }),
4051
- execute: async ({ context }) => {
4055
+ execute: async (input) => {
4052
4056
  try {
4053
- const { sourcePath, destinationPath } = context;
4057
+ const { sourcePath, destinationPath } = input;
4054
4058
  const resolvedSourcePath = resolve(templateDir, sourcePath);
4055
4059
  const resolvedDestinationPath = resolve(targetPath, destinationPath);
4056
4060
  if (existsSync(resolvedSourcePath) && !existsSync(dirname(resolvedDestinationPath))) {
@@ -4298,10 +4302,10 @@ var validationAndFixStep = createStep({
4298
4302
  description: "Validate the merged template code and fix any issues using a specialized agent",
4299
4303
  inputSchema: ValidationFixInputSchema,
4300
4304
  outputSchema: ValidationFixResultSchema,
4301
- execute: async ({ inputData, runtimeContext }) => {
4305
+ execute: async ({ inputData, requestContext }) => {
4302
4306
  console.info("Validation and fix step starting...");
4303
4307
  const { commitSha, slug, orderedUnits, templateDir, copiedFiles, conflictsResolved, maxIterations = 5 } = inputData;
4304
- const targetPath = resolveTargetPath(inputData, runtimeContext);
4308
+ const targetPath = resolveTargetPath(inputData, requestContext);
4305
4309
  const hasChanges = copiedFiles.length > 0 || conflictsResolved && conflictsResolved.length > 0;
4306
4310
  if (!hasChanges) {
4307
4311
  console.info("\u23ED\uFE0F Skipping validation - no files copied or conflicts resolved");
@@ -4321,10 +4325,11 @@ var validationAndFixStep = createStep({
4321
4325
  );
4322
4326
  let currentIteration = 1;
4323
4327
  try {
4324
- const model = await resolveModel({ runtimeContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
4325
- const allTools = await AgentBuilderDefaults.getToolsForMode(targetPath, "template");
4328
+ const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
4329
+ const allTools = await AgentBuilderDefaults.listToolsForMode(targetPath, "template");
4326
4330
  const validationAgent = new Agent({
4327
- name: "code-validator-fixer",
4331
+ id: "code-validator-fixer",
4332
+ name: "Code Validator Fixer",
4328
4333
  description: "Specialized agent for validating and fixing template integration issues",
4329
4334
  instructions: `You are a code validation and fixing specialist. Your job is to:
4330
4335
 
@@ -4727,7 +4732,7 @@ var agentBuilderTemplateWorkflow = createWorkflow({
4727
4732
  }).commit();
4728
4733
  async function mergeTemplateBySlug(slug, targetPath) {
4729
4734
  const template = await getMastraTemplate(slug);
4730
- const run = await agentBuilderTemplateWorkflow.createRunAsync();
4735
+ const run = await agentBuilderTemplateWorkflow.createRun();
4731
4736
  return await run.start({
4732
4737
  inputData: {
4733
4738
  repo: template.githubUrl,
@@ -5034,7 +5039,7 @@ var planningIterationStep = createStep({
5034
5039
  outputSchema: PlanningIterationResultSchema,
5035
5040
  suspendSchema: PlanningIterationSuspendSchema,
5036
5041
  resumeSchema: PlanningIterationResumeSchema,
5037
- execute: async ({ inputData, resumeData, suspend, runtimeContext }) => {
5042
+ execute: async ({ inputData, resumeData, suspend, requestContext }) => {
5038
5043
  const {
5039
5044
  action,
5040
5045
  workflowName,
@@ -5047,7 +5052,7 @@ var planningIterationStep = createStep({
5047
5052
  } = inputData;
5048
5053
  console.info("Starting planning iteration...");
5049
5054
  const qaKey = "workflow-builder-qa";
5050
- let storedQAPairs = runtimeContext.get(qaKey) || [];
5055
+ let storedQAPairs = requestContext.get(qaKey) || [];
5051
5056
  const newAnswers = { ...userAnswers || {}, ...resumeData?.answers || {} };
5052
5057
  if (Object.keys(newAnswers).length > 0) {
5053
5058
  storedQAPairs = storedQAPairs.map((pair) => {
@@ -5060,10 +5065,10 @@ var planningIterationStep = createStep({
5060
5065
  }
5061
5066
  return pair;
5062
5067
  });
5063
- runtimeContext.set(qaKey, storedQAPairs);
5068
+ requestContext.set(qaKey, storedQAPairs);
5064
5069
  }
5065
5070
  try {
5066
- const model = await resolveModel({ runtimeContext });
5071
+ const model = await resolveModel({ requestContext });
5067
5072
  const planningAgent = new Agent({
5068
5073
  model,
5069
5074
  instructions: taskPlanningPrompts.planningAgent.instructions({
@@ -5094,7 +5099,9 @@ var planningIterationStep = createStep({
5094
5099
  research
5095
5100
  });
5096
5101
  const result = await planningAgent.generate(planningPrompt, {
5097
- output: PlanningAgentOutputSchema
5102
+ structuredOutput: {
5103
+ schema: PlanningAgentOutputSchema
5104
+ }
5098
5105
  // maxSteps: 15,
5099
5106
  });
5100
5107
  const planResult = await result.object;
@@ -5118,7 +5125,7 @@ var planningIterationStep = createStep({
5118
5125
  answeredAt: null
5119
5126
  }));
5120
5127
  storedQAPairs = [...storedQAPairs, ...newQAPairs];
5121
- runtimeContext.set(qaKey, storedQAPairs);
5128
+ requestContext.set(qaKey, storedQAPairs);
5122
5129
  console.info(
5123
5130
  `Updated Q&A state: ${storedQAPairs.length} total question-answer pairs, ${storedQAPairs.filter((p) => p.answer).length} answered`
5124
5131
  );
@@ -5132,7 +5139,7 @@ var planningIterationStep = createStep({
5132
5139
  });
5133
5140
  }
5134
5141
  console.info(`Planning complete with ${planResult.tasks.length} tasks`);
5135
- runtimeContext.set(qaKey, storedQAPairs);
5142
+ requestContext.set(qaKey, storedQAPairs);
5136
5143
  console.info(
5137
5144
  `Final Q&A state: ${storedQAPairs.length} total question-answer pairs, ${storedQAPairs.filter((p) => p.answer).length} answered`
5138
5145
  );
@@ -5277,7 +5284,7 @@ const myStep = createStep({
5277
5284
  - \`mastra\`: Access to Mastra instance (agents, tools, other workflows)
5278
5285
  - \`getStepResult(stepInstance)\`: Get results from previous steps
5279
5286
  - \`getInitData()\`: Access original workflow input data
5280
- - \`runtimeContext\`: Runtime dependency injection context
5287
+ - \`requestContext\`: Runtime dependency injection context
5281
5288
  - \`runCount\`: Number of times this step has run (useful for retries)
5282
5289
 
5283
5290
  ### **\u{1F504} CONTROL FLOW METHODS**
@@ -5356,10 +5363,10 @@ const toolStep = createStep(myTool);
5356
5363
 
5357
5364
  // Method 2: Call tool in execute function
5358
5365
  const step = createStep({
5359
- execute: async ({ inputData, runtimeContext }) => {
5366
+ execute: async ({ inputData, requestContext }) => {
5360
5367
  const result = await myTool.execute({
5361
5368
  context: inputData,
5362
- runtimeContext
5369
+ requestContext
5363
5370
  });
5364
5371
  return result;
5365
5372
  }
@@ -5451,7 +5458,7 @@ export const mastra = new Mastra({
5451
5458
  **Running Workflows:**
5452
5459
  \`\`\`typescript
5453
5460
  // Create and start run
5454
- const run = await workflow.createRunAsync();
5461
+ const run = await workflow.createRun();
5455
5462
  const result = await run.start({ inputData: {...} });
5456
5463
 
5457
5464
  // Stream execution for real-time monitoring
@@ -5475,7 +5482,7 @@ run.watch((event) => console.log(event));
5475
5482
  - Use workflows as steps: \`.then(otherWorkflow)\`
5476
5483
  - Enable complex workflow composition
5477
5484
 
5478
- **Runtime Context:**
5485
+ **Request Context:**
5479
5486
  - Pass shared data across all steps
5480
5487
  - Enable dependency injection patterns
5481
5488
 
@@ -5648,11 +5655,11 @@ var restrictedTaskManager = createTool({
5648
5655
  ),
5649
5656
  message: z.string()
5650
5657
  }),
5651
- execute: async ({ context }) => {
5658
+ execute: async (input) => {
5652
5659
  const adaptedContext = {
5653
- ...context,
5654
- action: context.action,
5655
- tasks: context.tasks?.map((task) => ({
5660
+ ...input,
5661
+ action: input.action,
5662
+ tasks: input.tasks?.map((task) => ({
5656
5663
  ...task,
5657
5664
  priority: task.priority || "medium"
5658
5665
  }))
@@ -5667,7 +5674,7 @@ var workflowDiscoveryStep = createStep({
5667
5674
  description: "Discover existing workflows in the project",
5668
5675
  inputSchema: WorkflowBuilderInputSchema,
5669
5676
  outputSchema: WorkflowDiscoveryResultSchema,
5670
- execute: async ({ inputData, runtimeContext: _runtimeContext }) => {
5677
+ execute: async ({ inputData, requestContext: _requestContext }) => {
5671
5678
  console.info("Starting workflow discovery...");
5672
5679
  const { projectPath = process.cwd() } = inputData;
5673
5680
  try {
@@ -5726,7 +5733,7 @@ var projectDiscoveryStep = createStep({
5726
5733
  description: "Analyze the project structure and setup",
5727
5734
  inputSchema: WorkflowDiscoveryResultSchema,
5728
5735
  outputSchema: ProjectDiscoveryResultSchema,
5729
- execute: async ({ inputData: _inputData, runtimeContext: _runtimeContext }) => {
5736
+ execute: async ({ inputData: _inputData, requestContext: _requestContext }) => {
5730
5737
  console.info("Starting project discovery...");
5731
5738
  try {
5732
5739
  const projectPath = process.cwd();
@@ -5788,10 +5795,10 @@ var workflowResearchStep = createStep({
5788
5795
  description: "Research Mastra workflows and gather relevant documentation",
5789
5796
  inputSchema: ProjectDiscoveryResultSchema,
5790
5797
  outputSchema: WorkflowResearchResultSchema,
5791
- execute: async ({ inputData, runtimeContext }) => {
5798
+ execute: async ({ inputData, requestContext }) => {
5792
5799
  console.info("Starting workflow research...");
5793
5800
  try {
5794
- const model = await resolveModel({ runtimeContext });
5801
+ const model = await resolveModel({ requestContext });
5795
5802
  const researchAgent = new Agent({
5796
5803
  model,
5797
5804
  instructions: workflowBuilderPrompts.researchAgent.instructions,
@@ -5804,7 +5811,9 @@ var workflowResearchStep = createStep({
5804
5811
  hasWorkflowsDir: inputData.structure.hasWorkflowsDir
5805
5812
  });
5806
5813
  const result = await researchAgent.generate(researchPrompt, {
5807
- output: WorkflowResearchResultSchema
5814
+ structuredOutput: {
5815
+ schema: WorkflowResearchResultSchema
5816
+ }
5808
5817
  // stopWhen: stepCountIs(10),
5809
5818
  });
5810
5819
  const researchResult = await result.object;
@@ -5855,7 +5864,7 @@ var taskExecutionStep = createStep({
5855
5864
  outputSchema: TaskExecutionResultSchema,
5856
5865
  suspendSchema: TaskExecutionSuspendSchema,
5857
5866
  resumeSchema: TaskExecutionResumeSchema,
5858
- execute: async ({ inputData, resumeData, suspend, runtimeContext }) => {
5867
+ execute: async ({ inputData, resumeData, suspend, requestContext }) => {
5859
5868
  const {
5860
5869
  action,
5861
5870
  workflowName,
@@ -5870,7 +5879,7 @@ var taskExecutionStep = createStep({
5870
5879
  console.info(`Starting task execution for ${action}ing workflow: ${workflowName}`);
5871
5880
  console.info(`Executing ${tasks.length} tasks using AgentBuilder stream...`);
5872
5881
  try {
5873
- const model = await resolveModel({ runtimeContext });
5882
+ const model = await resolveModel({ requestContext });
5874
5883
  const currentProjectPath = projectPath || process.cwd();
5875
5884
  console.info("Pre-populating taskManager with planned tasks...");
5876
5885
  const taskManagerContext = {
@@ -5915,18 +5924,11 @@ ${workflowBuilderPrompts.validation.instructions}`
5915
5924
  tasks,
5916
5925
  resumeData
5917
5926
  });
5918
- const originalInstructions = await executionAgent.getInstructions({ runtimeContext });
5919
- const additionalInstructions = executionAgent.instructions;
5920
- let enhancedInstructions = originalInstructions;
5921
- if (additionalInstructions) {
5922
- enhancedInstructions = `${originalInstructions}
5923
-
5924
- ${additionalInstructions}`;
5925
- }
5927
+ const originalInstructions = await executionAgent.getInstructions({ requestContext });
5926
5928
  const enhancedOptions = {
5927
5929
  stopWhen: stepCountIs(100),
5928
5930
  temperature: 0.3,
5929
- instructions: enhancedInstructions
5931
+ instructions: originalInstructions
5930
5932
  };
5931
5933
  let finalResult = null;
5932
5934
  let allTasksCompleted = false;