@mastra/agent-builder 0.0.0-netlify-no-bundle-20251127120354 → 0.0.0-partial-response-backport-20251204204441
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 +39 -149
- package/dist/agent/index.d.ts +3 -3
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/defaults.d.ts +783 -235
- package/dist/defaults.d.ts.map +1 -1
- package/dist/index.js +137 -163
- package/dist/index.js.map +1 -1
- package/dist/processors/tool-summary.d.ts +5 -10
- package/dist/processors/tool-summary.d.ts.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/utils.d.ts +4 -4
- package/dist/workflows/shared/schema.d.ts +2 -2
- package/dist/workflows/task-planning/schema.d.ts +12 -12
- package/dist/workflows/task-planning/task-planning.d.ts +23 -23
- package/dist/workflows/task-planning/task-planning.d.ts.map +1 -1
- package/dist/workflows/template-builder/template-builder.d.ts +21 -21
- package/dist/workflows/template-builder/template-builder.d.ts.map +1 -1
- package/dist/workflows/workflow-builder/prompts.d.ts +1 -1
- package/dist/workflows/workflow-builder/prompts.d.ts.map +1 -1
- package/dist/workflows/workflow-builder/schema.d.ts +14 -14
- package/dist/workflows/workflow-builder/tools.d.ts +83 -13
- package/dist/workflows/workflow-builder/tools.d.ts.map +1 -1
- package/dist/workflows/workflow-builder/workflow-builder.d.ts +52 -52
- package/dist/workflows/workflow-builder/workflow-builder.d.ts.map +1 -1
- package/package.json +16 -11
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Agent, tryGenerateWithJsonFallback, tryStreamWithJsonFallback } from '@mastra/core/agent';
|
|
2
2
|
import { Memory } from '@mastra/memory';
|
|
3
|
+
import { TokenLimiter } from '@mastra/memory/processors';
|
|
3
4
|
import { exec as exec$1, execFile as execFile$1, spawn as spawn$1 } from 'child_process';
|
|
4
5
|
import { mkdtemp, rm, readFile, writeFile, readdir, mkdir, copyFile, stat } from 'fs/promises';
|
|
5
6
|
import { join, resolve, basename, extname, dirname, isAbsolute, relative } from 'path';
|
|
@@ -10,6 +11,7 @@ import { existsSync, readFileSync } from 'fs';
|
|
|
10
11
|
import { createRequire } from 'module';
|
|
11
12
|
import { promisify } from 'util';
|
|
12
13
|
import { ModelRouterLanguageModel } from '@mastra/core/llm';
|
|
14
|
+
import { MemoryProcessor } from '@mastra/core/memory';
|
|
13
15
|
import { tmpdir } from 'os';
|
|
14
16
|
import { openai } from '@ai-sdk/openai';
|
|
15
17
|
import { createStep, createWorkflow } from '@mastra/core/workflows';
|
|
@@ -499,11 +501,11 @@ async function renameAndCopyFile(sourceFile, targetFile) {
|
|
|
499
501
|
var isValidMastraLanguageModel = (model) => {
|
|
500
502
|
return model && typeof model === "object" && typeof model.modelId === "string";
|
|
501
503
|
};
|
|
502
|
-
var resolveTargetPath = (inputData,
|
|
504
|
+
var resolveTargetPath = (inputData, runtimeContext) => {
|
|
503
505
|
if (inputData.targetPath) {
|
|
504
506
|
return inputData.targetPath;
|
|
505
507
|
}
|
|
506
|
-
const contextPath =
|
|
508
|
+
const contextPath = runtimeContext.get("targetPath");
|
|
507
509
|
if (contextPath) {
|
|
508
510
|
return contextPath;
|
|
509
511
|
}
|
|
@@ -672,13 +674,13 @@ var createModelInstance = async (provider, modelId, version = "v2") => {
|
|
|
672
674
|
}
|
|
673
675
|
};
|
|
674
676
|
var resolveModel = async ({
|
|
675
|
-
|
|
677
|
+
runtimeContext,
|
|
676
678
|
defaultModel = "openai/gpt-4.1",
|
|
677
679
|
projectPath
|
|
678
680
|
}) => {
|
|
679
|
-
const modelFromContext =
|
|
681
|
+
const modelFromContext = runtimeContext.get("model");
|
|
680
682
|
if (modelFromContext) {
|
|
681
|
-
console.info("Using model from
|
|
683
|
+
console.info("Using model from runtime context");
|
|
682
684
|
if (isValidMastraLanguageModel(modelFromContext)) {
|
|
683
685
|
return modelFromContext;
|
|
684
686
|
}
|
|
@@ -686,13 +688,13 @@ var resolveModel = async ({
|
|
|
686
688
|
'Invalid model provided. Model must be a MastraLanguageModel instance (e.g., openai("gpt-4"), anthropic("claude-3-5-sonnet"), etc.)'
|
|
687
689
|
);
|
|
688
690
|
}
|
|
689
|
-
const selectedModel =
|
|
691
|
+
const selectedModel = runtimeContext.get("selectedModel");
|
|
690
692
|
if (selectedModel?.provider && selectedModel?.modelId && projectPath) {
|
|
691
693
|
console.info(`Resolving selected model: ${selectedModel.provider}/${selectedModel.modelId}`);
|
|
692
694
|
const version = await detectAISDKVersion(projectPath);
|
|
693
695
|
const modelInstance = await createModelInstance(selectedModel.provider, selectedModel.modelId, version);
|
|
694
696
|
if (modelInstance) {
|
|
695
|
-
|
|
697
|
+
runtimeContext.set("model", modelInstance);
|
|
696
698
|
return modelInstance;
|
|
697
699
|
}
|
|
698
700
|
}
|
|
@@ -866,7 +868,7 @@ You have access to an enhanced set of tools based on production coding agent pat
|
|
|
866
868
|
### Task Management
|
|
867
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.
|
|
868
870
|
|
|
869
|
-
### Code Discovery & Analysis
|
|
871
|
+
### Code Discovery & Analysis
|
|
870
872
|
- **codeAnalyzer**: Analyze codebase structure, discover definitions (functions, classes, interfaces), map dependencies, and understand architectural patterns.
|
|
871
873
|
- **smartSearch**: Intelligent search with context awareness, pattern matching, and relevance scoring.
|
|
872
874
|
|
|
@@ -904,14 +906,12 @@ import { LibSQLStore } from '@mastra/libsql';
|
|
|
904
906
|
import { weatherTool } from '../tools/weather-tool';
|
|
905
907
|
|
|
906
908
|
export const weatherAgent = new Agent({
|
|
907
|
-
id: 'weather-agent',
|
|
908
909
|
name: 'Weather Agent',
|
|
909
910
|
instructions: \${instructions},
|
|
910
911
|
model: openai('gpt-4o-mini'),
|
|
911
912
|
tools: { weatherTool },
|
|
912
913
|
memory: new Memory({
|
|
913
914
|
storage: new LibSQLStore({
|
|
914
|
-
id: 'mastra-memory-storage',
|
|
915
915
|
url: 'file:../mastra.db', // ask user what database to use, use this as the default
|
|
916
916
|
}),
|
|
917
917
|
}),
|
|
@@ -940,8 +940,8 @@ export const weatherTool = createTool({
|
|
|
940
940
|
conditions: z.string(),
|
|
941
941
|
location: z.string(),
|
|
942
942
|
}),
|
|
943
|
-
execute: async (
|
|
944
|
-
return await getWeather(
|
|
943
|
+
execute: async ({ context }) => {
|
|
944
|
+
return await getWeather(context.location);
|
|
945
945
|
},
|
|
946
946
|
});
|
|
947
947
|
\`\`\`
|
|
@@ -959,7 +959,7 @@ const fetchWeather = createStep({
|
|
|
959
959
|
city: z.string().describe('The city to get the weather for'),
|
|
960
960
|
}),
|
|
961
961
|
outputSchema: forecastSchema,
|
|
962
|
-
execute: async (inputData) => {
|
|
962
|
+
execute: async ({ inputData }) => {
|
|
963
963
|
if (!inputData) {
|
|
964
964
|
throw new Error('Input data not found');
|
|
965
965
|
}
|
|
@@ -1013,8 +1013,7 @@ const planActivities = createStep({
|
|
|
1013
1013
|
outputSchema: z.object({
|
|
1014
1014
|
activities: z.string(),
|
|
1015
1015
|
}),
|
|
1016
|
-
execute: async (inputData,
|
|
1017
|
-
const mastra = context?.mastra;
|
|
1016
|
+
execute: async ({ inputData, mastra }) => {
|
|
1018
1017
|
const forecast = inputData;
|
|
1019
1018
|
|
|
1020
1019
|
if (!forecast) {
|
|
@@ -1079,8 +1078,7 @@ export const mastra = new Mastra({
|
|
|
1079
1078
|
workflows: { weatherWorkflow },
|
|
1080
1079
|
agents: { weatherAgent },
|
|
1081
1080
|
storage: new LibSQLStore({
|
|
1082
|
-
|
|
1083
|
-
// stores observability, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
1081
|
+
// stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
1084
1082
|
url: ":memory:",
|
|
1085
1083
|
}),
|
|
1086
1084
|
logger: new PinoLogger({
|
|
@@ -1124,8 +1122,8 @@ export const mastra = new Mastra({
|
|
|
1124
1122
|
}).optional(),
|
|
1125
1123
|
error: z.string().optional()
|
|
1126
1124
|
}),
|
|
1127
|
-
execute: async (
|
|
1128
|
-
return await _AgentBuilderDefaults.readFile({ ...
|
|
1125
|
+
execute: async ({ context }) => {
|
|
1126
|
+
return await _AgentBuilderDefaults.readFile({ ...context, projectPath });
|
|
1129
1127
|
}
|
|
1130
1128
|
}),
|
|
1131
1129
|
writeFile: createTool({
|
|
@@ -1144,8 +1142,8 @@ export const mastra = new Mastra({
|
|
|
1144
1142
|
message: z.string(),
|
|
1145
1143
|
error: z.string().optional()
|
|
1146
1144
|
}),
|
|
1147
|
-
execute: async (
|
|
1148
|
-
return await _AgentBuilderDefaults.writeFile({ ...
|
|
1145
|
+
execute: async ({ context }) => {
|
|
1146
|
+
return await _AgentBuilderDefaults.writeFile({ ...context, projectPath });
|
|
1149
1147
|
}
|
|
1150
1148
|
}),
|
|
1151
1149
|
listDirectory: createTool({
|
|
@@ -1176,8 +1174,8 @@ export const mastra = new Mastra({
|
|
|
1176
1174
|
message: z.string(),
|
|
1177
1175
|
error: z.string().optional()
|
|
1178
1176
|
}),
|
|
1179
|
-
execute: async (
|
|
1180
|
-
return await _AgentBuilderDefaults.listDirectory({ ...
|
|
1177
|
+
execute: async ({ context }) => {
|
|
1178
|
+
return await _AgentBuilderDefaults.listDirectory({ ...context, projectPath });
|
|
1181
1179
|
}
|
|
1182
1180
|
}),
|
|
1183
1181
|
executeCommand: createTool({
|
|
@@ -1201,10 +1199,10 @@ export const mastra = new Mastra({
|
|
|
1201
1199
|
executionTime: z.number().optional(),
|
|
1202
1200
|
error: z.string().optional()
|
|
1203
1201
|
}),
|
|
1204
|
-
execute: async (
|
|
1202
|
+
execute: async ({ context }) => {
|
|
1205
1203
|
return await _AgentBuilderDefaults.executeCommand({
|
|
1206
|
-
...
|
|
1207
|
-
workingDirectory:
|
|
1204
|
+
...context,
|
|
1205
|
+
workingDirectory: context.workingDirectory || projectPath
|
|
1208
1206
|
});
|
|
1209
1207
|
}
|
|
1210
1208
|
}),
|
|
@@ -1242,8 +1240,8 @@ export const mastra = new Mastra({
|
|
|
1242
1240
|
),
|
|
1243
1241
|
message: z.string()
|
|
1244
1242
|
}),
|
|
1245
|
-
execute: async (
|
|
1246
|
-
return await _AgentBuilderDefaults.manageTaskList(
|
|
1243
|
+
execute: async ({ context }) => {
|
|
1244
|
+
return await _AgentBuilderDefaults.manageTaskList(context);
|
|
1247
1245
|
}
|
|
1248
1246
|
}),
|
|
1249
1247
|
// Advanced File Operations
|
|
@@ -1277,8 +1275,8 @@ export const mastra = new Mastra({
|
|
|
1277
1275
|
),
|
|
1278
1276
|
message: z.string()
|
|
1279
1277
|
}),
|
|
1280
|
-
execute: async (
|
|
1281
|
-
return await _AgentBuilderDefaults.performMultiEdit({ ...
|
|
1278
|
+
execute: async ({ context }) => {
|
|
1279
|
+
return await _AgentBuilderDefaults.performMultiEdit({ ...context, projectPath });
|
|
1282
1280
|
}
|
|
1283
1281
|
}),
|
|
1284
1282
|
replaceLines: createTool({
|
|
@@ -1302,8 +1300,8 @@ export const mastra = new Mastra({
|
|
|
1302
1300
|
backup: z.string().optional(),
|
|
1303
1301
|
error: z.string().optional()
|
|
1304
1302
|
}),
|
|
1305
|
-
execute: async (
|
|
1306
|
-
return await _AgentBuilderDefaults.replaceLines({ ...
|
|
1303
|
+
execute: async ({ context }) => {
|
|
1304
|
+
return await _AgentBuilderDefaults.replaceLines({ ...context, projectPath });
|
|
1307
1305
|
}
|
|
1308
1306
|
}),
|
|
1309
1307
|
// File diagnostics tool to help debug line replacement issues
|
|
@@ -1331,8 +1329,8 @@ export const mastra = new Mastra({
|
|
|
1331
1329
|
message: z.string(),
|
|
1332
1330
|
error: z.string().optional()
|
|
1333
1331
|
}),
|
|
1334
|
-
execute: async (
|
|
1335
|
-
return await _AgentBuilderDefaults.showFileLines({ ...
|
|
1332
|
+
execute: async ({ context }) => {
|
|
1333
|
+
return await _AgentBuilderDefaults.showFileLines({ ...context, projectPath });
|
|
1336
1334
|
}
|
|
1337
1335
|
}),
|
|
1338
1336
|
// Enhanced Pattern Search
|
|
@@ -1375,8 +1373,8 @@ export const mastra = new Mastra({
|
|
|
1375
1373
|
patterns: z.array(z.string())
|
|
1376
1374
|
})
|
|
1377
1375
|
}),
|
|
1378
|
-
execute: async (
|
|
1379
|
-
return await _AgentBuilderDefaults.performSmartSearch(
|
|
1376
|
+
execute: async ({ context }) => {
|
|
1377
|
+
return await _AgentBuilderDefaults.performSmartSearch(context, projectPath);
|
|
1380
1378
|
}
|
|
1381
1379
|
}),
|
|
1382
1380
|
validateCode: createTool({
|
|
@@ -1409,8 +1407,8 @@ export const mastra = new Mastra({
|
|
|
1409
1407
|
validationsFailed: z.array(z.string())
|
|
1410
1408
|
})
|
|
1411
1409
|
}),
|
|
1412
|
-
execute: async (
|
|
1413
|
-
const { projectPath: validationProjectPath, validationType, files } =
|
|
1410
|
+
execute: async ({ context }) => {
|
|
1411
|
+
const { projectPath: validationProjectPath, validationType, files } = context;
|
|
1414
1412
|
const targetPath = validationProjectPath || projectPath;
|
|
1415
1413
|
return await _AgentBuilderDefaults.validateCode({
|
|
1416
1414
|
projectPath: targetPath,
|
|
@@ -1449,8 +1447,8 @@ export const mastra = new Mastra({
|
|
|
1449
1447
|
suggestions: z.array(z.string()).optional(),
|
|
1450
1448
|
error: z.string().optional()
|
|
1451
1449
|
}),
|
|
1452
|
-
execute: async (
|
|
1453
|
-
return await _AgentBuilderDefaults.webSearch(
|
|
1450
|
+
execute: async ({ context }) => {
|
|
1451
|
+
return await _AgentBuilderDefaults.webSearch(context);
|
|
1454
1452
|
}
|
|
1455
1453
|
}),
|
|
1456
1454
|
// Task Completion Signaling
|
|
@@ -1479,8 +1477,8 @@ export const mastra = new Mastra({
|
|
|
1479
1477
|
summary: z.string(),
|
|
1480
1478
|
confidence: z.number().min(0).max(100)
|
|
1481
1479
|
}),
|
|
1482
|
-
execute: async (
|
|
1483
|
-
return await _AgentBuilderDefaults.signalCompletion(
|
|
1480
|
+
execute: async ({ context }) => {
|
|
1481
|
+
return await _AgentBuilderDefaults.signalCompletion(context);
|
|
1484
1482
|
}
|
|
1485
1483
|
}),
|
|
1486
1484
|
manageProject: createTool({
|
|
@@ -1505,8 +1503,8 @@ export const mastra = new Mastra({
|
|
|
1505
1503
|
details: z.string().optional(),
|
|
1506
1504
|
error: z.string().optional()
|
|
1507
1505
|
}),
|
|
1508
|
-
execute: async (
|
|
1509
|
-
const { action, features, packages } =
|
|
1506
|
+
execute: async ({ context }) => {
|
|
1507
|
+
const { action, features, packages } = context;
|
|
1510
1508
|
try {
|
|
1511
1509
|
switch (action) {
|
|
1512
1510
|
case "create":
|
|
@@ -1567,8 +1565,8 @@ export const mastra = new Mastra({
|
|
|
1567
1565
|
stdout: z.array(z.string()).optional().describe("Server output lines captured during startup"),
|
|
1568
1566
|
error: z.string().optional()
|
|
1569
1567
|
}),
|
|
1570
|
-
execute: async (
|
|
1571
|
-
const { action, port } =
|
|
1568
|
+
execute: async ({ context }) => {
|
|
1569
|
+
const { action, port } = context;
|
|
1572
1570
|
try {
|
|
1573
1571
|
switch (action) {
|
|
1574
1572
|
case "start":
|
|
@@ -1653,8 +1651,8 @@ export const mastra = new Mastra({
|
|
|
1653
1651
|
url: z.string(),
|
|
1654
1652
|
method: z.string()
|
|
1655
1653
|
}),
|
|
1656
|
-
execute: async (
|
|
1657
|
-
const { method, url, baseUrl, headers, body, timeout } =
|
|
1654
|
+
execute: async ({ context }) => {
|
|
1655
|
+
const { method, url, baseUrl, headers, body, timeout } = context;
|
|
1658
1656
|
try {
|
|
1659
1657
|
return await _AgentBuilderDefaults.makeHttpRequest({
|
|
1660
1658
|
method,
|
|
@@ -1709,7 +1707,7 @@ export const mastra = new Mastra({
|
|
|
1709
1707
|
/**
|
|
1710
1708
|
* Get tools for a specific mode
|
|
1711
1709
|
*/
|
|
1712
|
-
static async
|
|
1710
|
+
static async getToolsForMode(projectPath, mode = "code-editor") {
|
|
1713
1711
|
const allTools = await _AgentBuilderDefaults.DEFAULT_TOOLS(projectPath);
|
|
1714
1712
|
if (mode === "template") {
|
|
1715
1713
|
return _AgentBuilderDefaults.filterToolsForTemplateBuilder(allTools);
|
|
@@ -3082,15 +3080,13 @@ export const mastra = new Mastra({
|
|
|
3082
3080
|
}
|
|
3083
3081
|
}
|
|
3084
3082
|
};
|
|
3085
|
-
var ToolSummaryProcessor = class {
|
|
3086
|
-
id = "tool-summary-processor";
|
|
3087
|
-
name = "ToolSummaryProcessor";
|
|
3083
|
+
var ToolSummaryProcessor = class extends MemoryProcessor {
|
|
3088
3084
|
summaryAgent;
|
|
3089
3085
|
summaryCache = /* @__PURE__ */ new Map();
|
|
3090
3086
|
constructor({ summaryModel }) {
|
|
3087
|
+
super({ name: "ToolSummaryProcessor" });
|
|
3091
3088
|
this.summaryAgent = new Agent({
|
|
3092
|
-
|
|
3093
|
-
name: "Tool Summary Agent",
|
|
3089
|
+
name: "ToolSummaryAgent",
|
|
3094
3090
|
description: "A summary agent that summarizes tool calls and results",
|
|
3095
3091
|
instructions: "You are a summary agent that summarizes tool calls and results",
|
|
3096
3092
|
model: summaryModel
|
|
@@ -3124,37 +3120,30 @@ var ToolSummaryProcessor = class {
|
|
|
3124
3120
|
keys: Array.from(this.summaryCache.keys())
|
|
3125
3121
|
};
|
|
3126
3122
|
}
|
|
3127
|
-
async
|
|
3128
|
-
messages,
|
|
3129
|
-
messageList: _messageList
|
|
3130
|
-
}) {
|
|
3123
|
+
async process(messages) {
|
|
3131
3124
|
const summaryTasks = [];
|
|
3132
3125
|
for (const message of messages) {
|
|
3133
|
-
if (message.content.
|
|
3134
|
-
for (
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3126
|
+
if (message.role === "tool" && Array.isArray(message.content) && message.content.length > 0 && message.content?.some((content) => content.type === "tool-result")) {
|
|
3127
|
+
for (const content of message.content) {
|
|
3128
|
+
if (content.type === "tool-result") {
|
|
3129
|
+
const assistantMessageWithToolCall = messages.find(
|
|
3130
|
+
(message2) => message2.role === "assistant" && Array.isArray(message2.content) && message2.content.length > 0 && message2.content?.some(
|
|
3131
|
+
(assistantContent) => assistantContent.type === "tool-call" && assistantContent.toolCallId === content.toolCallId
|
|
3132
|
+
)
|
|
3133
|
+
);
|
|
3134
|
+
const toolCall = Array.isArray(assistantMessageWithToolCall?.content) ? assistantMessageWithToolCall?.content.find(
|
|
3135
|
+
(assistantContent) => assistantContent.type === "tool-call" && assistantContent.toolCallId === content.toolCallId
|
|
3136
|
+
) : null;
|
|
3137
|
+
const cacheKey = this.createCacheKey(toolCall);
|
|
3138
3138
|
const cachedSummary = this.summaryCache.get(cacheKey);
|
|
3139
3139
|
if (cachedSummary) {
|
|
3140
|
-
|
|
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
|
-
};
|
|
3140
|
+
content.result = `Tool call summary: ${cachedSummary}`;
|
|
3151
3141
|
} else {
|
|
3152
3142
|
const summaryPromise = this.summaryAgent.generate(
|
|
3153
|
-
`Summarize the following tool call: ${JSON.stringify(
|
|
3143
|
+
`Summarize the following tool call: ${JSON.stringify(toolCall)} and result: ${JSON.stringify(content)}`
|
|
3154
3144
|
);
|
|
3155
3145
|
summaryTasks.push({
|
|
3156
|
-
|
|
3157
|
-
partIndex,
|
|
3146
|
+
content,
|
|
3158
3147
|
promise: summaryPromise,
|
|
3159
3148
|
cacheKey
|
|
3160
3149
|
});
|
|
@@ -3172,24 +3161,10 @@ var ToolSummaryProcessor = class {
|
|
|
3172
3161
|
const summaryResult = result.value;
|
|
3173
3162
|
const summaryText = summaryResult.text;
|
|
3174
3163
|
this.summaryCache.set(task.cacheKey, summaryText);
|
|
3175
|
-
|
|
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
|
-
}
|
|
3164
|
+
task.content.result = `Tool call summary: ${summaryText}`;
|
|
3191
3165
|
} else if (result.status === "rejected") {
|
|
3192
3166
|
console.warn(`Failed to generate summary for tool call:`, result.reason);
|
|
3167
|
+
task.content.result = `Tool call summary: [Summary generation failed]`;
|
|
3193
3168
|
}
|
|
3194
3169
|
});
|
|
3195
3170
|
}
|
|
@@ -3209,26 +3184,26 @@ var AgentBuilder = class extends Agent {
|
|
|
3209
3184
|
${config.instructions}` : "";
|
|
3210
3185
|
const combinedInstructions = additionalInstructions + AgentBuilderDefaults.DEFAULT_INSTRUCTIONS(config.projectPath);
|
|
3211
3186
|
const agentConfig = {
|
|
3212
|
-
id: "agent-builder",
|
|
3213
3187
|
name: "agent-builder",
|
|
3214
3188
|
description: "An AI agent specialized in generating Mastra agents, tools, and workflows from natural language requirements.",
|
|
3215
3189
|
instructions: combinedInstructions,
|
|
3216
3190
|
model: config.model,
|
|
3217
3191
|
tools: async () => {
|
|
3218
3192
|
return {
|
|
3219
|
-
...await AgentBuilderDefaults.
|
|
3193
|
+
...await AgentBuilderDefaults.getToolsForMode(config.projectPath, config.mode),
|
|
3220
3194
|
...config.tools || {}
|
|
3221
3195
|
};
|
|
3222
3196
|
},
|
|
3223
3197
|
memory: new Memory({
|
|
3224
|
-
options: AgentBuilderDefaults.DEFAULT_MEMORY_CONFIG
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3198
|
+
options: AgentBuilderDefaults.DEFAULT_MEMORY_CONFIG,
|
|
3199
|
+
processors: [
|
|
3200
|
+
// use the write to disk processor to debug the agent's context
|
|
3201
|
+
// new WriteToDiskProcessor({ prefix: 'before-filter' }),
|
|
3202
|
+
new ToolSummaryProcessor({ summaryModel: config.summaryModel || config.model }),
|
|
3203
|
+
new TokenLimiter(1e5)
|
|
3204
|
+
// new WriteToDiskProcessor({ prefix: 'after-filter' }),
|
|
3205
|
+
]
|
|
3206
|
+
})
|
|
3232
3207
|
};
|
|
3233
3208
|
super(agentConfig);
|
|
3234
3209
|
this.builderConfig = config;
|
|
@@ -3239,7 +3214,7 @@ ${config.instructions}` : "";
|
|
|
3239
3214
|
*/
|
|
3240
3215
|
generateLegacy = async (messages, generateOptions = {}) => {
|
|
3241
3216
|
const { maxSteps, ...baseOptions } = generateOptions;
|
|
3242
|
-
const originalInstructions = await this.getInstructions({
|
|
3217
|
+
const originalInstructions = await this.getInstructions({ runtimeContext: generateOptions?.runtimeContext });
|
|
3243
3218
|
const additionalInstructions = baseOptions.instructions;
|
|
3244
3219
|
let enhancedInstructions = originalInstructions;
|
|
3245
3220
|
if (additionalInstructions) {
|
|
@@ -3268,7 +3243,7 @@ ${additionalInstructions}`;
|
|
|
3268
3243
|
*/
|
|
3269
3244
|
streamLegacy = async (messages, streamOptions = {}) => {
|
|
3270
3245
|
const { maxSteps, ...baseOptions } = streamOptions;
|
|
3271
|
-
const originalInstructions = await this.getInstructions({
|
|
3246
|
+
const originalInstructions = await this.getInstructions({ runtimeContext: streamOptions?.runtimeContext });
|
|
3272
3247
|
const additionalInstructions = baseOptions.instructions;
|
|
3273
3248
|
let enhancedInstructions = originalInstructions;
|
|
3274
3249
|
if (additionalInstructions) {
|
|
@@ -3297,7 +3272,7 @@ ${additionalInstructions}`;
|
|
|
3297
3272
|
*/
|
|
3298
3273
|
async stream(messages, streamOptions) {
|
|
3299
3274
|
const { ...baseOptions } = streamOptions || {};
|
|
3300
|
-
const originalInstructions = await this.getInstructions({
|
|
3275
|
+
const originalInstructions = await this.getInstructions({ runtimeContext: streamOptions?.runtimeContext });
|
|
3301
3276
|
const additionalInstructions = baseOptions.instructions;
|
|
3302
3277
|
let enhancedInstructions = originalInstructions;
|
|
3303
3278
|
if (additionalInstructions) {
|
|
@@ -3321,7 +3296,7 @@ ${additionalInstructions}`;
|
|
|
3321
3296
|
}
|
|
3322
3297
|
async generate(messages, options) {
|
|
3323
3298
|
const { ...baseOptions } = options || {};
|
|
3324
|
-
const originalInstructions = await this.getInstructions({
|
|
3299
|
+
const originalInstructions = await this.getInstructions({ runtimeContext: options?.runtimeContext });
|
|
3325
3300
|
const additionalInstructions = baseOptions.instructions;
|
|
3326
3301
|
let enhancedInstructions = originalInstructions;
|
|
3327
3302
|
if (additionalInstructions) {
|
|
@@ -3429,15 +3404,14 @@ var discoverUnitsStep = createStep({
|
|
|
3429
3404
|
description: "Discover template units by analyzing the templates directory structure",
|
|
3430
3405
|
inputSchema: CloneTemplateResultSchema,
|
|
3431
3406
|
outputSchema: DiscoveryResultSchema,
|
|
3432
|
-
execute: async ({ inputData,
|
|
3407
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
3433
3408
|
const { templateDir } = inputData;
|
|
3434
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3409
|
+
const targetPath = resolveTargetPath(inputData, runtimeContext);
|
|
3435
3410
|
const tools = await AgentBuilderDefaults.DEFAULT_TOOLS(templateDir);
|
|
3436
3411
|
console.info("targetPath", targetPath);
|
|
3437
|
-
const model = await resolveModel({
|
|
3412
|
+
const model = await resolveModel({ runtimeContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
3438
3413
|
try {
|
|
3439
3414
|
const agent = new Agent({
|
|
3440
|
-
id: "mastra-project-discoverer",
|
|
3441
3415
|
model,
|
|
3442
3416
|
instructions: `You are an expert at analyzing Mastra projects.
|
|
3443
3417
|
|
|
@@ -3574,8 +3548,8 @@ var prepareBranchStep = createStep({
|
|
|
3574
3548
|
description: "Create or switch to integration branch before modifications",
|
|
3575
3549
|
inputSchema: PrepareBranchInputSchema,
|
|
3576
3550
|
outputSchema: PrepareBranchResultSchema,
|
|
3577
|
-
execute: async ({ inputData,
|
|
3578
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3551
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
3552
|
+
const targetPath = resolveTargetPath(inputData, runtimeContext);
|
|
3579
3553
|
try {
|
|
3580
3554
|
const branchName = `feat/install-template-${inputData.slug}`;
|
|
3581
3555
|
await gitCheckoutBranch(branchName, targetPath);
|
|
@@ -3599,10 +3573,10 @@ var packageMergeStep = createStep({
|
|
|
3599
3573
|
description: "Merge template package.json dependencies into target project",
|
|
3600
3574
|
inputSchema: PackageMergeInputSchema,
|
|
3601
3575
|
outputSchema: PackageMergeResultSchema,
|
|
3602
|
-
execute: async ({ inputData,
|
|
3576
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
3603
3577
|
console.info("Package merge step starting...");
|
|
3604
3578
|
const { slug, packageInfo } = inputData;
|
|
3605
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3579
|
+
const targetPath = resolveTargetPath(inputData, runtimeContext);
|
|
3606
3580
|
try {
|
|
3607
3581
|
const targetPkgPath = join(targetPath, "package.json");
|
|
3608
3582
|
let targetPkgRaw = "{}";
|
|
@@ -3676,9 +3650,9 @@ var installStep = createStep({
|
|
|
3676
3650
|
description: "Install packages based on merged package.json",
|
|
3677
3651
|
inputSchema: InstallInputSchema,
|
|
3678
3652
|
outputSchema: InstallResultSchema,
|
|
3679
|
-
execute: async ({ inputData,
|
|
3653
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
3680
3654
|
console.info("Running install step...");
|
|
3681
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3655
|
+
const targetPath = resolveTargetPath(inputData, runtimeContext);
|
|
3682
3656
|
try {
|
|
3683
3657
|
await spawnSWPM(targetPath, "install", []);
|
|
3684
3658
|
const lock = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock"].map((f) => join(targetPath, f)).find((f) => existsSync(f));
|
|
@@ -3704,10 +3678,10 @@ var programmaticFileCopyStep = createStep({
|
|
|
3704
3678
|
description: "Programmatically copy template files to target project based on ordered units",
|
|
3705
3679
|
inputSchema: FileCopyInputSchema,
|
|
3706
3680
|
outputSchema: FileCopyResultSchema,
|
|
3707
|
-
execute: async ({ inputData,
|
|
3681
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
3708
3682
|
console.info("Programmatic file copy step starting...");
|
|
3709
3683
|
const { orderedUnits, templateDir, commitSha, slug } = inputData;
|
|
3710
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3684
|
+
const targetPath = resolveTargetPath(inputData, runtimeContext);
|
|
3711
3685
|
try {
|
|
3712
3686
|
const copiedFiles = [];
|
|
3713
3687
|
const conflicts = [];
|
|
@@ -4056,12 +4030,12 @@ var intelligentMergeStep = createStep({
|
|
|
4056
4030
|
description: "Use AgentBuilder to intelligently merge template files",
|
|
4057
4031
|
inputSchema: IntelligentMergeInputSchema,
|
|
4058
4032
|
outputSchema: IntelligentMergeResultSchema,
|
|
4059
|
-
execute: async ({ inputData,
|
|
4033
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
4060
4034
|
console.info("Intelligent merge step starting...");
|
|
4061
4035
|
const { conflicts, copiedFiles, commitSha, slug, templateDir, branchName } = inputData;
|
|
4062
|
-
const targetPath = resolveTargetPath(inputData,
|
|
4036
|
+
const targetPath = resolveTargetPath(inputData, runtimeContext);
|
|
4063
4037
|
try {
|
|
4064
|
-
const model = await resolveModel({
|
|
4038
|
+
const model = await resolveModel({ runtimeContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
4065
4039
|
const copyFileTool = createTool({
|
|
4066
4040
|
id: "copy-file",
|
|
4067
4041
|
description: "Copy a file from template to target project (use only for edge cases - most files are already copied programmatically).",
|
|
@@ -4074,9 +4048,9 @@ var intelligentMergeStep = createStep({
|
|
|
4074
4048
|
message: z.string(),
|
|
4075
4049
|
error: z.string().optional()
|
|
4076
4050
|
}),
|
|
4077
|
-
execute: async (
|
|
4051
|
+
execute: async ({ context }) => {
|
|
4078
4052
|
try {
|
|
4079
|
-
const { sourcePath, destinationPath } =
|
|
4053
|
+
const { sourcePath, destinationPath } = context;
|
|
4080
4054
|
const resolvedSourcePath = resolve(templateDir, sourcePath);
|
|
4081
4055
|
const resolvedDestinationPath = resolve(targetPath, destinationPath);
|
|
4082
4056
|
if (existsSync(resolvedSourcePath) && !existsSync(dirname(resolvedDestinationPath))) {
|
|
@@ -4324,10 +4298,10 @@ var validationAndFixStep = createStep({
|
|
|
4324
4298
|
description: "Validate the merged template code and fix any issues using a specialized agent",
|
|
4325
4299
|
inputSchema: ValidationFixInputSchema,
|
|
4326
4300
|
outputSchema: ValidationFixResultSchema,
|
|
4327
|
-
execute: async ({ inputData,
|
|
4301
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
4328
4302
|
console.info("Validation and fix step starting...");
|
|
4329
4303
|
const { commitSha, slug, orderedUnits, templateDir, copiedFiles, conflictsResolved, maxIterations = 5 } = inputData;
|
|
4330
|
-
const targetPath = resolveTargetPath(inputData,
|
|
4304
|
+
const targetPath = resolveTargetPath(inputData, runtimeContext);
|
|
4331
4305
|
const hasChanges = copiedFiles.length > 0 || conflictsResolved && conflictsResolved.length > 0;
|
|
4332
4306
|
if (!hasChanges) {
|
|
4333
4307
|
console.info("\u23ED\uFE0F Skipping validation - no files copied or conflicts resolved");
|
|
@@ -4347,11 +4321,10 @@ var validationAndFixStep = createStep({
|
|
|
4347
4321
|
);
|
|
4348
4322
|
let currentIteration = 1;
|
|
4349
4323
|
try {
|
|
4350
|
-
const model = await resolveModel({
|
|
4351
|
-
const allTools = await AgentBuilderDefaults.
|
|
4324
|
+
const model = await resolveModel({ runtimeContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
4325
|
+
const allTools = await AgentBuilderDefaults.getToolsForMode(targetPath, "template");
|
|
4352
4326
|
const validationAgent = new Agent({
|
|
4353
|
-
|
|
4354
|
-
name: "Code Validator Fixer",
|
|
4327
|
+
name: "code-validator-fixer",
|
|
4355
4328
|
description: "Specialized agent for validating and fixing template integration issues",
|
|
4356
4329
|
instructions: `You are a code validation and fixing specialist. Your job is to:
|
|
4357
4330
|
|
|
@@ -4754,7 +4727,7 @@ var agentBuilderTemplateWorkflow = createWorkflow({
|
|
|
4754
4727
|
}).commit();
|
|
4755
4728
|
async function mergeTemplateBySlug(slug, targetPath) {
|
|
4756
4729
|
const template = await getMastraTemplate(slug);
|
|
4757
|
-
const run = await agentBuilderTemplateWorkflow.
|
|
4730
|
+
const run = await agentBuilderTemplateWorkflow.createRunAsync();
|
|
4758
4731
|
return await run.start({
|
|
4759
4732
|
inputData: {
|
|
4760
4733
|
repo: template.githubUrl,
|
|
@@ -5061,7 +5034,7 @@ var planningIterationStep = createStep({
|
|
|
5061
5034
|
outputSchema: PlanningIterationResultSchema,
|
|
5062
5035
|
suspendSchema: PlanningIterationSuspendSchema,
|
|
5063
5036
|
resumeSchema: PlanningIterationResumeSchema,
|
|
5064
|
-
execute: async ({ inputData, resumeData, suspend,
|
|
5037
|
+
execute: async ({ inputData, resumeData, suspend, runtimeContext }) => {
|
|
5065
5038
|
const {
|
|
5066
5039
|
action,
|
|
5067
5040
|
workflowName,
|
|
@@ -5074,7 +5047,7 @@ var planningIterationStep = createStep({
|
|
|
5074
5047
|
} = inputData;
|
|
5075
5048
|
console.info("Starting planning iteration...");
|
|
5076
5049
|
const qaKey = "workflow-builder-qa";
|
|
5077
|
-
let storedQAPairs =
|
|
5050
|
+
let storedQAPairs = runtimeContext.get(qaKey) || [];
|
|
5078
5051
|
const newAnswers = { ...userAnswers || {}, ...resumeData?.answers || {} };
|
|
5079
5052
|
if (Object.keys(newAnswers).length > 0) {
|
|
5080
5053
|
storedQAPairs = storedQAPairs.map((pair) => {
|
|
@@ -5087,12 +5060,11 @@ var planningIterationStep = createStep({
|
|
|
5087
5060
|
}
|
|
5088
5061
|
return pair;
|
|
5089
5062
|
});
|
|
5090
|
-
|
|
5063
|
+
runtimeContext.set(qaKey, storedQAPairs);
|
|
5091
5064
|
}
|
|
5092
5065
|
try {
|
|
5093
|
-
const model = await resolveModel({
|
|
5066
|
+
const model = await resolveModel({ runtimeContext });
|
|
5094
5067
|
const planningAgent = new Agent({
|
|
5095
|
-
id: "workflow-planning-agent",
|
|
5096
5068
|
model,
|
|
5097
5069
|
instructions: taskPlanningPrompts.planningAgent.instructions({
|
|
5098
5070
|
storedQAPairs
|
|
@@ -5122,9 +5094,7 @@ var planningIterationStep = createStep({
|
|
|
5122
5094
|
research
|
|
5123
5095
|
});
|
|
5124
5096
|
const result = await planningAgent.generate(planningPrompt, {
|
|
5125
|
-
|
|
5126
|
-
schema: PlanningAgentOutputSchema
|
|
5127
|
-
}
|
|
5097
|
+
output: PlanningAgentOutputSchema
|
|
5128
5098
|
// maxSteps: 15,
|
|
5129
5099
|
});
|
|
5130
5100
|
const planResult = await result.object;
|
|
@@ -5148,7 +5118,7 @@ var planningIterationStep = createStep({
|
|
|
5148
5118
|
answeredAt: null
|
|
5149
5119
|
}));
|
|
5150
5120
|
storedQAPairs = [...storedQAPairs, ...newQAPairs];
|
|
5151
|
-
|
|
5121
|
+
runtimeContext.set(qaKey, storedQAPairs);
|
|
5152
5122
|
console.info(
|
|
5153
5123
|
`Updated Q&A state: ${storedQAPairs.length} total question-answer pairs, ${storedQAPairs.filter((p) => p.answer).length} answered`
|
|
5154
5124
|
);
|
|
@@ -5162,7 +5132,7 @@ var planningIterationStep = createStep({
|
|
|
5162
5132
|
});
|
|
5163
5133
|
}
|
|
5164
5134
|
console.info(`Planning complete with ${planResult.tasks.length} tasks`);
|
|
5165
|
-
|
|
5135
|
+
runtimeContext.set(qaKey, storedQAPairs);
|
|
5166
5136
|
console.info(
|
|
5167
5137
|
`Final Q&A state: ${storedQAPairs.length} total question-answer pairs, ${storedQAPairs.filter((p) => p.answer).length} answered`
|
|
5168
5138
|
);
|
|
@@ -5307,7 +5277,7 @@ const myStep = createStep({
|
|
|
5307
5277
|
- \`mastra\`: Access to Mastra instance (agents, tools, other workflows)
|
|
5308
5278
|
- \`getStepResult(stepInstance)\`: Get results from previous steps
|
|
5309
5279
|
- \`getInitData()\`: Access original workflow input data
|
|
5310
|
-
- \`
|
|
5280
|
+
- \`runtimeContext\`: Runtime dependency injection context
|
|
5311
5281
|
- \`runCount\`: Number of times this step has run (useful for retries)
|
|
5312
5282
|
|
|
5313
5283
|
### **\u{1F504} CONTROL FLOW METHODS**
|
|
@@ -5386,10 +5356,10 @@ const toolStep = createStep(myTool);
|
|
|
5386
5356
|
|
|
5387
5357
|
// Method 2: Call tool in execute function
|
|
5388
5358
|
const step = createStep({
|
|
5389
|
-
execute: async ({ inputData,
|
|
5359
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
5390
5360
|
const result = await myTool.execute({
|
|
5391
5361
|
context: inputData,
|
|
5392
|
-
|
|
5362
|
+
runtimeContext
|
|
5393
5363
|
});
|
|
5394
5364
|
return result;
|
|
5395
5365
|
}
|
|
@@ -5433,7 +5403,7 @@ export const mastra = new Mastra({
|
|
|
5433
5403
|
sendEmailWorkflow, // Use camelCase for keys
|
|
5434
5404
|
dataProcessingWorkflow
|
|
5435
5405
|
},
|
|
5436
|
-
storage: new LibSQLStore({
|
|
5406
|
+
storage: new LibSQLStore({ url: 'file:./mastra.db' }), // Required for suspend/resume
|
|
5437
5407
|
});
|
|
5438
5408
|
\`\`\`
|
|
5439
5409
|
|
|
@@ -5481,7 +5451,7 @@ export const mastra = new Mastra({
|
|
|
5481
5451
|
**Running Workflows:**
|
|
5482
5452
|
\`\`\`typescript
|
|
5483
5453
|
// Create and start run
|
|
5484
|
-
const run = await workflow.
|
|
5454
|
+
const run = await workflow.createRunAsync();
|
|
5485
5455
|
const result = await run.start({ inputData: {...} });
|
|
5486
5456
|
|
|
5487
5457
|
// Stream execution for real-time monitoring
|
|
@@ -5505,7 +5475,7 @@ run.watch((event) => console.log(event));
|
|
|
5505
5475
|
- Use workflows as steps: \`.then(otherWorkflow)\`
|
|
5506
5476
|
- Enable complex workflow composition
|
|
5507
5477
|
|
|
5508
|
-
**
|
|
5478
|
+
**Runtime Context:**
|
|
5509
5479
|
- Pass shared data across all steps
|
|
5510
5480
|
- Enable dependency injection patterns
|
|
5511
5481
|
|
|
@@ -5678,11 +5648,11 @@ var restrictedTaskManager = createTool({
|
|
|
5678
5648
|
),
|
|
5679
5649
|
message: z.string()
|
|
5680
5650
|
}),
|
|
5681
|
-
execute: async (
|
|
5651
|
+
execute: async ({ context }) => {
|
|
5682
5652
|
const adaptedContext = {
|
|
5683
|
-
...
|
|
5684
|
-
action:
|
|
5685
|
-
tasks:
|
|
5653
|
+
...context,
|
|
5654
|
+
action: context.action,
|
|
5655
|
+
tasks: context.tasks?.map((task) => ({
|
|
5686
5656
|
...task,
|
|
5687
5657
|
priority: task.priority || "medium"
|
|
5688
5658
|
}))
|
|
@@ -5697,7 +5667,7 @@ var workflowDiscoveryStep = createStep({
|
|
|
5697
5667
|
description: "Discover existing workflows in the project",
|
|
5698
5668
|
inputSchema: WorkflowBuilderInputSchema,
|
|
5699
5669
|
outputSchema: WorkflowDiscoveryResultSchema,
|
|
5700
|
-
execute: async ({ inputData,
|
|
5670
|
+
execute: async ({ inputData, runtimeContext: _runtimeContext }) => {
|
|
5701
5671
|
console.info("Starting workflow discovery...");
|
|
5702
5672
|
const { projectPath = process.cwd() } = inputData;
|
|
5703
5673
|
try {
|
|
@@ -5756,7 +5726,7 @@ var projectDiscoveryStep = createStep({
|
|
|
5756
5726
|
description: "Analyze the project structure and setup",
|
|
5757
5727
|
inputSchema: WorkflowDiscoveryResultSchema,
|
|
5758
5728
|
outputSchema: ProjectDiscoveryResultSchema,
|
|
5759
|
-
execute: async ({ inputData: _inputData,
|
|
5729
|
+
execute: async ({ inputData: _inputData, runtimeContext: _runtimeContext }) => {
|
|
5760
5730
|
console.info("Starting project discovery...");
|
|
5761
5731
|
try {
|
|
5762
5732
|
const projectPath = process.cwd();
|
|
@@ -5818,12 +5788,11 @@ var workflowResearchStep = createStep({
|
|
|
5818
5788
|
description: "Research Mastra workflows and gather relevant documentation",
|
|
5819
5789
|
inputSchema: ProjectDiscoveryResultSchema,
|
|
5820
5790
|
outputSchema: WorkflowResearchResultSchema,
|
|
5821
|
-
execute: async ({ inputData,
|
|
5791
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
5822
5792
|
console.info("Starting workflow research...");
|
|
5823
5793
|
try {
|
|
5824
|
-
const model = await resolveModel({
|
|
5794
|
+
const model = await resolveModel({ runtimeContext });
|
|
5825
5795
|
const researchAgent = new Agent({
|
|
5826
|
-
id: "workflow-research-agent",
|
|
5827
5796
|
model,
|
|
5828
5797
|
instructions: workflowBuilderPrompts.researchAgent.instructions,
|
|
5829
5798
|
name: "Workflow Research Agent"
|
|
@@ -5835,9 +5804,7 @@ var workflowResearchStep = createStep({
|
|
|
5835
5804
|
hasWorkflowsDir: inputData.structure.hasWorkflowsDir
|
|
5836
5805
|
});
|
|
5837
5806
|
const result = await researchAgent.generate(researchPrompt, {
|
|
5838
|
-
|
|
5839
|
-
schema: WorkflowResearchResultSchema
|
|
5840
|
-
}
|
|
5807
|
+
output: WorkflowResearchResultSchema
|
|
5841
5808
|
// stopWhen: stepCountIs(10),
|
|
5842
5809
|
});
|
|
5843
5810
|
const researchResult = await result.object;
|
|
@@ -5888,7 +5855,7 @@ var taskExecutionStep = createStep({
|
|
|
5888
5855
|
outputSchema: TaskExecutionResultSchema,
|
|
5889
5856
|
suspendSchema: TaskExecutionSuspendSchema,
|
|
5890
5857
|
resumeSchema: TaskExecutionResumeSchema,
|
|
5891
|
-
execute: async ({ inputData, resumeData, suspend,
|
|
5858
|
+
execute: async ({ inputData, resumeData, suspend, runtimeContext }) => {
|
|
5892
5859
|
const {
|
|
5893
5860
|
action,
|
|
5894
5861
|
workflowName,
|
|
@@ -5903,7 +5870,7 @@ var taskExecutionStep = createStep({
|
|
|
5903
5870
|
console.info(`Starting task execution for ${action}ing workflow: ${workflowName}`);
|
|
5904
5871
|
console.info(`Executing ${tasks.length} tasks using AgentBuilder stream...`);
|
|
5905
5872
|
try {
|
|
5906
|
-
const model = await resolveModel({
|
|
5873
|
+
const model = await resolveModel({ runtimeContext });
|
|
5907
5874
|
const currentProjectPath = projectPath || process.cwd();
|
|
5908
5875
|
console.info("Pre-populating taskManager with planned tasks...");
|
|
5909
5876
|
const taskManagerContext = {
|
|
@@ -5948,11 +5915,18 @@ ${workflowBuilderPrompts.validation.instructions}`
|
|
|
5948
5915
|
tasks,
|
|
5949
5916
|
resumeData
|
|
5950
5917
|
});
|
|
5951
|
-
const originalInstructions = await executionAgent.getInstructions({
|
|
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
|
+
}
|
|
5952
5926
|
const enhancedOptions = {
|
|
5953
5927
|
stopWhen: stepCountIs(100),
|
|
5954
5928
|
temperature: 0.3,
|
|
5955
|
-
instructions:
|
|
5929
|
+
instructions: enhancedInstructions
|
|
5956
5930
|
};
|
|
5957
5931
|
let finalResult = null;
|
|
5958
5932
|
let allTasksCompleted = false;
|