@mastra/agent-builder 0.0.0-vector-extension-schema-20250922130418 → 0.0.0-vnext-20251104230439
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 +259 -4
- package/dist/agent/index.d.ts +5 -5
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/defaults.d.ts +87 -1685
- package/dist/defaults.d.ts.map +1 -1
- package/dist/index.js +134 -150
- package/dist/index.js.map +1 -1
- package/dist/processors/tool-summary.d.ts.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/utils.d.ts +5 -5
- package/dist/utils.d.ts.map +1 -1
- package/dist/workflows/shared/schema.d.ts +2 -2
- package/dist/workflows/task-planning/schema.d.ts +10 -10
- package/dist/workflows/task-planning/task-planning.d.ts +31 -19
- package/dist/workflows/task-planning/task-planning.d.ts.map +1 -1
- package/dist/workflows/template-builder/template-builder.d.ts +101 -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 +16 -16
- package/dist/workflows/workflow-builder/tools.d.ts +3 -179
- package/dist/workflows/workflow-builder/tools.d.ts.map +1 -1
- package/dist/workflows/workflow-builder/workflow-builder.d.ts +84 -52
- package/dist/workflows/workflow-builder/workflow-builder.d.ts.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Agent } from '@mastra/core/agent';
|
|
1
|
+
import { Agent, tryGenerateWithJsonFallback, tryStreamWithJsonFallback } from '@mastra/core/agent';
|
|
2
2
|
import { Memory } from '@mastra/memory';
|
|
3
3
|
import { TokenLimiter } from '@mastra/memory/processors';
|
|
4
4
|
import { exec as exec$1, execFile as execFile$1, spawn as spawn$1 } from 'child_process';
|
|
@@ -10,7 +10,7 @@ import { z } from 'zod';
|
|
|
10
10
|
import { existsSync, readFileSync } from 'fs';
|
|
11
11
|
import { createRequire } from 'module';
|
|
12
12
|
import { promisify } from 'util';
|
|
13
|
-
import {
|
|
13
|
+
import { ModelRouterLanguageModel } from '@mastra/core/llm';
|
|
14
14
|
import { MemoryProcessor } from '@mastra/core/memory';
|
|
15
15
|
import { tmpdir } from 'os';
|
|
16
16
|
import { openai } from '@ai-sdk/openai';
|
|
@@ -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,
|
|
504
|
+
var resolveTargetPath = (inputData, requestContext) => {
|
|
505
505
|
if (inputData.targetPath) {
|
|
506
506
|
return inputData.targetPath;
|
|
507
507
|
}
|
|
508
|
-
const contextPath =
|
|
508
|
+
const contextPath = requestContext.get("targetPath");
|
|
509
509
|
if (contextPath) {
|
|
510
510
|
return contextPath;
|
|
511
511
|
}
|
|
@@ -658,31 +658,9 @@ var createModelInstance = async (provider, modelId, version = "v2") => {
|
|
|
658
658
|
const { google } = await import('@ai-sdk/google');
|
|
659
659
|
return google(modelId);
|
|
660
660
|
}
|
|
661
|
-
},
|
|
662
|
-
v2: {
|
|
663
|
-
openai: async () => {
|
|
664
|
-
const { openai: openai2 } = await import('@ai-sdk/openai-v5');
|
|
665
|
-
return openai2(modelId);
|
|
666
|
-
},
|
|
667
|
-
anthropic: async () => {
|
|
668
|
-
const { anthropic } = await import('@ai-sdk/anthropic-v5');
|
|
669
|
-
return anthropic(modelId);
|
|
670
|
-
},
|
|
671
|
-
groq: async () => {
|
|
672
|
-
const { groq } = await import('@ai-sdk/groq-v5');
|
|
673
|
-
return groq(modelId);
|
|
674
|
-
},
|
|
675
|
-
xai: async () => {
|
|
676
|
-
const { xai } = await import('@ai-sdk/xai-v5');
|
|
677
|
-
return xai(modelId);
|
|
678
|
-
},
|
|
679
|
-
google: async () => {
|
|
680
|
-
const { google } = await import('@ai-sdk/google-v5');
|
|
681
|
-
return google(modelId);
|
|
682
|
-
}
|
|
683
661
|
}
|
|
684
662
|
};
|
|
685
|
-
const providerFn = providerMap[version][provider];
|
|
663
|
+
const providerFn = version === `v1` ? providerMap[version][provider] : () => new ModelRouterLanguageModel(`${provider}/${modelId}`);
|
|
686
664
|
if (!providerFn) {
|
|
687
665
|
console.error(`Unsupported provider: ${provider}`);
|
|
688
666
|
return null;
|
|
@@ -696,13 +674,13 @@ var createModelInstance = async (provider, modelId, version = "v2") => {
|
|
|
696
674
|
}
|
|
697
675
|
};
|
|
698
676
|
var resolveModel = async ({
|
|
699
|
-
|
|
700
|
-
defaultModel = openai
|
|
677
|
+
requestContext,
|
|
678
|
+
defaultModel = "openai/gpt-4.1",
|
|
701
679
|
projectPath
|
|
702
680
|
}) => {
|
|
703
|
-
const modelFromContext =
|
|
681
|
+
const modelFromContext = requestContext.get("model");
|
|
704
682
|
if (modelFromContext) {
|
|
705
|
-
console.info("Using model from
|
|
683
|
+
console.info("Using model from request context");
|
|
706
684
|
if (isValidMastraLanguageModel(modelFromContext)) {
|
|
707
685
|
return modelFromContext;
|
|
708
686
|
}
|
|
@@ -710,18 +688,18 @@ var resolveModel = async ({
|
|
|
710
688
|
'Invalid model provided. Model must be a MastraLanguageModel instance (e.g., openai("gpt-4"), anthropic("claude-3-5-sonnet"), etc.)'
|
|
711
689
|
);
|
|
712
690
|
}
|
|
713
|
-
const selectedModel =
|
|
691
|
+
const selectedModel = requestContext.get("selectedModel");
|
|
714
692
|
if (selectedModel?.provider && selectedModel?.modelId && projectPath) {
|
|
715
693
|
console.info(`Resolving selected model: ${selectedModel.provider}/${selectedModel.modelId}`);
|
|
716
694
|
const version = await detectAISDKVersion(projectPath);
|
|
717
695
|
const modelInstance = await createModelInstance(selectedModel.provider, selectedModel.modelId, version);
|
|
718
696
|
if (modelInstance) {
|
|
719
|
-
|
|
697
|
+
requestContext.set("model", modelInstance);
|
|
720
698
|
return modelInstance;
|
|
721
699
|
}
|
|
722
700
|
}
|
|
723
701
|
console.info("Using default model");
|
|
724
|
-
return defaultModel;
|
|
702
|
+
return typeof defaultModel === `string` ? new ModelRouterLanguageModel(defaultModel) : defaultModel;
|
|
725
703
|
};
|
|
726
704
|
|
|
727
705
|
// src/defaults.ts
|
|
@@ -890,7 +868,7 @@ You have access to an enhanced set of tools based on production coding agent pat
|
|
|
890
868
|
### Task Management
|
|
891
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.
|
|
892
870
|
|
|
893
|
-
### Code Discovery & Analysis
|
|
871
|
+
### Code Discovery & Analysis
|
|
894
872
|
- **codeAnalyzer**: Analyze codebase structure, discover definitions (functions, classes, interfaces), map dependencies, and understand architectural patterns.
|
|
895
873
|
- **smartSearch**: Intelligent search with context awareness, pattern matching, and relevance scoring.
|
|
896
874
|
|
|
@@ -928,6 +906,7 @@ import { LibSQLStore } from '@mastra/libsql';
|
|
|
928
906
|
import { weatherTool } from '../tools/weather-tool';
|
|
929
907
|
|
|
930
908
|
export const weatherAgent = new Agent({
|
|
909
|
+
id: 'weather-agent',
|
|
931
910
|
name: 'Weather Agent',
|
|
932
911
|
instructions: \${instructions},
|
|
933
912
|
model: openai('gpt-4o-mini'),
|
|
@@ -962,8 +941,8 @@ export const weatherTool = createTool({
|
|
|
962
941
|
conditions: z.string(),
|
|
963
942
|
location: z.string(),
|
|
964
943
|
}),
|
|
965
|
-
execute: async (
|
|
966
|
-
return await getWeather(
|
|
944
|
+
execute: async (inputData) => {
|
|
945
|
+
return await getWeather(inputData.location);
|
|
967
946
|
},
|
|
968
947
|
});
|
|
969
948
|
\`\`\`
|
|
@@ -981,7 +960,7 @@ const fetchWeather = createStep({
|
|
|
981
960
|
city: z.string().describe('The city to get the weather for'),
|
|
982
961
|
}),
|
|
983
962
|
outputSchema: forecastSchema,
|
|
984
|
-
execute: async (
|
|
963
|
+
execute: async (inputData) => {
|
|
985
964
|
if (!inputData) {
|
|
986
965
|
throw new Error('Input data not found');
|
|
987
966
|
}
|
|
@@ -1035,7 +1014,8 @@ const planActivities = createStep({
|
|
|
1035
1014
|
outputSchema: z.object({
|
|
1036
1015
|
activities: z.string(),
|
|
1037
1016
|
}),
|
|
1038
|
-
execute: async (
|
|
1017
|
+
execute: async (inputData, context) => {
|
|
1018
|
+
const mastra = context?.mastra;
|
|
1039
1019
|
const forecast = inputData;
|
|
1040
1020
|
|
|
1041
1021
|
if (!forecast) {
|
|
@@ -1100,7 +1080,7 @@ export const mastra = new Mastra({
|
|
|
1100
1080
|
workflows: { weatherWorkflow },
|
|
1101
1081
|
agents: { weatherAgent },
|
|
1102
1082
|
storage: new LibSQLStore({
|
|
1103
|
-
// stores
|
|
1083
|
+
// stores observability, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
1104
1084
|
url: ":memory:",
|
|
1105
1085
|
}),
|
|
1106
1086
|
logger: new PinoLogger({
|
|
@@ -1144,8 +1124,8 @@ export const mastra = new Mastra({
|
|
|
1144
1124
|
}).optional(),
|
|
1145
1125
|
error: z.string().optional()
|
|
1146
1126
|
}),
|
|
1147
|
-
execute: async (
|
|
1148
|
-
return await _AgentBuilderDefaults.readFile({ ...
|
|
1127
|
+
execute: async (inputData) => {
|
|
1128
|
+
return await _AgentBuilderDefaults.readFile({ ...inputData, projectPath });
|
|
1149
1129
|
}
|
|
1150
1130
|
}),
|
|
1151
1131
|
writeFile: createTool({
|
|
@@ -1164,8 +1144,8 @@ export const mastra = new Mastra({
|
|
|
1164
1144
|
message: z.string(),
|
|
1165
1145
|
error: z.string().optional()
|
|
1166
1146
|
}),
|
|
1167
|
-
execute: async (
|
|
1168
|
-
return await _AgentBuilderDefaults.writeFile({ ...
|
|
1147
|
+
execute: async (inputData) => {
|
|
1148
|
+
return await _AgentBuilderDefaults.writeFile({ ...inputData, projectPath });
|
|
1169
1149
|
}
|
|
1170
1150
|
}),
|
|
1171
1151
|
listDirectory: createTool({
|
|
@@ -1196,8 +1176,8 @@ export const mastra = new Mastra({
|
|
|
1196
1176
|
message: z.string(),
|
|
1197
1177
|
error: z.string().optional()
|
|
1198
1178
|
}),
|
|
1199
|
-
execute: async (
|
|
1200
|
-
return await _AgentBuilderDefaults.listDirectory({ ...
|
|
1179
|
+
execute: async (inputData) => {
|
|
1180
|
+
return await _AgentBuilderDefaults.listDirectory({ ...inputData, projectPath });
|
|
1201
1181
|
}
|
|
1202
1182
|
}),
|
|
1203
1183
|
executeCommand: createTool({
|
|
@@ -1221,10 +1201,10 @@ export const mastra = new Mastra({
|
|
|
1221
1201
|
executionTime: z.number().optional(),
|
|
1222
1202
|
error: z.string().optional()
|
|
1223
1203
|
}),
|
|
1224
|
-
execute: async (
|
|
1204
|
+
execute: async (inputData) => {
|
|
1225
1205
|
return await _AgentBuilderDefaults.executeCommand({
|
|
1226
|
-
...
|
|
1227
|
-
workingDirectory:
|
|
1206
|
+
...inputData,
|
|
1207
|
+
workingDirectory: inputData.workingDirectory || projectPath
|
|
1228
1208
|
});
|
|
1229
1209
|
}
|
|
1230
1210
|
}),
|
|
@@ -1262,8 +1242,8 @@ export const mastra = new Mastra({
|
|
|
1262
1242
|
),
|
|
1263
1243
|
message: z.string()
|
|
1264
1244
|
}),
|
|
1265
|
-
execute: async (
|
|
1266
|
-
return await _AgentBuilderDefaults.manageTaskList(
|
|
1245
|
+
execute: async (inputData) => {
|
|
1246
|
+
return await _AgentBuilderDefaults.manageTaskList(inputData);
|
|
1267
1247
|
}
|
|
1268
1248
|
}),
|
|
1269
1249
|
// Advanced File Operations
|
|
@@ -1297,8 +1277,8 @@ export const mastra = new Mastra({
|
|
|
1297
1277
|
),
|
|
1298
1278
|
message: z.string()
|
|
1299
1279
|
}),
|
|
1300
|
-
execute: async (
|
|
1301
|
-
return await _AgentBuilderDefaults.performMultiEdit({ ...
|
|
1280
|
+
execute: async (inputData) => {
|
|
1281
|
+
return await _AgentBuilderDefaults.performMultiEdit({ ...inputData, projectPath });
|
|
1302
1282
|
}
|
|
1303
1283
|
}),
|
|
1304
1284
|
replaceLines: createTool({
|
|
@@ -1322,8 +1302,8 @@ export const mastra = new Mastra({
|
|
|
1322
1302
|
backup: z.string().optional(),
|
|
1323
1303
|
error: z.string().optional()
|
|
1324
1304
|
}),
|
|
1325
|
-
execute: async (
|
|
1326
|
-
return await _AgentBuilderDefaults.replaceLines({ ...
|
|
1305
|
+
execute: async (inputData) => {
|
|
1306
|
+
return await _AgentBuilderDefaults.replaceLines({ ...inputData, projectPath });
|
|
1327
1307
|
}
|
|
1328
1308
|
}),
|
|
1329
1309
|
// File diagnostics tool to help debug line replacement issues
|
|
@@ -1351,8 +1331,8 @@ export const mastra = new Mastra({
|
|
|
1351
1331
|
message: z.string(),
|
|
1352
1332
|
error: z.string().optional()
|
|
1353
1333
|
}),
|
|
1354
|
-
execute: async (
|
|
1355
|
-
return await _AgentBuilderDefaults.showFileLines({ ...
|
|
1334
|
+
execute: async (inputData) => {
|
|
1335
|
+
return await _AgentBuilderDefaults.showFileLines({ ...inputData, projectPath });
|
|
1356
1336
|
}
|
|
1357
1337
|
}),
|
|
1358
1338
|
// Enhanced Pattern Search
|
|
@@ -1395,8 +1375,8 @@ export const mastra = new Mastra({
|
|
|
1395
1375
|
patterns: z.array(z.string())
|
|
1396
1376
|
})
|
|
1397
1377
|
}),
|
|
1398
|
-
execute: async (
|
|
1399
|
-
return await _AgentBuilderDefaults.performSmartSearch(
|
|
1378
|
+
execute: async (inputData) => {
|
|
1379
|
+
return await _AgentBuilderDefaults.performSmartSearch(inputData, projectPath);
|
|
1400
1380
|
}
|
|
1401
1381
|
}),
|
|
1402
1382
|
validateCode: createTool({
|
|
@@ -1429,8 +1409,8 @@ export const mastra = new Mastra({
|
|
|
1429
1409
|
validationsFailed: z.array(z.string())
|
|
1430
1410
|
})
|
|
1431
1411
|
}),
|
|
1432
|
-
execute: async (
|
|
1433
|
-
const { projectPath: validationProjectPath, validationType, files } =
|
|
1412
|
+
execute: async (inputData) => {
|
|
1413
|
+
const { projectPath: validationProjectPath, validationType, files } = inputData;
|
|
1434
1414
|
const targetPath = validationProjectPath || projectPath;
|
|
1435
1415
|
return await _AgentBuilderDefaults.validateCode({
|
|
1436
1416
|
projectPath: targetPath,
|
|
@@ -1469,8 +1449,8 @@ export const mastra = new Mastra({
|
|
|
1469
1449
|
suggestions: z.array(z.string()).optional(),
|
|
1470
1450
|
error: z.string().optional()
|
|
1471
1451
|
}),
|
|
1472
|
-
execute: async (
|
|
1473
|
-
return await _AgentBuilderDefaults.webSearch(
|
|
1452
|
+
execute: async (inputData) => {
|
|
1453
|
+
return await _AgentBuilderDefaults.webSearch(inputData);
|
|
1474
1454
|
}
|
|
1475
1455
|
}),
|
|
1476
1456
|
// Task Completion Signaling
|
|
@@ -1499,8 +1479,8 @@ export const mastra = new Mastra({
|
|
|
1499
1479
|
summary: z.string(),
|
|
1500
1480
|
confidence: z.number().min(0).max(100)
|
|
1501
1481
|
}),
|
|
1502
|
-
execute: async (
|
|
1503
|
-
return await _AgentBuilderDefaults.signalCompletion(
|
|
1482
|
+
execute: async (inputData) => {
|
|
1483
|
+
return await _AgentBuilderDefaults.signalCompletion(inputData);
|
|
1504
1484
|
}
|
|
1505
1485
|
}),
|
|
1506
1486
|
manageProject: createTool({
|
|
@@ -1525,8 +1505,8 @@ export const mastra = new Mastra({
|
|
|
1525
1505
|
details: z.string().optional(),
|
|
1526
1506
|
error: z.string().optional()
|
|
1527
1507
|
}),
|
|
1528
|
-
execute: async (
|
|
1529
|
-
const { action, features, packages } =
|
|
1508
|
+
execute: async (inputData) => {
|
|
1509
|
+
const { action, features, packages } = inputData;
|
|
1530
1510
|
try {
|
|
1531
1511
|
switch (action) {
|
|
1532
1512
|
case "create":
|
|
@@ -1587,8 +1567,8 @@ export const mastra = new Mastra({
|
|
|
1587
1567
|
stdout: z.array(z.string()).optional().describe("Server output lines captured during startup"),
|
|
1588
1568
|
error: z.string().optional()
|
|
1589
1569
|
}),
|
|
1590
|
-
execute: async (
|
|
1591
|
-
const { action, port } =
|
|
1570
|
+
execute: async (inputData) => {
|
|
1571
|
+
const { action, port } = inputData;
|
|
1592
1572
|
try {
|
|
1593
1573
|
switch (action) {
|
|
1594
1574
|
case "start":
|
|
@@ -1673,8 +1653,8 @@ export const mastra = new Mastra({
|
|
|
1673
1653
|
url: z.string(),
|
|
1674
1654
|
method: z.string()
|
|
1675
1655
|
}),
|
|
1676
|
-
execute: async (
|
|
1677
|
-
const { method, url, baseUrl, headers, body, timeout } =
|
|
1656
|
+
execute: async (inputData) => {
|
|
1657
|
+
const { method, url, baseUrl, headers, body, timeout } = inputData;
|
|
1678
1658
|
try {
|
|
1679
1659
|
return await _AgentBuilderDefaults.makeHttpRequest({
|
|
1680
1660
|
method,
|
|
@@ -1729,7 +1709,7 @@ export const mastra = new Mastra({
|
|
|
1729
1709
|
/**
|
|
1730
1710
|
* Get tools for a specific mode
|
|
1731
1711
|
*/
|
|
1732
|
-
static async
|
|
1712
|
+
static async listToolsForMode(projectPath, mode = "code-editor") {
|
|
1733
1713
|
const allTools = await _AgentBuilderDefaults.DEFAULT_TOOLS(projectPath);
|
|
1734
1714
|
if (mode === "template") {
|
|
1735
1715
|
return _AgentBuilderDefaults.filterToolsForTemplateBuilder(allTools);
|
|
@@ -3108,7 +3088,8 @@ var ToolSummaryProcessor = class extends MemoryProcessor {
|
|
|
3108
3088
|
constructor({ summaryModel }) {
|
|
3109
3089
|
super({ name: "ToolSummaryProcessor" });
|
|
3110
3090
|
this.summaryAgent = new Agent({
|
|
3111
|
-
|
|
3091
|
+
id: "tool-summary-agent",
|
|
3092
|
+
name: "Tool Summary Agent",
|
|
3112
3093
|
description: "A summary agent that summarizes tool calls and results",
|
|
3113
3094
|
instructions: "You are a summary agent that summarizes tool calls and results",
|
|
3114
3095
|
model: summaryModel
|
|
@@ -3212,7 +3193,7 @@ ${config.instructions}` : "";
|
|
|
3212
3193
|
model: config.model,
|
|
3213
3194
|
tools: async () => {
|
|
3214
3195
|
return {
|
|
3215
|
-
...await AgentBuilderDefaults.
|
|
3196
|
+
...await AgentBuilderDefaults.listToolsForMode(config.projectPath, config.mode),
|
|
3216
3197
|
...config.tools || {}
|
|
3217
3198
|
};
|
|
3218
3199
|
},
|
|
@@ -3234,9 +3215,9 @@ ${config.instructions}` : "";
|
|
|
3234
3215
|
* Enhanced generate method with AgentBuilder-specific configuration
|
|
3235
3216
|
* Overrides the base Agent generate method to provide additional project context
|
|
3236
3217
|
*/
|
|
3237
|
-
|
|
3218
|
+
generateLegacy = async (messages, generateOptions = {}) => {
|
|
3238
3219
|
const { maxSteps, ...baseOptions } = generateOptions;
|
|
3239
|
-
const originalInstructions = await this.getInstructions({
|
|
3220
|
+
const originalInstructions = await this.getInstructions({ requestContext: generateOptions?.requestContext });
|
|
3240
3221
|
const additionalInstructions = baseOptions.instructions;
|
|
3241
3222
|
let enhancedInstructions = originalInstructions;
|
|
3242
3223
|
if (additionalInstructions) {
|
|
@@ -3257,15 +3238,15 @@ ${additionalInstructions}`;
|
|
|
3257
3238
|
this.logger.debug(`[AgentBuilder:${this.name}] Starting generation with enhanced context`, {
|
|
3258
3239
|
projectPath: this.builderConfig.projectPath
|
|
3259
3240
|
});
|
|
3260
|
-
return super.
|
|
3241
|
+
return super.generateLegacy(messages, enhancedOptions);
|
|
3261
3242
|
};
|
|
3262
3243
|
/**
|
|
3263
3244
|
* Enhanced stream method with AgentBuilder-specific configuration
|
|
3264
3245
|
* Overrides the base Agent stream method to provide additional project context
|
|
3265
3246
|
*/
|
|
3266
|
-
|
|
3247
|
+
streamLegacy = async (messages, streamOptions = {}) => {
|
|
3267
3248
|
const { maxSteps, ...baseOptions } = streamOptions;
|
|
3268
|
-
const originalInstructions = await this.getInstructions({
|
|
3249
|
+
const originalInstructions = await this.getInstructions({ requestContext: streamOptions?.requestContext });
|
|
3269
3250
|
const additionalInstructions = baseOptions.instructions;
|
|
3270
3251
|
let enhancedInstructions = originalInstructions;
|
|
3271
3252
|
if (additionalInstructions) {
|
|
@@ -3286,15 +3267,15 @@ ${additionalInstructions}`;
|
|
|
3286
3267
|
this.logger.debug(`[AgentBuilder:${this.name}] Starting streaming with enhanced context`, {
|
|
3287
3268
|
projectPath: this.builderConfig.projectPath
|
|
3288
3269
|
});
|
|
3289
|
-
return super.
|
|
3270
|
+
return super.streamLegacy(messages, enhancedOptions);
|
|
3290
3271
|
};
|
|
3291
3272
|
/**
|
|
3292
3273
|
* Enhanced stream method with AgentBuilder-specific configuration
|
|
3293
3274
|
* Overrides the base Agent stream method to provide additional project context
|
|
3294
3275
|
*/
|
|
3295
|
-
async
|
|
3276
|
+
async stream(messages, streamOptions) {
|
|
3296
3277
|
const { ...baseOptions } = streamOptions || {};
|
|
3297
|
-
const originalInstructions = await this.getInstructions({
|
|
3278
|
+
const originalInstructions = await this.getInstructions({ requestContext: streamOptions?.requestContext });
|
|
3298
3279
|
const additionalInstructions = baseOptions.instructions;
|
|
3299
3280
|
let enhancedInstructions = originalInstructions;
|
|
3300
3281
|
if (additionalInstructions) {
|
|
@@ -3314,11 +3295,11 @@ ${additionalInstructions}`;
|
|
|
3314
3295
|
this.logger.debug(`[AgentBuilder:${this.name}] Starting streaming with enhanced context`, {
|
|
3315
3296
|
projectPath: this.builderConfig.projectPath
|
|
3316
3297
|
});
|
|
3317
|
-
return super.
|
|
3298
|
+
return super.stream(messages, enhancedOptions);
|
|
3318
3299
|
}
|
|
3319
|
-
async
|
|
3300
|
+
async generate(messages, options) {
|
|
3320
3301
|
const { ...baseOptions } = options || {};
|
|
3321
|
-
const originalInstructions = await this.getInstructions({
|
|
3302
|
+
const originalInstructions = await this.getInstructions({ requestContext: options?.requestContext });
|
|
3322
3303
|
const additionalInstructions = baseOptions.instructions;
|
|
3323
3304
|
let enhancedInstructions = originalInstructions;
|
|
3324
3305
|
if (additionalInstructions) {
|
|
@@ -3338,7 +3319,7 @@ ${additionalInstructions}`;
|
|
|
3338
3319
|
this.logger.debug(`[AgentBuilder:${this.name}] Starting streaming with enhanced context`, {
|
|
3339
3320
|
projectPath: this.builderConfig.projectPath
|
|
3340
3321
|
});
|
|
3341
|
-
return super.
|
|
3322
|
+
return super.generate(messages, enhancedOptions);
|
|
3342
3323
|
}
|
|
3343
3324
|
};
|
|
3344
3325
|
var cloneTemplateStep = createStep({
|
|
@@ -3426,14 +3407,15 @@ var discoverUnitsStep = createStep({
|
|
|
3426
3407
|
description: "Discover template units by analyzing the templates directory structure",
|
|
3427
3408
|
inputSchema: CloneTemplateResultSchema,
|
|
3428
3409
|
outputSchema: DiscoveryResultSchema,
|
|
3429
|
-
execute: async ({ inputData,
|
|
3410
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3430
3411
|
const { templateDir } = inputData;
|
|
3431
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3412
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3432
3413
|
const tools = await AgentBuilderDefaults.DEFAULT_TOOLS(templateDir);
|
|
3433
3414
|
console.info("targetPath", targetPath);
|
|
3434
|
-
const model = await resolveModel({
|
|
3415
|
+
const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
3435
3416
|
try {
|
|
3436
3417
|
const agent = new Agent({
|
|
3418
|
+
id: "mastra-project-discoverer",
|
|
3437
3419
|
model,
|
|
3438
3420
|
instructions: `You are an expert at analyzing Mastra projects.
|
|
3439
3421
|
|
|
@@ -3491,10 +3473,12 @@ Return the actual exported names of the units, as well as the file names.`,
|
|
|
3491
3473
|
networks: z.array(z.object({ name: z.string(), file: z.string() })).optional(),
|
|
3492
3474
|
other: z.array(z.object({ name: z.string(), file: z.string() })).optional()
|
|
3493
3475
|
});
|
|
3494
|
-
const result = isV2 ? await agent
|
|
3495
|
-
|
|
3476
|
+
const result = isV2 ? await tryGenerateWithJsonFallback(agent, prompt, {
|
|
3477
|
+
structuredOutput: {
|
|
3478
|
+
schema: output
|
|
3479
|
+
},
|
|
3496
3480
|
maxSteps: 100
|
|
3497
|
-
}) : await agent.
|
|
3481
|
+
}) : await agent.generateLegacy(prompt, {
|
|
3498
3482
|
experimental_output: output,
|
|
3499
3483
|
maxSteps: 100
|
|
3500
3484
|
});
|
|
@@ -3568,8 +3552,8 @@ var prepareBranchStep = createStep({
|
|
|
3568
3552
|
description: "Create or switch to integration branch before modifications",
|
|
3569
3553
|
inputSchema: PrepareBranchInputSchema,
|
|
3570
3554
|
outputSchema: PrepareBranchResultSchema,
|
|
3571
|
-
execute: async ({ inputData,
|
|
3572
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3555
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3556
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3573
3557
|
try {
|
|
3574
3558
|
const branchName = `feat/install-template-${inputData.slug}`;
|
|
3575
3559
|
await gitCheckoutBranch(branchName, targetPath);
|
|
@@ -3593,10 +3577,10 @@ var packageMergeStep = createStep({
|
|
|
3593
3577
|
description: "Merge template package.json dependencies into target project",
|
|
3594
3578
|
inputSchema: PackageMergeInputSchema,
|
|
3595
3579
|
outputSchema: PackageMergeResultSchema,
|
|
3596
|
-
execute: async ({ inputData,
|
|
3580
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3597
3581
|
console.info("Package merge step starting...");
|
|
3598
3582
|
const { slug, packageInfo } = inputData;
|
|
3599
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3583
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3600
3584
|
try {
|
|
3601
3585
|
const targetPkgPath = join(targetPath, "package.json");
|
|
3602
3586
|
let targetPkgRaw = "{}";
|
|
@@ -3670,9 +3654,9 @@ var installStep = createStep({
|
|
|
3670
3654
|
description: "Install packages based on merged package.json",
|
|
3671
3655
|
inputSchema: InstallInputSchema,
|
|
3672
3656
|
outputSchema: InstallResultSchema,
|
|
3673
|
-
execute: async ({ inputData,
|
|
3657
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3674
3658
|
console.info("Running install step...");
|
|
3675
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3659
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3676
3660
|
try {
|
|
3677
3661
|
await spawnSWPM(targetPath, "install", []);
|
|
3678
3662
|
const lock = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock"].map((f) => join(targetPath, f)).find((f) => existsSync(f));
|
|
@@ -3698,10 +3682,10 @@ var programmaticFileCopyStep = createStep({
|
|
|
3698
3682
|
description: "Programmatically copy template files to target project based on ordered units",
|
|
3699
3683
|
inputSchema: FileCopyInputSchema,
|
|
3700
3684
|
outputSchema: FileCopyResultSchema,
|
|
3701
|
-
execute: async ({ inputData,
|
|
3685
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3702
3686
|
console.info("Programmatic file copy step starting...");
|
|
3703
3687
|
const { orderedUnits, templateDir, commitSha, slug } = inputData;
|
|
3704
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3688
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3705
3689
|
try {
|
|
3706
3690
|
const copiedFiles = [];
|
|
3707
3691
|
const conflicts = [];
|
|
@@ -4050,12 +4034,12 @@ var intelligentMergeStep = createStep({
|
|
|
4050
4034
|
description: "Use AgentBuilder to intelligently merge template files",
|
|
4051
4035
|
inputSchema: IntelligentMergeInputSchema,
|
|
4052
4036
|
outputSchema: IntelligentMergeResultSchema,
|
|
4053
|
-
execute: async ({ inputData,
|
|
4037
|
+
execute: async ({ inputData, requestContext }) => {
|
|
4054
4038
|
console.info("Intelligent merge step starting...");
|
|
4055
4039
|
const { conflicts, copiedFiles, commitSha, slug, templateDir, branchName } = inputData;
|
|
4056
|
-
const targetPath = resolveTargetPath(inputData,
|
|
4040
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
4057
4041
|
try {
|
|
4058
|
-
const model = await resolveModel({
|
|
4042
|
+
const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
4059
4043
|
const copyFileTool = createTool({
|
|
4060
4044
|
id: "copy-file",
|
|
4061
4045
|
description: "Copy a file from template to target project (use only for edge cases - most files are already copied programmatically).",
|
|
@@ -4068,9 +4052,9 @@ var intelligentMergeStep = createStep({
|
|
|
4068
4052
|
message: z.string(),
|
|
4069
4053
|
error: z.string().optional()
|
|
4070
4054
|
}),
|
|
4071
|
-
execute: async (
|
|
4055
|
+
execute: async (input) => {
|
|
4072
4056
|
try {
|
|
4073
|
-
const { sourcePath, destinationPath } =
|
|
4057
|
+
const { sourcePath, destinationPath } = input;
|
|
4074
4058
|
const resolvedSourcePath = resolve(templateDir, sourcePath);
|
|
4075
4059
|
const resolvedDestinationPath = resolve(targetPath, destinationPath);
|
|
4076
4060
|
if (existsSync(resolvedSourcePath) && !existsSync(dirname(resolvedDestinationPath))) {
|
|
@@ -4240,7 +4224,7 @@ For each task:
|
|
|
4240
4224
|
Start by listing your tasks and work through them systematically!
|
|
4241
4225
|
`;
|
|
4242
4226
|
const isV2 = model.specificationVersion === "v2";
|
|
4243
|
-
const result = isV2 ? await agentBuilder.
|
|
4227
|
+
const result = isV2 ? await agentBuilder.stream(prompt) : await agentBuilder.streamLegacy(prompt);
|
|
4244
4228
|
const actualResolutions = [];
|
|
4245
4229
|
for await (const chunk of result.fullStream) {
|
|
4246
4230
|
if (chunk.type === "step-finish" || chunk.type === "step-start") {
|
|
@@ -4318,10 +4302,10 @@ var validationAndFixStep = createStep({
|
|
|
4318
4302
|
description: "Validate the merged template code and fix any issues using a specialized agent",
|
|
4319
4303
|
inputSchema: ValidationFixInputSchema,
|
|
4320
4304
|
outputSchema: ValidationFixResultSchema,
|
|
4321
|
-
execute: async ({ inputData,
|
|
4305
|
+
execute: async ({ inputData, requestContext }) => {
|
|
4322
4306
|
console.info("Validation and fix step starting...");
|
|
4323
4307
|
const { commitSha, slug, orderedUnits, templateDir, copiedFiles, conflictsResolved, maxIterations = 5 } = inputData;
|
|
4324
|
-
const targetPath = resolveTargetPath(inputData,
|
|
4308
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
4325
4309
|
const hasChanges = copiedFiles.length > 0 || conflictsResolved && conflictsResolved.length > 0;
|
|
4326
4310
|
if (!hasChanges) {
|
|
4327
4311
|
console.info("\u23ED\uFE0F Skipping validation - no files copied or conflicts resolved");
|
|
@@ -4341,10 +4325,11 @@ var validationAndFixStep = createStep({
|
|
|
4341
4325
|
);
|
|
4342
4326
|
let currentIteration = 1;
|
|
4343
4327
|
try {
|
|
4344
|
-
const model = await resolveModel({
|
|
4345
|
-
const allTools = await AgentBuilderDefaults.
|
|
4328
|
+
const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
4329
|
+
const allTools = await AgentBuilderDefaults.listToolsForMode(targetPath, "template");
|
|
4346
4330
|
const validationAgent = new Agent({
|
|
4347
|
-
|
|
4331
|
+
id: "code-validator-fixer",
|
|
4332
|
+
name: "Code Validator Fixer",
|
|
4348
4333
|
description: "Specialized agent for validating and fixing template integration issues",
|
|
4349
4334
|
instructions: `You are a code validation and fixing specialist. Your job is to:
|
|
4350
4335
|
|
|
@@ -4482,9 +4467,11 @@ Start by running validateCode with all validation types to get a complete pictur
|
|
|
4482
4467
|
Previous iterations may have fixed some issues, so start by re-running validateCode to see the current state, then fix any remaining issues.`;
|
|
4483
4468
|
const isV2 = model.specificationVersion === "v2";
|
|
4484
4469
|
const output = z.object({ success: z.boolean() });
|
|
4485
|
-
const result = isV2 ? await validationAgent
|
|
4486
|
-
|
|
4487
|
-
|
|
4470
|
+
const result = isV2 ? await tryStreamWithJsonFallback(validationAgent, iterationPrompt, {
|
|
4471
|
+
structuredOutput: {
|
|
4472
|
+
schema: output
|
|
4473
|
+
}
|
|
4474
|
+
}) : await validationAgent.streamLegacy(iterationPrompt, {
|
|
4488
4475
|
experimental_output: output
|
|
4489
4476
|
});
|
|
4490
4477
|
let iterationErrors = 0;
|
|
@@ -4745,7 +4732,7 @@ var agentBuilderTemplateWorkflow = createWorkflow({
|
|
|
4745
4732
|
}).commit();
|
|
4746
4733
|
async function mergeTemplateBySlug(slug, targetPath) {
|
|
4747
4734
|
const template = await getMastraTemplate(slug);
|
|
4748
|
-
const run = await agentBuilderTemplateWorkflow.
|
|
4735
|
+
const run = await agentBuilderTemplateWorkflow.createRun();
|
|
4749
4736
|
return await run.start({
|
|
4750
4737
|
inputData: {
|
|
4751
4738
|
repo: template.githubUrl,
|
|
@@ -5052,7 +5039,7 @@ var planningIterationStep = createStep({
|
|
|
5052
5039
|
outputSchema: PlanningIterationResultSchema,
|
|
5053
5040
|
suspendSchema: PlanningIterationSuspendSchema,
|
|
5054
5041
|
resumeSchema: PlanningIterationResumeSchema,
|
|
5055
|
-
execute: async ({ inputData, resumeData, suspend,
|
|
5042
|
+
execute: async ({ inputData, resumeData, suspend, requestContext }) => {
|
|
5056
5043
|
const {
|
|
5057
5044
|
action,
|
|
5058
5045
|
workflowName,
|
|
@@ -5065,7 +5052,7 @@ var planningIterationStep = createStep({
|
|
|
5065
5052
|
} = inputData;
|
|
5066
5053
|
console.info("Starting planning iteration...");
|
|
5067
5054
|
const qaKey = "workflow-builder-qa";
|
|
5068
|
-
let storedQAPairs =
|
|
5055
|
+
let storedQAPairs = requestContext.get(qaKey) || [];
|
|
5069
5056
|
const newAnswers = { ...userAnswers || {}, ...resumeData?.answers || {} };
|
|
5070
5057
|
if (Object.keys(newAnswers).length > 0) {
|
|
5071
5058
|
storedQAPairs = storedQAPairs.map((pair) => {
|
|
@@ -5078,10 +5065,10 @@ var planningIterationStep = createStep({
|
|
|
5078
5065
|
}
|
|
5079
5066
|
return pair;
|
|
5080
5067
|
});
|
|
5081
|
-
|
|
5068
|
+
requestContext.set(qaKey, storedQAPairs);
|
|
5082
5069
|
}
|
|
5083
5070
|
try {
|
|
5084
|
-
const model = await resolveModel({
|
|
5071
|
+
const model = await resolveModel({ requestContext });
|
|
5085
5072
|
const planningAgent = new Agent({
|
|
5086
5073
|
model,
|
|
5087
5074
|
instructions: taskPlanningPrompts.planningAgent.instructions({
|
|
@@ -5111,8 +5098,10 @@ var planningIterationStep = createStep({
|
|
|
5111
5098
|
projectStructure,
|
|
5112
5099
|
research
|
|
5113
5100
|
});
|
|
5114
|
-
const result = await planningAgent.
|
|
5115
|
-
|
|
5101
|
+
const result = await planningAgent.generate(planningPrompt, {
|
|
5102
|
+
structuredOutput: {
|
|
5103
|
+
schema: PlanningAgentOutputSchema
|
|
5104
|
+
}
|
|
5116
5105
|
// maxSteps: 15,
|
|
5117
5106
|
});
|
|
5118
5107
|
const planResult = await result.object;
|
|
@@ -5136,7 +5125,7 @@ var planningIterationStep = createStep({
|
|
|
5136
5125
|
answeredAt: null
|
|
5137
5126
|
}));
|
|
5138
5127
|
storedQAPairs = [...storedQAPairs, ...newQAPairs];
|
|
5139
|
-
|
|
5128
|
+
requestContext.set(qaKey, storedQAPairs);
|
|
5140
5129
|
console.info(
|
|
5141
5130
|
`Updated Q&A state: ${storedQAPairs.length} total question-answer pairs, ${storedQAPairs.filter((p) => p.answer).length} answered`
|
|
5142
5131
|
);
|
|
@@ -5150,7 +5139,7 @@ var planningIterationStep = createStep({
|
|
|
5150
5139
|
});
|
|
5151
5140
|
}
|
|
5152
5141
|
console.info(`Planning complete with ${planResult.tasks.length} tasks`);
|
|
5153
|
-
|
|
5142
|
+
requestContext.set(qaKey, storedQAPairs);
|
|
5154
5143
|
console.info(
|
|
5155
5144
|
`Final Q&A state: ${storedQAPairs.length} total question-answer pairs, ${storedQAPairs.filter((p) => p.answer).length} answered`
|
|
5156
5145
|
);
|
|
@@ -5295,7 +5284,7 @@ const myStep = createStep({
|
|
|
5295
5284
|
- \`mastra\`: Access to Mastra instance (agents, tools, other workflows)
|
|
5296
5285
|
- \`getStepResult(stepInstance)\`: Get results from previous steps
|
|
5297
5286
|
- \`getInitData()\`: Access original workflow input data
|
|
5298
|
-
- \`
|
|
5287
|
+
- \`requestContext\`: Runtime dependency injection context
|
|
5299
5288
|
- \`runCount\`: Number of times this step has run (useful for retries)
|
|
5300
5289
|
|
|
5301
5290
|
### **\u{1F504} CONTROL FLOW METHODS**
|
|
@@ -5374,10 +5363,10 @@ const toolStep = createStep(myTool);
|
|
|
5374
5363
|
|
|
5375
5364
|
// Method 2: Call tool in execute function
|
|
5376
5365
|
const step = createStep({
|
|
5377
|
-
execute: async ({ inputData,
|
|
5366
|
+
execute: async ({ inputData, requestContext }) => {
|
|
5378
5367
|
const result = await myTool.execute({
|
|
5379
5368
|
context: inputData,
|
|
5380
|
-
|
|
5369
|
+
requestContext
|
|
5381
5370
|
});
|
|
5382
5371
|
return result;
|
|
5383
5372
|
}
|
|
@@ -5469,7 +5458,7 @@ export const mastra = new Mastra({
|
|
|
5469
5458
|
**Running Workflows:**
|
|
5470
5459
|
\`\`\`typescript
|
|
5471
5460
|
// Create and start run
|
|
5472
|
-
const run = await workflow.
|
|
5461
|
+
const run = await workflow.createRun();
|
|
5473
5462
|
const result = await run.start({ inputData: {...} });
|
|
5474
5463
|
|
|
5475
5464
|
// Stream execution for real-time monitoring
|
|
@@ -5493,7 +5482,7 @@ run.watch((event) => console.log(event));
|
|
|
5493
5482
|
- Use workflows as steps: \`.then(otherWorkflow)\`
|
|
5494
5483
|
- Enable complex workflow composition
|
|
5495
5484
|
|
|
5496
|
-
**
|
|
5485
|
+
**Request Context:**
|
|
5497
5486
|
- Pass shared data across all steps
|
|
5498
5487
|
- Enable dependency injection patterns
|
|
5499
5488
|
|
|
@@ -5666,11 +5655,11 @@ var restrictedTaskManager = createTool({
|
|
|
5666
5655
|
),
|
|
5667
5656
|
message: z.string()
|
|
5668
5657
|
}),
|
|
5669
|
-
execute: async (
|
|
5658
|
+
execute: async (input) => {
|
|
5670
5659
|
const adaptedContext = {
|
|
5671
|
-
...
|
|
5672
|
-
action:
|
|
5673
|
-
tasks:
|
|
5660
|
+
...input,
|
|
5661
|
+
action: input.action,
|
|
5662
|
+
tasks: input.tasks?.map((task) => ({
|
|
5674
5663
|
...task,
|
|
5675
5664
|
priority: task.priority || "medium"
|
|
5676
5665
|
}))
|
|
@@ -5685,7 +5674,7 @@ var workflowDiscoveryStep = createStep({
|
|
|
5685
5674
|
description: "Discover existing workflows in the project",
|
|
5686
5675
|
inputSchema: WorkflowBuilderInputSchema,
|
|
5687
5676
|
outputSchema: WorkflowDiscoveryResultSchema,
|
|
5688
|
-
execute: async ({ inputData,
|
|
5677
|
+
execute: async ({ inputData, requestContext: _requestContext }) => {
|
|
5689
5678
|
console.info("Starting workflow discovery...");
|
|
5690
5679
|
const { projectPath = process.cwd() } = inputData;
|
|
5691
5680
|
try {
|
|
@@ -5744,7 +5733,7 @@ var projectDiscoveryStep = createStep({
|
|
|
5744
5733
|
description: "Analyze the project structure and setup",
|
|
5745
5734
|
inputSchema: WorkflowDiscoveryResultSchema,
|
|
5746
5735
|
outputSchema: ProjectDiscoveryResultSchema,
|
|
5747
|
-
execute: async ({ inputData: _inputData,
|
|
5736
|
+
execute: async ({ inputData: _inputData, requestContext: _requestContext }) => {
|
|
5748
5737
|
console.info("Starting project discovery...");
|
|
5749
5738
|
try {
|
|
5750
5739
|
const projectPath = process.cwd();
|
|
@@ -5806,10 +5795,10 @@ var workflowResearchStep = createStep({
|
|
|
5806
5795
|
description: "Research Mastra workflows and gather relevant documentation",
|
|
5807
5796
|
inputSchema: ProjectDiscoveryResultSchema,
|
|
5808
5797
|
outputSchema: WorkflowResearchResultSchema,
|
|
5809
|
-
execute: async ({ inputData,
|
|
5798
|
+
execute: async ({ inputData, requestContext }) => {
|
|
5810
5799
|
console.info("Starting workflow research...");
|
|
5811
5800
|
try {
|
|
5812
|
-
const model = await resolveModel({
|
|
5801
|
+
const model = await resolveModel({ requestContext });
|
|
5813
5802
|
const researchAgent = new Agent({
|
|
5814
5803
|
model,
|
|
5815
5804
|
instructions: workflowBuilderPrompts.researchAgent.instructions,
|
|
@@ -5821,8 +5810,10 @@ var workflowResearchStep = createStep({
|
|
|
5821
5810
|
dependencies: inputData.dependencies,
|
|
5822
5811
|
hasWorkflowsDir: inputData.structure.hasWorkflowsDir
|
|
5823
5812
|
});
|
|
5824
|
-
const result = await researchAgent.
|
|
5825
|
-
|
|
5813
|
+
const result = await researchAgent.generate(researchPrompt, {
|
|
5814
|
+
structuredOutput: {
|
|
5815
|
+
schema: WorkflowResearchResultSchema
|
|
5816
|
+
}
|
|
5826
5817
|
// stopWhen: stepCountIs(10),
|
|
5827
5818
|
});
|
|
5828
5819
|
const researchResult = await result.object;
|
|
@@ -5873,7 +5864,7 @@ var taskExecutionStep = createStep({
|
|
|
5873
5864
|
outputSchema: TaskExecutionResultSchema,
|
|
5874
5865
|
suspendSchema: TaskExecutionSuspendSchema,
|
|
5875
5866
|
resumeSchema: TaskExecutionResumeSchema,
|
|
5876
|
-
execute: async ({ inputData, resumeData, suspend,
|
|
5867
|
+
execute: async ({ inputData, resumeData, suspend, requestContext }) => {
|
|
5877
5868
|
const {
|
|
5878
5869
|
action,
|
|
5879
5870
|
workflowName,
|
|
@@ -5888,7 +5879,7 @@ var taskExecutionStep = createStep({
|
|
|
5888
5879
|
console.info(`Starting task execution for ${action}ing workflow: ${workflowName}`);
|
|
5889
5880
|
console.info(`Executing ${tasks.length} tasks using AgentBuilder stream...`);
|
|
5890
5881
|
try {
|
|
5891
|
-
const model = await resolveModel({
|
|
5882
|
+
const model = await resolveModel({ requestContext });
|
|
5892
5883
|
const currentProjectPath = projectPath || process.cwd();
|
|
5893
5884
|
console.info("Pre-populating taskManager with planned tasks...");
|
|
5894
5885
|
const taskManagerContext = {
|
|
@@ -5933,18 +5924,11 @@ ${workflowBuilderPrompts.validation.instructions}`
|
|
|
5933
5924
|
tasks,
|
|
5934
5925
|
resumeData
|
|
5935
5926
|
});
|
|
5936
|
-
const originalInstructions = await executionAgent.getInstructions({
|
|
5937
|
-
const additionalInstructions = executionAgent.instructions;
|
|
5938
|
-
let enhancedInstructions = originalInstructions;
|
|
5939
|
-
if (additionalInstructions) {
|
|
5940
|
-
enhancedInstructions = `${originalInstructions}
|
|
5941
|
-
|
|
5942
|
-
${additionalInstructions}`;
|
|
5943
|
-
}
|
|
5927
|
+
const originalInstructions = await executionAgent.getInstructions({ requestContext });
|
|
5944
5928
|
const enhancedOptions = {
|
|
5945
5929
|
stopWhen: stepCountIs(100),
|
|
5946
5930
|
temperature: 0.3,
|
|
5947
|
-
instructions:
|
|
5931
|
+
instructions: originalInstructions
|
|
5948
5932
|
};
|
|
5949
5933
|
let finalResult = null;
|
|
5950
5934
|
let allTasksCompleted = false;
|
|
@@ -5973,7 +5957,7 @@ ${additionalInstructions}`;
|
|
|
5973
5957
|
})}
|
|
5974
5958
|
|
|
5975
5959
|
${workflowBuilderPrompts.validation.instructions}`;
|
|
5976
|
-
const stream = await executionAgent.
|
|
5960
|
+
const stream = await executionAgent.stream(iterationPrompt, {
|
|
5977
5961
|
structuredOutput: {
|
|
5978
5962
|
schema: TaskExecutionIterationInputSchema(tasks.length),
|
|
5979
5963
|
model
|