@agentforge/patterns 0.6.4 → 0.7.0
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.cjs +193 -220
- package/dist/index.js +193 -220
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -138,15 +138,46 @@ var ScratchpadEntrySchema = import_zod.z.object({
|
|
|
138
138
|
});
|
|
139
139
|
|
|
140
140
|
// src/react/state.ts
|
|
141
|
-
var
|
|
141
|
+
var import_zod3 = require("zod");
|
|
142
142
|
var import_core = require("@agentforge/core");
|
|
143
|
+
|
|
144
|
+
// src/shared/state-fields.ts
|
|
145
|
+
var import_zod2 = require("zod");
|
|
146
|
+
var iterationField = {
|
|
147
|
+
schema: import_zod2.z.number().int().nonnegative(),
|
|
148
|
+
reducer: (left, right) => left + right,
|
|
149
|
+
default: () => 0,
|
|
150
|
+
description: "Current iteration number"
|
|
151
|
+
};
|
|
152
|
+
function maxIterationsField(defaultValue) {
|
|
153
|
+
return {
|
|
154
|
+
schema: import_zod2.z.number().int().positive(),
|
|
155
|
+
default: () => defaultValue,
|
|
156
|
+
description: "Maximum number of iterations allowed"
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
var errorField = {
|
|
160
|
+
schema: import_zod2.z.string().optional(),
|
|
161
|
+
description: "Error message if execution failed"
|
|
162
|
+
};
|
|
163
|
+
var responseField = {
|
|
164
|
+
schema: import_zod2.z.string().optional(),
|
|
165
|
+
description: "Final response after completion"
|
|
166
|
+
};
|
|
167
|
+
var inputField = {
|
|
168
|
+
schema: import_zod2.z.string(),
|
|
169
|
+
default: () => "",
|
|
170
|
+
description: "Original user input or query"
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// src/react/state.ts
|
|
143
174
|
var ReActStateConfig = {
|
|
144
175
|
/**
|
|
145
176
|
* Conversation messages
|
|
146
177
|
* Accumulates all messages in the conversation
|
|
147
178
|
*/
|
|
148
179
|
messages: {
|
|
149
|
-
schema:
|
|
180
|
+
schema: import_zod3.z.array(MessageSchema),
|
|
150
181
|
reducer: (left, right) => [...left, ...right],
|
|
151
182
|
default: () => [],
|
|
152
183
|
description: "Conversation message history"
|
|
@@ -156,7 +187,7 @@ var ReActStateConfig = {
|
|
|
156
187
|
* Accumulates all reasoning steps the agent takes
|
|
157
188
|
*/
|
|
158
189
|
thoughts: {
|
|
159
|
-
schema:
|
|
190
|
+
schema: import_zod3.z.array(ThoughtSchema),
|
|
160
191
|
reducer: (left, right) => [...left, ...right],
|
|
161
192
|
default: () => [],
|
|
162
193
|
description: "Agent reasoning steps"
|
|
@@ -166,7 +197,7 @@ var ReActStateConfig = {
|
|
|
166
197
|
* Accumulates all tool calls made by the agent
|
|
167
198
|
*/
|
|
168
199
|
actions: {
|
|
169
|
-
schema:
|
|
200
|
+
schema: import_zod3.z.array(ToolCallSchema),
|
|
170
201
|
reducer: (left, right) => [...left, ...right],
|
|
171
202
|
default: () => [],
|
|
172
203
|
description: "Tool calls made by the agent"
|
|
@@ -176,7 +207,7 @@ var ReActStateConfig = {
|
|
|
176
207
|
* Accumulates all observations from tool executions
|
|
177
208
|
*/
|
|
178
209
|
observations: {
|
|
179
|
-
schema:
|
|
210
|
+
schema: import_zod3.z.array(ToolResultSchema),
|
|
180
211
|
reducer: (left, right) => [...left, ...right],
|
|
181
212
|
default: () => [],
|
|
182
213
|
description: "Results from tool executions"
|
|
@@ -186,7 +217,7 @@ var ReActStateConfig = {
|
|
|
186
217
|
* Accumulates step-by-step reasoning process
|
|
187
218
|
*/
|
|
188
219
|
scratchpad: {
|
|
189
|
-
schema:
|
|
220
|
+
schema: import_zod3.z.array(ScratchpadEntrySchema),
|
|
190
221
|
reducer: (left, right) => [...left, ...right],
|
|
191
222
|
default: () => [],
|
|
192
223
|
description: "Intermediate reasoning scratchpad"
|
|
@@ -195,27 +226,19 @@ var ReActStateConfig = {
|
|
|
195
226
|
* Current iteration count
|
|
196
227
|
* Tracks how many thought-action-observation loops have been executed
|
|
197
228
|
*/
|
|
198
|
-
iteration:
|
|
199
|
-
schema: import_zod2.z.number(),
|
|
200
|
-
reducer: (left, right) => left + right,
|
|
201
|
-
default: () => 0,
|
|
202
|
-
description: "Current iteration count"
|
|
203
|
-
},
|
|
229
|
+
iteration: iterationField,
|
|
204
230
|
/**
|
|
205
231
|
* Whether the agent should continue iterating
|
|
206
232
|
*/
|
|
207
233
|
shouldContinue: {
|
|
208
|
-
schema:
|
|
234
|
+
schema: import_zod3.z.boolean().optional(),
|
|
209
235
|
default: () => true,
|
|
210
236
|
description: "Whether to continue the ReAct loop"
|
|
211
237
|
},
|
|
212
238
|
/**
|
|
213
239
|
* Final response (if any)
|
|
214
240
|
*/
|
|
215
|
-
response:
|
|
216
|
-
schema: import_zod2.z.string().optional(),
|
|
217
|
-
description: "Final response from the agent"
|
|
218
|
-
}
|
|
241
|
+
response: responseField
|
|
219
242
|
};
|
|
220
243
|
var ReActState = (0, import_core.createStateAnnotation)(ReActStateConfig);
|
|
221
244
|
|
|
@@ -279,6 +302,24 @@ function buildDeduplicationMetrics(toolsExecuted, duplicatesSkipped, totalObserv
|
|
|
279
302
|
};
|
|
280
303
|
}
|
|
281
304
|
|
|
305
|
+
// src/shared/error-handling.ts
|
|
306
|
+
function isGraphInterrupt(error) {
|
|
307
|
+
return error !== null && typeof error === "object" && "constructor" in error && error.constructor.name === "GraphInterrupt";
|
|
308
|
+
}
|
|
309
|
+
function handleNodeError(error, context, verbose = false) {
|
|
310
|
+
if (isGraphInterrupt(error)) {
|
|
311
|
+
throw error;
|
|
312
|
+
}
|
|
313
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
314
|
+
if (verbose) {
|
|
315
|
+
console.error(`[${context}] Error:`, errorMessage);
|
|
316
|
+
if (error instanceof Error && error.stack) {
|
|
317
|
+
console.error(`[${context}] Stack:`, error.stack);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return errorMessage;
|
|
321
|
+
}
|
|
322
|
+
|
|
282
323
|
// src/react/nodes.ts
|
|
283
324
|
var reasoningLogger = createPatternLogger("agentforge:patterns:react:reasoning");
|
|
284
325
|
var actionLogger = createPatternLogger("agentforge:patterns:react:action");
|
|
@@ -441,10 +482,7 @@ function createActionNode(tools, verbose = false, enableDeduplication = true) {
|
|
|
441
482
|
executionCache.set(cacheKey, observation);
|
|
442
483
|
}
|
|
443
484
|
} catch (error) {
|
|
444
|
-
|
|
445
|
-
throw error;
|
|
446
|
-
}
|
|
447
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
485
|
+
const errorMessage = handleNodeError(error, `action:${action.name}`, false);
|
|
448
486
|
actionLogger.error("Tool execution failed", {
|
|
449
487
|
toolName: action.name,
|
|
450
488
|
error: errorMessage,
|
|
@@ -683,34 +721,34 @@ function createReActAgentBuilder() {
|
|
|
683
721
|
var import_langgraph2 = require("@langchain/langgraph");
|
|
684
722
|
|
|
685
723
|
// src/plan-execute/state.ts
|
|
686
|
-
var
|
|
724
|
+
var import_zod5 = require("zod");
|
|
687
725
|
var import_core5 = require("@agentforge/core");
|
|
688
726
|
|
|
689
727
|
// src/plan-execute/schemas.ts
|
|
690
|
-
var
|
|
691
|
-
var PlanStepSchema =
|
|
728
|
+
var import_zod4 = require("zod");
|
|
729
|
+
var PlanStepSchema = import_zod4.z.object({
|
|
692
730
|
/**
|
|
693
731
|
* Unique identifier for the step
|
|
694
732
|
*/
|
|
695
|
-
id:
|
|
733
|
+
id: import_zod4.z.string().describe("Unique identifier for the step"),
|
|
696
734
|
/**
|
|
697
735
|
* Description of what this step should accomplish
|
|
698
736
|
*/
|
|
699
|
-
description:
|
|
737
|
+
description: import_zod4.z.string().describe("Description of what this step should accomplish"),
|
|
700
738
|
/**
|
|
701
739
|
* Optional dependencies on other steps (by ID)
|
|
702
740
|
*/
|
|
703
|
-
dependencies:
|
|
741
|
+
dependencies: import_zod4.z.array(import_zod4.z.string()).optional().describe("IDs of steps that must complete before this one"),
|
|
704
742
|
/**
|
|
705
743
|
* Optional tool to use for this step
|
|
706
744
|
*/
|
|
707
|
-
tool:
|
|
745
|
+
tool: import_zod4.z.string().optional().describe("Name of the tool to use for this step"),
|
|
708
746
|
/**
|
|
709
747
|
* Optional arguments for the tool
|
|
710
748
|
*/
|
|
711
|
-
args:
|
|
749
|
+
args: import_zod4.z.record(import_zod4.z.any()).optional().describe("Arguments to pass to the tool")
|
|
712
750
|
});
|
|
713
|
-
var CompletedStepSchema =
|
|
751
|
+
var CompletedStepSchema = import_zod4.z.object({
|
|
714
752
|
/**
|
|
715
753
|
* The step that was executed
|
|
716
754
|
*/
|
|
@@ -718,53 +756,53 @@ var CompletedStepSchema = import_zod3.z.object({
|
|
|
718
756
|
/**
|
|
719
757
|
* The result of executing the step
|
|
720
758
|
*/
|
|
721
|
-
result:
|
|
759
|
+
result: import_zod4.z.any().describe("The result of executing the step"),
|
|
722
760
|
/**
|
|
723
761
|
* Whether the step succeeded
|
|
724
762
|
*/
|
|
725
|
-
success:
|
|
763
|
+
success: import_zod4.z.boolean().describe("Whether the step succeeded"),
|
|
726
764
|
/**
|
|
727
765
|
* Optional error message if the step failed
|
|
728
766
|
*/
|
|
729
|
-
error:
|
|
767
|
+
error: import_zod4.z.string().optional().describe("Error message if the step failed"),
|
|
730
768
|
/**
|
|
731
769
|
* Timestamp when the step was completed
|
|
732
770
|
*/
|
|
733
|
-
timestamp:
|
|
771
|
+
timestamp: import_zod4.z.string().datetime().describe("ISO timestamp when the step was completed")
|
|
734
772
|
});
|
|
735
|
-
var PlanSchema =
|
|
773
|
+
var PlanSchema = import_zod4.z.object({
|
|
736
774
|
/**
|
|
737
775
|
* List of steps in the plan
|
|
738
776
|
*/
|
|
739
|
-
steps:
|
|
777
|
+
steps: import_zod4.z.array(PlanStepSchema).describe("List of steps in the plan"),
|
|
740
778
|
/**
|
|
741
779
|
* Overall goal of the plan
|
|
742
780
|
*/
|
|
743
|
-
goal:
|
|
781
|
+
goal: import_zod4.z.string().describe("Overall goal of the plan"),
|
|
744
782
|
/**
|
|
745
783
|
* Timestamp when the plan was created
|
|
746
784
|
*/
|
|
747
|
-
createdAt:
|
|
785
|
+
createdAt: import_zod4.z.string().datetime().describe("ISO timestamp when the plan was created"),
|
|
748
786
|
/**
|
|
749
787
|
* Optional confidence score (0-1)
|
|
750
788
|
*/
|
|
751
|
-
confidence:
|
|
789
|
+
confidence: import_zod4.z.number().min(0).max(1).optional().describe("Confidence score for the plan (0-1)")
|
|
752
790
|
});
|
|
753
|
-
var ReplanDecisionSchema =
|
|
791
|
+
var ReplanDecisionSchema = import_zod4.z.object({
|
|
754
792
|
/**
|
|
755
793
|
* Whether to replan
|
|
756
794
|
*/
|
|
757
|
-
shouldReplan:
|
|
795
|
+
shouldReplan: import_zod4.z.boolean().describe("Whether to replan based on current results"),
|
|
758
796
|
/**
|
|
759
797
|
* Reason for the decision
|
|
760
798
|
*/
|
|
761
|
-
reason:
|
|
799
|
+
reason: import_zod4.z.string().describe("Reason for the replan decision"),
|
|
762
800
|
/**
|
|
763
801
|
* Optional new goal if replanning
|
|
764
802
|
*/
|
|
765
|
-
newGoal:
|
|
803
|
+
newGoal: import_zod4.z.string().optional().describe("Updated goal if replanning")
|
|
766
804
|
});
|
|
767
|
-
var ExecutionStatusSchema =
|
|
805
|
+
var ExecutionStatusSchema = import_zod4.z.enum([
|
|
768
806
|
"planning",
|
|
769
807
|
"executing",
|
|
770
808
|
"replanning",
|
|
@@ -777,11 +815,7 @@ var PlanExecuteStateConfig = {
|
|
|
777
815
|
/**
|
|
778
816
|
* Original user input/query
|
|
779
817
|
*/
|
|
780
|
-
input:
|
|
781
|
-
schema: import_zod4.z.string(),
|
|
782
|
-
default: () => "",
|
|
783
|
-
description: "Original user input or query"
|
|
784
|
-
},
|
|
818
|
+
input: inputField,
|
|
785
819
|
/**
|
|
786
820
|
* The current plan
|
|
787
821
|
*/
|
|
@@ -794,7 +828,7 @@ var PlanExecuteStateConfig = {
|
|
|
794
828
|
* Accumulates all completed steps
|
|
795
829
|
*/
|
|
796
830
|
pastSteps: {
|
|
797
|
-
schema:
|
|
831
|
+
schema: import_zod5.z.array(CompletedStepSchema),
|
|
798
832
|
reducer: (left, right) => [...left, ...right],
|
|
799
833
|
default: () => [],
|
|
800
834
|
description: "Completed steps with their results"
|
|
@@ -803,7 +837,7 @@ var PlanExecuteStateConfig = {
|
|
|
803
837
|
* Index of the current step being executed
|
|
804
838
|
*/
|
|
805
839
|
currentStepIndex: {
|
|
806
|
-
schema:
|
|
840
|
+
schema: import_zod5.z.number().int().nonnegative().optional(),
|
|
807
841
|
description: "Index of the current step being executed"
|
|
808
842
|
},
|
|
809
843
|
/**
|
|
@@ -817,34 +851,19 @@ var PlanExecuteStateConfig = {
|
|
|
817
851
|
/**
|
|
818
852
|
* Final response
|
|
819
853
|
*/
|
|
820
|
-
response:
|
|
821
|
-
schema: import_zod4.z.string().optional(),
|
|
822
|
-
description: "Final response after plan execution"
|
|
823
|
-
},
|
|
854
|
+
response: responseField,
|
|
824
855
|
/**
|
|
825
856
|
* Error message if execution failed
|
|
826
857
|
*/
|
|
827
|
-
error:
|
|
828
|
-
schema: import_zod4.z.string().optional(),
|
|
829
|
-
description: "Error message if execution failed"
|
|
830
|
-
},
|
|
858
|
+
error: errorField,
|
|
831
859
|
/**
|
|
832
860
|
* Iteration counter for replanning
|
|
833
861
|
*/
|
|
834
|
-
iteration:
|
|
835
|
-
schema: import_zod4.z.number().int().nonnegative(),
|
|
836
|
-
reducer: (left, right) => left + right,
|
|
837
|
-
default: () => 0,
|
|
838
|
-
description: "Number of planning iterations"
|
|
839
|
-
},
|
|
862
|
+
iteration: iterationField,
|
|
840
863
|
/**
|
|
841
864
|
* Maximum iterations allowed
|
|
842
865
|
*/
|
|
843
|
-
maxIterations:
|
|
844
|
-
schema: import_zod4.z.number().int().positive(),
|
|
845
|
-
default: () => 5,
|
|
846
|
-
description: "Maximum number of planning iterations allowed"
|
|
847
|
-
}
|
|
866
|
+
maxIterations: maxIterationsField(5)
|
|
848
867
|
};
|
|
849
868
|
var PlanExecuteState = (0, import_core5.createStateAnnotation)(PlanExecuteStateConfig);
|
|
850
869
|
|
|
@@ -1077,11 +1096,8 @@ function createExecutorNode(config) {
|
|
|
1077
1096
|
result = { message: "Step completed without tool execution" };
|
|
1078
1097
|
}
|
|
1079
1098
|
} catch (execError) {
|
|
1080
|
-
|
|
1081
|
-
throw execError;
|
|
1082
|
-
}
|
|
1099
|
+
error = handleNodeError(execError, `executor:${currentStep.description}`, false);
|
|
1083
1100
|
success = false;
|
|
1084
|
-
error = execError instanceof Error ? execError.message : "Unknown execution error";
|
|
1085
1101
|
result = null;
|
|
1086
1102
|
executorLogger.warn("Step execution failed", {
|
|
1087
1103
|
stepId: currentStep.id,
|
|
@@ -1284,46 +1300,46 @@ function createPlanExecuteAgent(config) {
|
|
|
1284
1300
|
}
|
|
1285
1301
|
|
|
1286
1302
|
// src/reflection/state.ts
|
|
1287
|
-
var
|
|
1303
|
+
var import_zod7 = require("zod");
|
|
1288
1304
|
var import_core6 = require("@agentforge/core");
|
|
1289
1305
|
|
|
1290
1306
|
// src/reflection/schemas.ts
|
|
1291
|
-
var
|
|
1292
|
-
var ReflectionSchema =
|
|
1307
|
+
var import_zod6 = require("zod");
|
|
1308
|
+
var ReflectionSchema = import_zod6.z.object({
|
|
1293
1309
|
/**
|
|
1294
1310
|
* The critique or feedback on the current response
|
|
1295
1311
|
*/
|
|
1296
|
-
critique:
|
|
1312
|
+
critique: import_zod6.z.string().describe("Critique or feedback on the current response"),
|
|
1297
1313
|
/**
|
|
1298
1314
|
* Specific issues identified
|
|
1299
1315
|
*/
|
|
1300
|
-
issues:
|
|
1316
|
+
issues: import_zod6.z.array(import_zod6.z.string()).describe("Specific issues or problems identified"),
|
|
1301
1317
|
/**
|
|
1302
1318
|
* Suggestions for improvement
|
|
1303
1319
|
*/
|
|
1304
|
-
suggestions:
|
|
1320
|
+
suggestions: import_zod6.z.array(import_zod6.z.string()).describe("Suggestions for improving the response"),
|
|
1305
1321
|
/**
|
|
1306
1322
|
* Quality score (0-10)
|
|
1307
1323
|
*/
|
|
1308
|
-
score:
|
|
1324
|
+
score: import_zod6.z.number().min(0).max(10).optional().describe("Quality score from 0 to 10"),
|
|
1309
1325
|
/**
|
|
1310
1326
|
* Whether the response meets quality standards
|
|
1311
1327
|
*/
|
|
1312
|
-
meetsStandards:
|
|
1328
|
+
meetsStandards: import_zod6.z.boolean().describe("Whether the response meets quality standards"),
|
|
1313
1329
|
/**
|
|
1314
1330
|
* Timestamp of the reflection
|
|
1315
1331
|
*/
|
|
1316
|
-
timestamp:
|
|
1332
|
+
timestamp: import_zod6.z.date().optional().describe("When this reflection was created")
|
|
1317
1333
|
});
|
|
1318
|
-
var RevisionSchema =
|
|
1334
|
+
var RevisionSchema = import_zod6.z.object({
|
|
1319
1335
|
/**
|
|
1320
1336
|
* The revised content
|
|
1321
1337
|
*/
|
|
1322
|
-
content:
|
|
1338
|
+
content: import_zod6.z.string().describe("The revised content"),
|
|
1323
1339
|
/**
|
|
1324
1340
|
* Which iteration this revision is from
|
|
1325
1341
|
*/
|
|
1326
|
-
iteration:
|
|
1342
|
+
iteration: import_zod6.z.number().int().nonnegative().describe("Iteration number"),
|
|
1327
1343
|
/**
|
|
1328
1344
|
* The reflection that prompted this revision
|
|
1329
1345
|
*/
|
|
@@ -1331,9 +1347,9 @@ var RevisionSchema = import_zod5.z.object({
|
|
|
1331
1347
|
/**
|
|
1332
1348
|
* Timestamp of the revision
|
|
1333
1349
|
*/
|
|
1334
|
-
timestamp:
|
|
1350
|
+
timestamp: import_zod6.z.date().optional().describe("When this revision was created")
|
|
1335
1351
|
});
|
|
1336
|
-
var ReflectionStatusSchema =
|
|
1352
|
+
var ReflectionStatusSchema = import_zod6.z.enum([
|
|
1337
1353
|
"generating",
|
|
1338
1354
|
// Initial generation
|
|
1339
1355
|
"reflecting",
|
|
@@ -1345,25 +1361,25 @@ var ReflectionStatusSchema = import_zod5.z.enum([
|
|
|
1345
1361
|
"failed"
|
|
1346
1362
|
// Max iterations reached without meeting standards
|
|
1347
1363
|
]);
|
|
1348
|
-
var QualityCriteriaSchema =
|
|
1364
|
+
var QualityCriteriaSchema = import_zod6.z.object({
|
|
1349
1365
|
/**
|
|
1350
1366
|
* Minimum quality score required (0-10)
|
|
1351
1367
|
*/
|
|
1352
|
-
minScore:
|
|
1368
|
+
minScore: import_zod6.z.number().min(0).max(10).default(7).describe("Minimum quality score required"),
|
|
1353
1369
|
/**
|
|
1354
1370
|
* Specific criteria to evaluate
|
|
1355
1371
|
*/
|
|
1356
|
-
criteria:
|
|
1372
|
+
criteria: import_zod6.z.array(import_zod6.z.string()).optional().describe("Specific criteria to evaluate"),
|
|
1357
1373
|
/**
|
|
1358
1374
|
* Whether all criteria must be met
|
|
1359
1375
|
*/
|
|
1360
|
-
requireAll:
|
|
1376
|
+
requireAll: import_zod6.z.boolean().default(true).describe("Whether all criteria must be met")
|
|
1361
1377
|
});
|
|
1362
|
-
var ReflectionConfigSchema =
|
|
1378
|
+
var ReflectionConfigSchema = import_zod6.z.object({
|
|
1363
1379
|
/**
|
|
1364
1380
|
* Maximum number of reflection iterations
|
|
1365
1381
|
*/
|
|
1366
|
-
maxIterations:
|
|
1382
|
+
maxIterations: import_zod6.z.number().int().positive().default(3).describe("Maximum reflection iterations"),
|
|
1367
1383
|
/**
|
|
1368
1384
|
* Quality criteria for completion
|
|
1369
1385
|
*/
|
|
@@ -1371,7 +1387,7 @@ var ReflectionConfigSchema = import_zod5.z.object({
|
|
|
1371
1387
|
/**
|
|
1372
1388
|
* Whether to include previous reflections in context
|
|
1373
1389
|
*/
|
|
1374
|
-
includeHistory:
|
|
1390
|
+
includeHistory: import_zod6.z.boolean().default(true).describe("Include previous reflections in context")
|
|
1375
1391
|
});
|
|
1376
1392
|
|
|
1377
1393
|
// src/reflection/state.ts
|
|
@@ -1379,16 +1395,12 @@ var ReflectionStateConfig = {
|
|
|
1379
1395
|
/**
|
|
1380
1396
|
* Original user input/task
|
|
1381
1397
|
*/
|
|
1382
|
-
input:
|
|
1383
|
-
schema: import_zod6.z.string(),
|
|
1384
|
-
default: () => "",
|
|
1385
|
-
description: "Original user input or task"
|
|
1386
|
-
},
|
|
1398
|
+
input: inputField,
|
|
1387
1399
|
/**
|
|
1388
1400
|
* Current response/output
|
|
1389
1401
|
*/
|
|
1390
1402
|
currentResponse: {
|
|
1391
|
-
schema:
|
|
1403
|
+
schema: import_zod7.z.string().optional(),
|
|
1392
1404
|
description: "Current response or output"
|
|
1393
1405
|
},
|
|
1394
1406
|
/**
|
|
@@ -1396,7 +1408,7 @@ var ReflectionStateConfig = {
|
|
|
1396
1408
|
* Accumulates all reflections
|
|
1397
1409
|
*/
|
|
1398
1410
|
reflections: {
|
|
1399
|
-
schema:
|
|
1411
|
+
schema: import_zod7.z.array(ReflectionSchema),
|
|
1400
1412
|
reducer: (left, right) => [...left, ...right],
|
|
1401
1413
|
default: () => [],
|
|
1402
1414
|
description: "History of all reflections and critiques"
|
|
@@ -1406,7 +1418,7 @@ var ReflectionStateConfig = {
|
|
|
1406
1418
|
* Accumulates all revisions
|
|
1407
1419
|
*/
|
|
1408
1420
|
revisions: {
|
|
1409
|
-
schema:
|
|
1421
|
+
schema: import_zod7.z.array(RevisionSchema),
|
|
1410
1422
|
reducer: (left, right) => [...left, ...right],
|
|
1411
1423
|
default: () => [],
|
|
1412
1424
|
description: "History of all revisions"
|
|
@@ -1414,12 +1426,7 @@ var ReflectionStateConfig = {
|
|
|
1414
1426
|
/**
|
|
1415
1427
|
* Current iteration number
|
|
1416
1428
|
*/
|
|
1417
|
-
iteration:
|
|
1418
|
-
schema: import_zod6.z.number().int().nonnegative(),
|
|
1419
|
-
reducer: (left, right) => left + right,
|
|
1420
|
-
default: () => 0,
|
|
1421
|
-
description: "Current iteration number"
|
|
1422
|
-
},
|
|
1429
|
+
iteration: iterationField,
|
|
1423
1430
|
/**
|
|
1424
1431
|
* Current status
|
|
1425
1432
|
*/
|
|
@@ -1438,25 +1445,15 @@ var ReflectionStateConfig = {
|
|
|
1438
1445
|
/**
|
|
1439
1446
|
* Maximum iterations allowed
|
|
1440
1447
|
*/
|
|
1441
|
-
maxIterations:
|
|
1442
|
-
schema: import_zod6.z.number().int().positive(),
|
|
1443
|
-
default: () => 3,
|
|
1444
|
-
description: "Maximum number of reflection iterations allowed"
|
|
1445
|
-
},
|
|
1448
|
+
maxIterations: maxIterationsField(3),
|
|
1446
1449
|
/**
|
|
1447
1450
|
* Final response (when completed)
|
|
1448
1451
|
*/
|
|
1449
|
-
response:
|
|
1450
|
-
schema: import_zod6.z.string().optional(),
|
|
1451
|
-
description: "Final response after reflection process"
|
|
1452
|
-
},
|
|
1452
|
+
response: responseField,
|
|
1453
1453
|
/**
|
|
1454
1454
|
* Error message if failed
|
|
1455
1455
|
*/
|
|
1456
|
-
error:
|
|
1457
|
-
schema: import_zod6.z.string().optional(),
|
|
1458
|
-
description: "Error message if reflection failed"
|
|
1459
|
-
}
|
|
1456
|
+
error: errorField
|
|
1460
1457
|
};
|
|
1461
1458
|
var ReflectionState = (0, import_core6.createStateAnnotation)(ReflectionStateConfig);
|
|
1462
1459
|
|
|
@@ -1605,14 +1602,15 @@ ${lastReflection.critique}`;
|
|
|
1605
1602
|
iteration: 1
|
|
1606
1603
|
};
|
|
1607
1604
|
} catch (error) {
|
|
1605
|
+
const errorMessage = handleNodeError(error, "generator", false);
|
|
1608
1606
|
generatorLogger.error("Response generation failed", {
|
|
1609
1607
|
attempt: state.iteration + 1,
|
|
1610
|
-
error:
|
|
1608
|
+
error: errorMessage,
|
|
1611
1609
|
duration: Date.now() - startTime
|
|
1612
1610
|
});
|
|
1613
1611
|
return {
|
|
1614
1612
|
status: "failed",
|
|
1615
|
-
error:
|
|
1613
|
+
error: errorMessage
|
|
1616
1614
|
};
|
|
1617
1615
|
}
|
|
1618
1616
|
};
|
|
@@ -1694,14 +1692,15 @@ function createReflectorNode(config) {
|
|
|
1694
1692
|
status: reflection.meetsStandards ? "completed" : "revising"
|
|
1695
1693
|
};
|
|
1696
1694
|
} catch (error) {
|
|
1695
|
+
const errorMessage = handleNodeError(error, "reflector", false);
|
|
1697
1696
|
reflectorLogger.error("Reflection failed", {
|
|
1698
1697
|
attempt: state.iteration,
|
|
1699
|
-
error:
|
|
1698
|
+
error: errorMessage,
|
|
1700
1699
|
duration: Date.now() - startTime
|
|
1701
1700
|
});
|
|
1702
1701
|
return {
|
|
1703
1702
|
status: "failed",
|
|
1704
|
-
error:
|
|
1703
|
+
error: errorMessage
|
|
1705
1704
|
};
|
|
1706
1705
|
}
|
|
1707
1706
|
};
|
|
@@ -1762,14 +1761,15 @@ ${revisionsText}`;
|
|
|
1762
1761
|
iteration: 1
|
|
1763
1762
|
};
|
|
1764
1763
|
} catch (error) {
|
|
1764
|
+
const errorMessage = handleNodeError(error, "reviser", false);
|
|
1765
1765
|
reviserLogger.error("Revision failed", {
|
|
1766
1766
|
attempt: state.iteration,
|
|
1767
|
-
error:
|
|
1767
|
+
error: errorMessage,
|
|
1768
1768
|
duration: Date.now() - startTime
|
|
1769
1769
|
});
|
|
1770
1770
|
return {
|
|
1771
1771
|
status: "failed",
|
|
1772
|
-
error:
|
|
1772
|
+
error: errorMessage
|
|
1773
1773
|
};
|
|
1774
1774
|
}
|
|
1775
1775
|
};
|
|
@@ -1855,13 +1855,13 @@ function createReflectionAgent(config) {
|
|
|
1855
1855
|
}
|
|
1856
1856
|
|
|
1857
1857
|
// src/multi-agent/state.ts
|
|
1858
|
-
var
|
|
1858
|
+
var import_zod9 = require("zod");
|
|
1859
1859
|
var import_core7 = require("@agentforge/core");
|
|
1860
1860
|
|
|
1861
1861
|
// src/multi-agent/schemas.ts
|
|
1862
|
-
var
|
|
1863
|
-
var AgentRoleSchema =
|
|
1864
|
-
var MessageTypeSchema =
|
|
1862
|
+
var import_zod8 = require("zod");
|
|
1863
|
+
var AgentRoleSchema = import_zod8.z.enum(["supervisor", "worker"]);
|
|
1864
|
+
var MessageTypeSchema = import_zod8.z.enum([
|
|
1865
1865
|
"user_input",
|
|
1866
1866
|
// Initial user message
|
|
1867
1867
|
"task_assignment",
|
|
@@ -1875,11 +1875,11 @@ var MessageTypeSchema = import_zod7.z.enum([
|
|
|
1875
1875
|
"completion"
|
|
1876
1876
|
// Final completion message
|
|
1877
1877
|
]);
|
|
1878
|
-
var AgentMessageSchema =
|
|
1878
|
+
var AgentMessageSchema = import_zod8.z.object({
|
|
1879
1879
|
/**
|
|
1880
1880
|
* Unique identifier for the message
|
|
1881
1881
|
*/
|
|
1882
|
-
id:
|
|
1882
|
+
id: import_zod8.z.string().describe("Unique message identifier"),
|
|
1883
1883
|
/**
|
|
1884
1884
|
* Type of message
|
|
1885
1885
|
*/
|
|
@@ -1887,25 +1887,25 @@ var AgentMessageSchema = import_zod7.z.object({
|
|
|
1887
1887
|
/**
|
|
1888
1888
|
* Agent that sent the message
|
|
1889
1889
|
*/
|
|
1890
|
-
from:
|
|
1890
|
+
from: import_zod8.z.string().describe("Agent identifier that sent the message"),
|
|
1891
1891
|
/**
|
|
1892
1892
|
* Agent(s) that should receive the message
|
|
1893
1893
|
*/
|
|
1894
|
-
to:
|
|
1894
|
+
to: import_zod8.z.union([import_zod8.z.string(), import_zod8.z.array(import_zod8.z.string())]).describe("Target agent(s)"),
|
|
1895
1895
|
/**
|
|
1896
1896
|
* Message content
|
|
1897
1897
|
*/
|
|
1898
|
-
content:
|
|
1898
|
+
content: import_zod8.z.string().describe("Message content"),
|
|
1899
1899
|
/**
|
|
1900
1900
|
* Optional metadata
|
|
1901
1901
|
*/
|
|
1902
|
-
metadata:
|
|
1902
|
+
metadata: import_zod8.z.record(import_zod8.z.any()).optional().describe("Additional message metadata"),
|
|
1903
1903
|
/**
|
|
1904
1904
|
* Timestamp when message was created
|
|
1905
1905
|
*/
|
|
1906
|
-
timestamp:
|
|
1906
|
+
timestamp: import_zod8.z.number().describe("Timestamp when message was created")
|
|
1907
1907
|
});
|
|
1908
|
-
var RoutingStrategySchema =
|
|
1908
|
+
var RoutingStrategySchema = import_zod8.z.enum([
|
|
1909
1909
|
"llm-based",
|
|
1910
1910
|
// LLM decides which agent to route to
|
|
1911
1911
|
"rule-based",
|
|
@@ -1917,25 +1917,25 @@ var RoutingStrategySchema = import_zod7.z.enum([
|
|
|
1917
1917
|
"load-balanced"
|
|
1918
1918
|
// Route based on agent workload
|
|
1919
1919
|
]);
|
|
1920
|
-
var RoutingDecisionSchema =
|
|
1920
|
+
var RoutingDecisionSchema = import_zod8.z.object({
|
|
1921
1921
|
/**
|
|
1922
1922
|
* Target agent to route to (single agent routing)
|
|
1923
1923
|
* @deprecated Use targetAgents for parallel routing support
|
|
1924
1924
|
*/
|
|
1925
|
-
targetAgent:
|
|
1925
|
+
targetAgent: import_zod8.z.string().nullable().default(null).describe("Agent to route the task to (single routing)"),
|
|
1926
1926
|
/**
|
|
1927
1927
|
* Target agents to route to (parallel routing)
|
|
1928
1928
|
* When multiple agents are specified, they execute in parallel
|
|
1929
1929
|
*/
|
|
1930
|
-
targetAgents:
|
|
1930
|
+
targetAgents: import_zod8.z.array(import_zod8.z.string()).nullable().default(null).describe("Agents to route the task to (parallel routing)"),
|
|
1931
1931
|
/**
|
|
1932
1932
|
* Reasoning for the routing decision
|
|
1933
1933
|
*/
|
|
1934
|
-
reasoning:
|
|
1934
|
+
reasoning: import_zod8.z.string().default("").describe("Explanation for routing decision"),
|
|
1935
1935
|
/**
|
|
1936
1936
|
* Confidence in the routing decision (0-1)
|
|
1937
1937
|
*/
|
|
1938
|
-
confidence:
|
|
1938
|
+
confidence: import_zod8.z.number().min(0).max(1).default(0.8).describe("Confidence score"),
|
|
1939
1939
|
/**
|
|
1940
1940
|
* Strategy used for routing
|
|
1941
1941
|
*/
|
|
@@ -1943,86 +1943,86 @@ var RoutingDecisionSchema = import_zod7.z.object({
|
|
|
1943
1943
|
/**
|
|
1944
1944
|
* Timestamp of the routing decision
|
|
1945
1945
|
*/
|
|
1946
|
-
timestamp:
|
|
1946
|
+
timestamp: import_zod8.z.number().default(() => Date.now()).describe("Timestamp of the decision")
|
|
1947
1947
|
}).refine(
|
|
1948
1948
|
(data) => data.targetAgent || data.targetAgents && data.targetAgents.length > 0,
|
|
1949
1949
|
{ message: "Either targetAgent or targetAgents must be provided" }
|
|
1950
1950
|
);
|
|
1951
|
-
var WorkerCapabilitiesSchema =
|
|
1951
|
+
var WorkerCapabilitiesSchema = import_zod8.z.object({
|
|
1952
1952
|
/**
|
|
1953
1953
|
* Skills/capabilities the agent has
|
|
1954
1954
|
*/
|
|
1955
|
-
skills:
|
|
1955
|
+
skills: import_zod8.z.array(import_zod8.z.string()).describe("List of agent skills"),
|
|
1956
1956
|
/**
|
|
1957
1957
|
* Tools available to the agent
|
|
1958
1958
|
*/
|
|
1959
|
-
tools:
|
|
1959
|
+
tools: import_zod8.z.array(import_zod8.z.string()).describe("List of tool names available to agent"),
|
|
1960
1960
|
/**
|
|
1961
1961
|
* Whether the agent is currently available
|
|
1962
1962
|
*/
|
|
1963
|
-
available:
|
|
1963
|
+
available: import_zod8.z.boolean().default(true).describe("Whether agent is available"),
|
|
1964
1964
|
/**
|
|
1965
1965
|
* Current workload (number of active tasks)
|
|
1966
1966
|
*/
|
|
1967
|
-
currentWorkload:
|
|
1967
|
+
currentWorkload: import_zod8.z.number().int().nonnegative().default(0).describe("Current number of active tasks")
|
|
1968
1968
|
});
|
|
1969
|
-
var TaskAssignmentSchema =
|
|
1969
|
+
var TaskAssignmentSchema = import_zod8.z.object({
|
|
1970
1970
|
/**
|
|
1971
1971
|
* Unique assignment identifier
|
|
1972
1972
|
*/
|
|
1973
|
-
id:
|
|
1973
|
+
id: import_zod8.z.string().describe("Unique assignment identifier"),
|
|
1974
1974
|
/**
|
|
1975
1975
|
* Worker ID assigned to the task
|
|
1976
1976
|
*/
|
|
1977
|
-
workerId:
|
|
1977
|
+
workerId: import_zod8.z.string().describe("Worker identifier assigned to task"),
|
|
1978
1978
|
/**
|
|
1979
1979
|
* Task description
|
|
1980
1980
|
*/
|
|
1981
|
-
task:
|
|
1981
|
+
task: import_zod8.z.string().describe("Description of the task"),
|
|
1982
1982
|
/**
|
|
1983
1983
|
* Task priority (1-10, higher is more urgent)
|
|
1984
1984
|
*/
|
|
1985
|
-
priority:
|
|
1985
|
+
priority: import_zod8.z.number().int().min(1).max(10).default(5).describe("Task priority"),
|
|
1986
1986
|
/**
|
|
1987
1987
|
* Timestamp when task was assigned
|
|
1988
1988
|
*/
|
|
1989
|
-
assignedAt:
|
|
1989
|
+
assignedAt: import_zod8.z.number().describe("Timestamp when task was assigned"),
|
|
1990
1990
|
/**
|
|
1991
1991
|
* Optional deadline for task completion
|
|
1992
1992
|
*/
|
|
1993
|
-
deadline:
|
|
1993
|
+
deadline: import_zod8.z.number().optional().describe("Optional task deadline timestamp")
|
|
1994
1994
|
});
|
|
1995
|
-
var TaskResultSchema =
|
|
1995
|
+
var TaskResultSchema = import_zod8.z.object({
|
|
1996
1996
|
/**
|
|
1997
1997
|
* Assignment identifier
|
|
1998
1998
|
*/
|
|
1999
|
-
assignmentId:
|
|
1999
|
+
assignmentId: import_zod8.z.string().describe("Assignment identifier"),
|
|
2000
2000
|
/**
|
|
2001
2001
|
* Worker that completed the task
|
|
2002
2002
|
*/
|
|
2003
|
-
workerId:
|
|
2003
|
+
workerId: import_zod8.z.string().describe("Worker that completed the task"),
|
|
2004
2004
|
/**
|
|
2005
2005
|
* Whether the task succeeded
|
|
2006
2006
|
*/
|
|
2007
|
-
success:
|
|
2007
|
+
success: import_zod8.z.boolean().describe("Whether the task succeeded"),
|
|
2008
2008
|
/**
|
|
2009
2009
|
* Task result/output
|
|
2010
2010
|
*/
|
|
2011
|
-
result:
|
|
2011
|
+
result: import_zod8.z.string().describe("Task result or output"),
|
|
2012
2012
|
/**
|
|
2013
2013
|
* Optional error message if task failed
|
|
2014
2014
|
*/
|
|
2015
|
-
error:
|
|
2015
|
+
error: import_zod8.z.string().optional().describe("Error message if task failed"),
|
|
2016
2016
|
/**
|
|
2017
2017
|
* Timestamp when task was completed
|
|
2018
2018
|
*/
|
|
2019
|
-
completedAt:
|
|
2019
|
+
completedAt: import_zod8.z.number().describe("Timestamp when task was completed"),
|
|
2020
2020
|
/**
|
|
2021
2021
|
* Optional metadata about execution
|
|
2022
2022
|
*/
|
|
2023
|
-
metadata:
|
|
2023
|
+
metadata: import_zod8.z.record(import_zod8.z.any()).optional().describe("Execution metadata")
|
|
2024
2024
|
});
|
|
2025
|
-
var MultiAgentStatusSchema =
|
|
2025
|
+
var MultiAgentStatusSchema = import_zod8.z.enum([
|
|
2026
2026
|
"initializing",
|
|
2027
2027
|
// System is initializing
|
|
2028
2028
|
"routing",
|
|
@@ -2038,27 +2038,27 @@ var MultiAgentStatusSchema = import_zod7.z.enum([
|
|
|
2038
2038
|
"failed"
|
|
2039
2039
|
// Task failed
|
|
2040
2040
|
]);
|
|
2041
|
-
var HandoffRequestSchema =
|
|
2041
|
+
var HandoffRequestSchema = import_zod8.z.object({
|
|
2042
2042
|
/**
|
|
2043
2043
|
* Agent requesting the handoff
|
|
2044
2044
|
*/
|
|
2045
|
-
from:
|
|
2045
|
+
from: import_zod8.z.string().describe("Agent requesting handoff"),
|
|
2046
2046
|
/**
|
|
2047
2047
|
* Target agent for handoff
|
|
2048
2048
|
*/
|
|
2049
|
-
to:
|
|
2049
|
+
to: import_zod8.z.string().describe("Target agent for handoff"),
|
|
2050
2050
|
/**
|
|
2051
2051
|
* Reason for handoff
|
|
2052
2052
|
*/
|
|
2053
|
-
reason:
|
|
2053
|
+
reason: import_zod8.z.string().describe("Reason for requesting handoff"),
|
|
2054
2054
|
/**
|
|
2055
2055
|
* Context to pass to next agent
|
|
2056
2056
|
*/
|
|
2057
|
-
context:
|
|
2057
|
+
context: import_zod8.z.any().describe("Context to pass to next agent"),
|
|
2058
2058
|
/**
|
|
2059
2059
|
* Timestamp of handoff request
|
|
2060
2060
|
*/
|
|
2061
|
-
timestamp:
|
|
2061
|
+
timestamp: import_zod8.z.string().datetime().describe("ISO timestamp of handoff request")
|
|
2062
2062
|
});
|
|
2063
2063
|
|
|
2064
2064
|
// src/multi-agent/state.ts
|
|
@@ -2066,17 +2066,13 @@ var MultiAgentStateConfig = {
|
|
|
2066
2066
|
/**
|
|
2067
2067
|
* Original user input/query
|
|
2068
2068
|
*/
|
|
2069
|
-
input:
|
|
2070
|
-
schema: import_zod8.z.string(),
|
|
2071
|
-
default: () => "",
|
|
2072
|
-
description: "Original user input or query"
|
|
2073
|
-
},
|
|
2069
|
+
input: inputField,
|
|
2074
2070
|
/**
|
|
2075
2071
|
* All messages in the multi-agent conversation
|
|
2076
2072
|
* Accumulates all messages between agents
|
|
2077
2073
|
*/
|
|
2078
2074
|
messages: {
|
|
2079
|
-
schema:
|
|
2075
|
+
schema: import_zod9.z.array(AgentMessageSchema),
|
|
2080
2076
|
reducer: (left, right) => [...left, ...right],
|
|
2081
2077
|
default: () => [],
|
|
2082
2078
|
description: "All messages in the multi-agent conversation"
|
|
@@ -2085,7 +2081,7 @@ var MultiAgentStateConfig = {
|
|
|
2085
2081
|
* Available worker agents and their capabilities
|
|
2086
2082
|
*/
|
|
2087
2083
|
workers: {
|
|
2088
|
-
schema:
|
|
2084
|
+
schema: import_zod9.z.record(import_zod9.z.string(), WorkerCapabilitiesSchema),
|
|
2089
2085
|
reducer: (left, right) => ({
|
|
2090
2086
|
...left,
|
|
2091
2087
|
...right
|
|
@@ -2097,7 +2093,7 @@ var MultiAgentStateConfig = {
|
|
|
2097
2093
|
* Current active agent
|
|
2098
2094
|
*/
|
|
2099
2095
|
currentAgent: {
|
|
2100
|
-
schema:
|
|
2096
|
+
schema: import_zod9.z.string().optional(),
|
|
2101
2097
|
description: "Identifier of the currently active agent"
|
|
2102
2098
|
},
|
|
2103
2099
|
/**
|
|
@@ -2105,7 +2101,7 @@ var MultiAgentStateConfig = {
|
|
|
2105
2101
|
* Accumulates all routing decisions
|
|
2106
2102
|
*/
|
|
2107
2103
|
routingHistory: {
|
|
2108
|
-
schema:
|
|
2104
|
+
schema: import_zod9.z.array(RoutingDecisionSchema),
|
|
2109
2105
|
reducer: (left, right) => [...left, ...right],
|
|
2110
2106
|
default: () => [],
|
|
2111
2107
|
description: "History of routing decisions"
|
|
@@ -2114,7 +2110,7 @@ var MultiAgentStateConfig = {
|
|
|
2114
2110
|
* Active task assignments
|
|
2115
2111
|
*/
|
|
2116
2112
|
activeAssignments: {
|
|
2117
|
-
schema:
|
|
2113
|
+
schema: import_zod9.z.array(TaskAssignmentSchema),
|
|
2118
2114
|
reducer: (left, right) => [...left, ...right],
|
|
2119
2115
|
default: () => [],
|
|
2120
2116
|
description: "Currently active task assignments"
|
|
@@ -2124,7 +2120,7 @@ var MultiAgentStateConfig = {
|
|
|
2124
2120
|
* Accumulates all completed tasks
|
|
2125
2121
|
*/
|
|
2126
2122
|
completedTasks: {
|
|
2127
|
-
schema:
|
|
2123
|
+
schema: import_zod9.z.array(TaskResultSchema),
|
|
2128
2124
|
reducer: (left, right) => [...left, ...right],
|
|
2129
2125
|
default: () => [],
|
|
2130
2126
|
description: "Completed task results"
|
|
@@ -2134,7 +2130,7 @@ var MultiAgentStateConfig = {
|
|
|
2134
2130
|
* Accumulates all handoff requests
|
|
2135
2131
|
*/
|
|
2136
2132
|
handoffs: {
|
|
2137
|
-
schema:
|
|
2133
|
+
schema: import_zod9.z.array(HandoffRequestSchema),
|
|
2138
2134
|
reducer: (left, right) => [...left, ...right],
|
|
2139
2135
|
default: () => [],
|
|
2140
2136
|
description: "Handoff requests between agents"
|
|
@@ -2150,34 +2146,19 @@ var MultiAgentStateConfig = {
|
|
|
2150
2146
|
/**
|
|
2151
2147
|
* Iteration counter
|
|
2152
2148
|
*/
|
|
2153
|
-
iteration:
|
|
2154
|
-
schema: import_zod8.z.number().int().nonnegative(),
|
|
2155
|
-
reducer: (left, right) => left + right,
|
|
2156
|
-
default: () => 0,
|
|
2157
|
-
description: "Current iteration number"
|
|
2158
|
-
},
|
|
2149
|
+
iteration: iterationField,
|
|
2159
2150
|
/**
|
|
2160
2151
|
* Maximum iterations allowed
|
|
2161
2152
|
*/
|
|
2162
|
-
maxIterations:
|
|
2163
|
-
schema: import_zod8.z.number().int().positive(),
|
|
2164
|
-
default: () => 10,
|
|
2165
|
-
description: "Maximum number of iterations allowed"
|
|
2166
|
-
},
|
|
2153
|
+
maxIterations: maxIterationsField(10),
|
|
2167
2154
|
/**
|
|
2168
2155
|
* Final aggregated response
|
|
2169
2156
|
*/
|
|
2170
|
-
response:
|
|
2171
|
-
schema: import_zod8.z.string().optional(),
|
|
2172
|
-
description: "Final aggregated response"
|
|
2173
|
-
},
|
|
2157
|
+
response: responseField,
|
|
2174
2158
|
/**
|
|
2175
2159
|
* Error message if execution failed
|
|
2176
2160
|
*/
|
|
2177
|
-
error:
|
|
2178
|
-
schema: import_zod8.z.string().optional(),
|
|
2179
|
-
description: "Error message if execution failed"
|
|
2180
|
-
}
|
|
2161
|
+
error: errorField
|
|
2181
2162
|
};
|
|
2182
2163
|
var MultiAgentState = (0, import_core7.createStateAnnotation)(MultiAgentStateConfig);
|
|
2183
2164
|
|
|
@@ -2624,14 +2605,10 @@ function wrapReActAgent(workerId, agent, verbose = false) {
|
|
|
2624
2605
|
completedTasks: [taskResult]
|
|
2625
2606
|
};
|
|
2626
2607
|
} catch (error) {
|
|
2627
|
-
|
|
2628
|
-
logger2.debug("GraphInterrupt detected - re-throwing", { workerId });
|
|
2629
|
-
throw error;
|
|
2630
|
-
}
|
|
2608
|
+
const errorMessage = handleNodeError(error, `react-agent:${workerId}`, false);
|
|
2631
2609
|
logger2.error("Error in ReAct agent execution", {
|
|
2632
2610
|
workerId,
|
|
2633
|
-
error:
|
|
2634
|
-
stack: error instanceof Error ? error.stack : void 0
|
|
2611
|
+
error: errorMessage
|
|
2635
2612
|
});
|
|
2636
2613
|
const currentAssignment = state.activeAssignments.find(
|
|
2637
2614
|
(assignment) => assignment.workerId === workerId
|
|
@@ -2642,7 +2619,7 @@ function wrapReActAgent(workerId, agent, verbose = false) {
|
|
|
2642
2619
|
workerId,
|
|
2643
2620
|
success: false,
|
|
2644
2621
|
result: "",
|
|
2645
|
-
error:
|
|
2622
|
+
error: errorMessage,
|
|
2646
2623
|
completedAt: Date.now()
|
|
2647
2624
|
};
|
|
2648
2625
|
return {
|
|
@@ -2653,7 +2630,7 @@ function wrapReActAgent(workerId, agent, verbose = false) {
|
|
|
2653
2630
|
}
|
|
2654
2631
|
return {
|
|
2655
2632
|
status: "failed",
|
|
2656
|
-
error:
|
|
2633
|
+
error: errorMessage
|
|
2657
2634
|
};
|
|
2658
2635
|
}
|
|
2659
2636
|
};
|
|
@@ -2935,14 +2912,10 @@ Execute the assigned task using your skills and tools. Provide a clear, actionab
|
|
|
2935
2912
|
workers: updatedWorkers
|
|
2936
2913
|
};
|
|
2937
2914
|
} catch (error) {
|
|
2938
|
-
|
|
2939
|
-
logger3.info("GraphInterrupt detected, re-throwing", { workerId: id });
|
|
2940
|
-
throw error;
|
|
2941
|
-
}
|
|
2915
|
+
const errorMessage = handleNodeError(error, `worker:${id}`, false);
|
|
2942
2916
|
logger3.error("Worker node error", {
|
|
2943
2917
|
workerId: id,
|
|
2944
|
-
error:
|
|
2945
|
-
stack: error instanceof Error ? error.stack : void 0
|
|
2918
|
+
error: errorMessage
|
|
2946
2919
|
});
|
|
2947
2920
|
const currentAssignment = state.activeAssignments.find(
|
|
2948
2921
|
(assignment) => assignment.workerId === id
|
|
@@ -2957,7 +2930,7 @@ Execute the assigned task using your skills and tools. Provide a clear, actionab
|
|
|
2957
2930
|
workerId: id,
|
|
2958
2931
|
success: false,
|
|
2959
2932
|
result: "",
|
|
2960
|
-
error:
|
|
2933
|
+
error: errorMessage,
|
|
2961
2934
|
completedAt: Date.now()
|
|
2962
2935
|
};
|
|
2963
2936
|
return {
|
|
@@ -2969,7 +2942,7 @@ Execute the assigned task using your skills and tools. Provide a clear, actionab
|
|
|
2969
2942
|
logger3.error("No assignment found for error handling", { workerId: id });
|
|
2970
2943
|
return {
|
|
2971
2944
|
status: "failed",
|
|
2972
|
-
error:
|
|
2945
|
+
error: errorMessage
|
|
2973
2946
|
};
|
|
2974
2947
|
}
|
|
2975
2948
|
};
|