@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.js
CHANGED
|
@@ -35,15 +35,46 @@ var ScratchpadEntrySchema = z.object({
|
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
// src/react/state.ts
|
|
38
|
-
import { z as
|
|
38
|
+
import { z as z3 } from "zod";
|
|
39
39
|
import { createStateAnnotation } from "@agentforge/core";
|
|
40
|
+
|
|
41
|
+
// src/shared/state-fields.ts
|
|
42
|
+
import { z as z2 } from "zod";
|
|
43
|
+
var iterationField = {
|
|
44
|
+
schema: z2.number().int().nonnegative(),
|
|
45
|
+
reducer: (left, right) => left + right,
|
|
46
|
+
default: () => 0,
|
|
47
|
+
description: "Current iteration number"
|
|
48
|
+
};
|
|
49
|
+
function maxIterationsField(defaultValue) {
|
|
50
|
+
return {
|
|
51
|
+
schema: z2.number().int().positive(),
|
|
52
|
+
default: () => defaultValue,
|
|
53
|
+
description: "Maximum number of iterations allowed"
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
var errorField = {
|
|
57
|
+
schema: z2.string().optional(),
|
|
58
|
+
description: "Error message if execution failed"
|
|
59
|
+
};
|
|
60
|
+
var responseField = {
|
|
61
|
+
schema: z2.string().optional(),
|
|
62
|
+
description: "Final response after completion"
|
|
63
|
+
};
|
|
64
|
+
var inputField = {
|
|
65
|
+
schema: z2.string(),
|
|
66
|
+
default: () => "",
|
|
67
|
+
description: "Original user input or query"
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/react/state.ts
|
|
40
71
|
var ReActStateConfig = {
|
|
41
72
|
/**
|
|
42
73
|
* Conversation messages
|
|
43
74
|
* Accumulates all messages in the conversation
|
|
44
75
|
*/
|
|
45
76
|
messages: {
|
|
46
|
-
schema:
|
|
77
|
+
schema: z3.array(MessageSchema),
|
|
47
78
|
reducer: (left, right) => [...left, ...right],
|
|
48
79
|
default: () => [],
|
|
49
80
|
description: "Conversation message history"
|
|
@@ -53,7 +84,7 @@ var ReActStateConfig = {
|
|
|
53
84
|
* Accumulates all reasoning steps the agent takes
|
|
54
85
|
*/
|
|
55
86
|
thoughts: {
|
|
56
|
-
schema:
|
|
87
|
+
schema: z3.array(ThoughtSchema),
|
|
57
88
|
reducer: (left, right) => [...left, ...right],
|
|
58
89
|
default: () => [],
|
|
59
90
|
description: "Agent reasoning steps"
|
|
@@ -63,7 +94,7 @@ var ReActStateConfig = {
|
|
|
63
94
|
* Accumulates all tool calls made by the agent
|
|
64
95
|
*/
|
|
65
96
|
actions: {
|
|
66
|
-
schema:
|
|
97
|
+
schema: z3.array(ToolCallSchema),
|
|
67
98
|
reducer: (left, right) => [...left, ...right],
|
|
68
99
|
default: () => [],
|
|
69
100
|
description: "Tool calls made by the agent"
|
|
@@ -73,7 +104,7 @@ var ReActStateConfig = {
|
|
|
73
104
|
* Accumulates all observations from tool executions
|
|
74
105
|
*/
|
|
75
106
|
observations: {
|
|
76
|
-
schema:
|
|
107
|
+
schema: z3.array(ToolResultSchema),
|
|
77
108
|
reducer: (left, right) => [...left, ...right],
|
|
78
109
|
default: () => [],
|
|
79
110
|
description: "Results from tool executions"
|
|
@@ -83,7 +114,7 @@ var ReActStateConfig = {
|
|
|
83
114
|
* Accumulates step-by-step reasoning process
|
|
84
115
|
*/
|
|
85
116
|
scratchpad: {
|
|
86
|
-
schema:
|
|
117
|
+
schema: z3.array(ScratchpadEntrySchema),
|
|
87
118
|
reducer: (left, right) => [...left, ...right],
|
|
88
119
|
default: () => [],
|
|
89
120
|
description: "Intermediate reasoning scratchpad"
|
|
@@ -92,27 +123,19 @@ var ReActStateConfig = {
|
|
|
92
123
|
* Current iteration count
|
|
93
124
|
* Tracks how many thought-action-observation loops have been executed
|
|
94
125
|
*/
|
|
95
|
-
iteration:
|
|
96
|
-
schema: z2.number(),
|
|
97
|
-
reducer: (left, right) => left + right,
|
|
98
|
-
default: () => 0,
|
|
99
|
-
description: "Current iteration count"
|
|
100
|
-
},
|
|
126
|
+
iteration: iterationField,
|
|
101
127
|
/**
|
|
102
128
|
* Whether the agent should continue iterating
|
|
103
129
|
*/
|
|
104
130
|
shouldContinue: {
|
|
105
|
-
schema:
|
|
131
|
+
schema: z3.boolean().optional(),
|
|
106
132
|
default: () => true,
|
|
107
133
|
description: "Whether to continue the ReAct loop"
|
|
108
134
|
},
|
|
109
135
|
/**
|
|
110
136
|
* Final response (if any)
|
|
111
137
|
*/
|
|
112
|
-
response:
|
|
113
|
-
schema: z2.string().optional(),
|
|
114
|
-
description: "Final response from the agent"
|
|
115
|
-
}
|
|
138
|
+
response: responseField
|
|
116
139
|
};
|
|
117
140
|
var ReActState = createStateAnnotation(ReActStateConfig);
|
|
118
141
|
|
|
@@ -176,6 +199,24 @@ function buildDeduplicationMetrics(toolsExecuted, duplicatesSkipped, totalObserv
|
|
|
176
199
|
};
|
|
177
200
|
}
|
|
178
201
|
|
|
202
|
+
// src/shared/error-handling.ts
|
|
203
|
+
function isGraphInterrupt(error) {
|
|
204
|
+
return error !== null && typeof error === "object" && "constructor" in error && error.constructor.name === "GraphInterrupt";
|
|
205
|
+
}
|
|
206
|
+
function handleNodeError(error, context, verbose = false) {
|
|
207
|
+
if (isGraphInterrupt(error)) {
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
211
|
+
if (verbose) {
|
|
212
|
+
console.error(`[${context}] Error:`, errorMessage);
|
|
213
|
+
if (error instanceof Error && error.stack) {
|
|
214
|
+
console.error(`[${context}] Stack:`, error.stack);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return errorMessage;
|
|
218
|
+
}
|
|
219
|
+
|
|
179
220
|
// src/react/nodes.ts
|
|
180
221
|
var reasoningLogger = createPatternLogger("agentforge:patterns:react:reasoning");
|
|
181
222
|
var actionLogger = createPatternLogger("agentforge:patterns:react:action");
|
|
@@ -338,10 +379,7 @@ function createActionNode(tools, verbose = false, enableDeduplication = true) {
|
|
|
338
379
|
executionCache.set(cacheKey, observation);
|
|
339
380
|
}
|
|
340
381
|
} catch (error) {
|
|
341
|
-
|
|
342
|
-
throw error;
|
|
343
|
-
}
|
|
344
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
382
|
+
const errorMessage = handleNodeError(error, `action:${action.name}`, false);
|
|
345
383
|
actionLogger.error("Tool execution failed", {
|
|
346
384
|
toolName: action.name,
|
|
347
385
|
error: errorMessage,
|
|
@@ -580,34 +618,34 @@ function createReActAgentBuilder() {
|
|
|
580
618
|
import { StateGraph as StateGraph2, END as END2 } from "@langchain/langgraph";
|
|
581
619
|
|
|
582
620
|
// src/plan-execute/state.ts
|
|
583
|
-
import { z as
|
|
621
|
+
import { z as z5 } from "zod";
|
|
584
622
|
import { createStateAnnotation as createStateAnnotation2 } from "@agentforge/core";
|
|
585
623
|
|
|
586
624
|
// src/plan-execute/schemas.ts
|
|
587
|
-
import { z as
|
|
588
|
-
var PlanStepSchema =
|
|
625
|
+
import { z as z4 } from "zod";
|
|
626
|
+
var PlanStepSchema = z4.object({
|
|
589
627
|
/**
|
|
590
628
|
* Unique identifier for the step
|
|
591
629
|
*/
|
|
592
|
-
id:
|
|
630
|
+
id: z4.string().describe("Unique identifier for the step"),
|
|
593
631
|
/**
|
|
594
632
|
* Description of what this step should accomplish
|
|
595
633
|
*/
|
|
596
|
-
description:
|
|
634
|
+
description: z4.string().describe("Description of what this step should accomplish"),
|
|
597
635
|
/**
|
|
598
636
|
* Optional dependencies on other steps (by ID)
|
|
599
637
|
*/
|
|
600
|
-
dependencies:
|
|
638
|
+
dependencies: z4.array(z4.string()).optional().describe("IDs of steps that must complete before this one"),
|
|
601
639
|
/**
|
|
602
640
|
* Optional tool to use for this step
|
|
603
641
|
*/
|
|
604
|
-
tool:
|
|
642
|
+
tool: z4.string().optional().describe("Name of the tool to use for this step"),
|
|
605
643
|
/**
|
|
606
644
|
* Optional arguments for the tool
|
|
607
645
|
*/
|
|
608
|
-
args:
|
|
646
|
+
args: z4.record(z4.any()).optional().describe("Arguments to pass to the tool")
|
|
609
647
|
});
|
|
610
|
-
var CompletedStepSchema =
|
|
648
|
+
var CompletedStepSchema = z4.object({
|
|
611
649
|
/**
|
|
612
650
|
* The step that was executed
|
|
613
651
|
*/
|
|
@@ -615,53 +653,53 @@ var CompletedStepSchema = z3.object({
|
|
|
615
653
|
/**
|
|
616
654
|
* The result of executing the step
|
|
617
655
|
*/
|
|
618
|
-
result:
|
|
656
|
+
result: z4.any().describe("The result of executing the step"),
|
|
619
657
|
/**
|
|
620
658
|
* Whether the step succeeded
|
|
621
659
|
*/
|
|
622
|
-
success:
|
|
660
|
+
success: z4.boolean().describe("Whether the step succeeded"),
|
|
623
661
|
/**
|
|
624
662
|
* Optional error message if the step failed
|
|
625
663
|
*/
|
|
626
|
-
error:
|
|
664
|
+
error: z4.string().optional().describe("Error message if the step failed"),
|
|
627
665
|
/**
|
|
628
666
|
* Timestamp when the step was completed
|
|
629
667
|
*/
|
|
630
|
-
timestamp:
|
|
668
|
+
timestamp: z4.string().datetime().describe("ISO timestamp when the step was completed")
|
|
631
669
|
});
|
|
632
|
-
var PlanSchema =
|
|
670
|
+
var PlanSchema = z4.object({
|
|
633
671
|
/**
|
|
634
672
|
* List of steps in the plan
|
|
635
673
|
*/
|
|
636
|
-
steps:
|
|
674
|
+
steps: z4.array(PlanStepSchema).describe("List of steps in the plan"),
|
|
637
675
|
/**
|
|
638
676
|
* Overall goal of the plan
|
|
639
677
|
*/
|
|
640
|
-
goal:
|
|
678
|
+
goal: z4.string().describe("Overall goal of the plan"),
|
|
641
679
|
/**
|
|
642
680
|
* Timestamp when the plan was created
|
|
643
681
|
*/
|
|
644
|
-
createdAt:
|
|
682
|
+
createdAt: z4.string().datetime().describe("ISO timestamp when the plan was created"),
|
|
645
683
|
/**
|
|
646
684
|
* Optional confidence score (0-1)
|
|
647
685
|
*/
|
|
648
|
-
confidence:
|
|
686
|
+
confidence: z4.number().min(0).max(1).optional().describe("Confidence score for the plan (0-1)")
|
|
649
687
|
});
|
|
650
|
-
var ReplanDecisionSchema =
|
|
688
|
+
var ReplanDecisionSchema = z4.object({
|
|
651
689
|
/**
|
|
652
690
|
* Whether to replan
|
|
653
691
|
*/
|
|
654
|
-
shouldReplan:
|
|
692
|
+
shouldReplan: z4.boolean().describe("Whether to replan based on current results"),
|
|
655
693
|
/**
|
|
656
694
|
* Reason for the decision
|
|
657
695
|
*/
|
|
658
|
-
reason:
|
|
696
|
+
reason: z4.string().describe("Reason for the replan decision"),
|
|
659
697
|
/**
|
|
660
698
|
* Optional new goal if replanning
|
|
661
699
|
*/
|
|
662
|
-
newGoal:
|
|
700
|
+
newGoal: z4.string().optional().describe("Updated goal if replanning")
|
|
663
701
|
});
|
|
664
|
-
var ExecutionStatusSchema =
|
|
702
|
+
var ExecutionStatusSchema = z4.enum([
|
|
665
703
|
"planning",
|
|
666
704
|
"executing",
|
|
667
705
|
"replanning",
|
|
@@ -674,11 +712,7 @@ var PlanExecuteStateConfig = {
|
|
|
674
712
|
/**
|
|
675
713
|
* Original user input/query
|
|
676
714
|
*/
|
|
677
|
-
input:
|
|
678
|
-
schema: z4.string(),
|
|
679
|
-
default: () => "",
|
|
680
|
-
description: "Original user input or query"
|
|
681
|
-
},
|
|
715
|
+
input: inputField,
|
|
682
716
|
/**
|
|
683
717
|
* The current plan
|
|
684
718
|
*/
|
|
@@ -691,7 +725,7 @@ var PlanExecuteStateConfig = {
|
|
|
691
725
|
* Accumulates all completed steps
|
|
692
726
|
*/
|
|
693
727
|
pastSteps: {
|
|
694
|
-
schema:
|
|
728
|
+
schema: z5.array(CompletedStepSchema),
|
|
695
729
|
reducer: (left, right) => [...left, ...right],
|
|
696
730
|
default: () => [],
|
|
697
731
|
description: "Completed steps with their results"
|
|
@@ -700,7 +734,7 @@ var PlanExecuteStateConfig = {
|
|
|
700
734
|
* Index of the current step being executed
|
|
701
735
|
*/
|
|
702
736
|
currentStepIndex: {
|
|
703
|
-
schema:
|
|
737
|
+
schema: z5.number().int().nonnegative().optional(),
|
|
704
738
|
description: "Index of the current step being executed"
|
|
705
739
|
},
|
|
706
740
|
/**
|
|
@@ -714,34 +748,19 @@ var PlanExecuteStateConfig = {
|
|
|
714
748
|
/**
|
|
715
749
|
* Final response
|
|
716
750
|
*/
|
|
717
|
-
response:
|
|
718
|
-
schema: z4.string().optional(),
|
|
719
|
-
description: "Final response after plan execution"
|
|
720
|
-
},
|
|
751
|
+
response: responseField,
|
|
721
752
|
/**
|
|
722
753
|
* Error message if execution failed
|
|
723
754
|
*/
|
|
724
|
-
error:
|
|
725
|
-
schema: z4.string().optional(),
|
|
726
|
-
description: "Error message if execution failed"
|
|
727
|
-
},
|
|
755
|
+
error: errorField,
|
|
728
756
|
/**
|
|
729
757
|
* Iteration counter for replanning
|
|
730
758
|
*/
|
|
731
|
-
iteration:
|
|
732
|
-
schema: z4.number().int().nonnegative(),
|
|
733
|
-
reducer: (left, right) => left + right,
|
|
734
|
-
default: () => 0,
|
|
735
|
-
description: "Number of planning iterations"
|
|
736
|
-
},
|
|
759
|
+
iteration: iterationField,
|
|
737
760
|
/**
|
|
738
761
|
* Maximum iterations allowed
|
|
739
762
|
*/
|
|
740
|
-
maxIterations:
|
|
741
|
-
schema: z4.number().int().positive(),
|
|
742
|
-
default: () => 5,
|
|
743
|
-
description: "Maximum number of planning iterations allowed"
|
|
744
|
-
}
|
|
763
|
+
maxIterations: maxIterationsField(5)
|
|
745
764
|
};
|
|
746
765
|
var PlanExecuteState = createStateAnnotation2(PlanExecuteStateConfig);
|
|
747
766
|
|
|
@@ -974,11 +993,8 @@ function createExecutorNode(config) {
|
|
|
974
993
|
result = { message: "Step completed without tool execution" };
|
|
975
994
|
}
|
|
976
995
|
} catch (execError) {
|
|
977
|
-
|
|
978
|
-
throw execError;
|
|
979
|
-
}
|
|
996
|
+
error = handleNodeError(execError, `executor:${currentStep.description}`, false);
|
|
980
997
|
success = false;
|
|
981
|
-
error = execError instanceof Error ? execError.message : "Unknown execution error";
|
|
982
998
|
result = null;
|
|
983
999
|
executorLogger.warn("Step execution failed", {
|
|
984
1000
|
stepId: currentStep.id,
|
|
@@ -1181,46 +1197,46 @@ function createPlanExecuteAgent(config) {
|
|
|
1181
1197
|
}
|
|
1182
1198
|
|
|
1183
1199
|
// src/reflection/state.ts
|
|
1184
|
-
import { z as
|
|
1200
|
+
import { z as z7 } from "zod";
|
|
1185
1201
|
import { createStateAnnotation as createStateAnnotation3 } from "@agentforge/core";
|
|
1186
1202
|
|
|
1187
1203
|
// src/reflection/schemas.ts
|
|
1188
|
-
import { z as
|
|
1189
|
-
var ReflectionSchema =
|
|
1204
|
+
import { z as z6 } from "zod";
|
|
1205
|
+
var ReflectionSchema = z6.object({
|
|
1190
1206
|
/**
|
|
1191
1207
|
* The critique or feedback on the current response
|
|
1192
1208
|
*/
|
|
1193
|
-
critique:
|
|
1209
|
+
critique: z6.string().describe("Critique or feedback on the current response"),
|
|
1194
1210
|
/**
|
|
1195
1211
|
* Specific issues identified
|
|
1196
1212
|
*/
|
|
1197
|
-
issues:
|
|
1213
|
+
issues: z6.array(z6.string()).describe("Specific issues or problems identified"),
|
|
1198
1214
|
/**
|
|
1199
1215
|
* Suggestions for improvement
|
|
1200
1216
|
*/
|
|
1201
|
-
suggestions:
|
|
1217
|
+
suggestions: z6.array(z6.string()).describe("Suggestions for improving the response"),
|
|
1202
1218
|
/**
|
|
1203
1219
|
* Quality score (0-10)
|
|
1204
1220
|
*/
|
|
1205
|
-
score:
|
|
1221
|
+
score: z6.number().min(0).max(10).optional().describe("Quality score from 0 to 10"),
|
|
1206
1222
|
/**
|
|
1207
1223
|
* Whether the response meets quality standards
|
|
1208
1224
|
*/
|
|
1209
|
-
meetsStandards:
|
|
1225
|
+
meetsStandards: z6.boolean().describe("Whether the response meets quality standards"),
|
|
1210
1226
|
/**
|
|
1211
1227
|
* Timestamp of the reflection
|
|
1212
1228
|
*/
|
|
1213
|
-
timestamp:
|
|
1229
|
+
timestamp: z6.date().optional().describe("When this reflection was created")
|
|
1214
1230
|
});
|
|
1215
|
-
var RevisionSchema =
|
|
1231
|
+
var RevisionSchema = z6.object({
|
|
1216
1232
|
/**
|
|
1217
1233
|
* The revised content
|
|
1218
1234
|
*/
|
|
1219
|
-
content:
|
|
1235
|
+
content: z6.string().describe("The revised content"),
|
|
1220
1236
|
/**
|
|
1221
1237
|
* Which iteration this revision is from
|
|
1222
1238
|
*/
|
|
1223
|
-
iteration:
|
|
1239
|
+
iteration: z6.number().int().nonnegative().describe("Iteration number"),
|
|
1224
1240
|
/**
|
|
1225
1241
|
* The reflection that prompted this revision
|
|
1226
1242
|
*/
|
|
@@ -1228,9 +1244,9 @@ var RevisionSchema = z5.object({
|
|
|
1228
1244
|
/**
|
|
1229
1245
|
* Timestamp of the revision
|
|
1230
1246
|
*/
|
|
1231
|
-
timestamp:
|
|
1247
|
+
timestamp: z6.date().optional().describe("When this revision was created")
|
|
1232
1248
|
});
|
|
1233
|
-
var ReflectionStatusSchema =
|
|
1249
|
+
var ReflectionStatusSchema = z6.enum([
|
|
1234
1250
|
"generating",
|
|
1235
1251
|
// Initial generation
|
|
1236
1252
|
"reflecting",
|
|
@@ -1242,25 +1258,25 @@ var ReflectionStatusSchema = z5.enum([
|
|
|
1242
1258
|
"failed"
|
|
1243
1259
|
// Max iterations reached without meeting standards
|
|
1244
1260
|
]);
|
|
1245
|
-
var QualityCriteriaSchema =
|
|
1261
|
+
var QualityCriteriaSchema = z6.object({
|
|
1246
1262
|
/**
|
|
1247
1263
|
* Minimum quality score required (0-10)
|
|
1248
1264
|
*/
|
|
1249
|
-
minScore:
|
|
1265
|
+
minScore: z6.number().min(0).max(10).default(7).describe("Minimum quality score required"),
|
|
1250
1266
|
/**
|
|
1251
1267
|
* Specific criteria to evaluate
|
|
1252
1268
|
*/
|
|
1253
|
-
criteria:
|
|
1269
|
+
criteria: z6.array(z6.string()).optional().describe("Specific criteria to evaluate"),
|
|
1254
1270
|
/**
|
|
1255
1271
|
* Whether all criteria must be met
|
|
1256
1272
|
*/
|
|
1257
|
-
requireAll:
|
|
1273
|
+
requireAll: z6.boolean().default(true).describe("Whether all criteria must be met")
|
|
1258
1274
|
});
|
|
1259
|
-
var ReflectionConfigSchema =
|
|
1275
|
+
var ReflectionConfigSchema = z6.object({
|
|
1260
1276
|
/**
|
|
1261
1277
|
* Maximum number of reflection iterations
|
|
1262
1278
|
*/
|
|
1263
|
-
maxIterations:
|
|
1279
|
+
maxIterations: z6.number().int().positive().default(3).describe("Maximum reflection iterations"),
|
|
1264
1280
|
/**
|
|
1265
1281
|
* Quality criteria for completion
|
|
1266
1282
|
*/
|
|
@@ -1268,7 +1284,7 @@ var ReflectionConfigSchema = z5.object({
|
|
|
1268
1284
|
/**
|
|
1269
1285
|
* Whether to include previous reflections in context
|
|
1270
1286
|
*/
|
|
1271
|
-
includeHistory:
|
|
1287
|
+
includeHistory: z6.boolean().default(true).describe("Include previous reflections in context")
|
|
1272
1288
|
});
|
|
1273
1289
|
|
|
1274
1290
|
// src/reflection/state.ts
|
|
@@ -1276,16 +1292,12 @@ var ReflectionStateConfig = {
|
|
|
1276
1292
|
/**
|
|
1277
1293
|
* Original user input/task
|
|
1278
1294
|
*/
|
|
1279
|
-
input:
|
|
1280
|
-
schema: z6.string(),
|
|
1281
|
-
default: () => "",
|
|
1282
|
-
description: "Original user input or task"
|
|
1283
|
-
},
|
|
1295
|
+
input: inputField,
|
|
1284
1296
|
/**
|
|
1285
1297
|
* Current response/output
|
|
1286
1298
|
*/
|
|
1287
1299
|
currentResponse: {
|
|
1288
|
-
schema:
|
|
1300
|
+
schema: z7.string().optional(),
|
|
1289
1301
|
description: "Current response or output"
|
|
1290
1302
|
},
|
|
1291
1303
|
/**
|
|
@@ -1293,7 +1305,7 @@ var ReflectionStateConfig = {
|
|
|
1293
1305
|
* Accumulates all reflections
|
|
1294
1306
|
*/
|
|
1295
1307
|
reflections: {
|
|
1296
|
-
schema:
|
|
1308
|
+
schema: z7.array(ReflectionSchema),
|
|
1297
1309
|
reducer: (left, right) => [...left, ...right],
|
|
1298
1310
|
default: () => [],
|
|
1299
1311
|
description: "History of all reflections and critiques"
|
|
@@ -1303,7 +1315,7 @@ var ReflectionStateConfig = {
|
|
|
1303
1315
|
* Accumulates all revisions
|
|
1304
1316
|
*/
|
|
1305
1317
|
revisions: {
|
|
1306
|
-
schema:
|
|
1318
|
+
schema: z7.array(RevisionSchema),
|
|
1307
1319
|
reducer: (left, right) => [...left, ...right],
|
|
1308
1320
|
default: () => [],
|
|
1309
1321
|
description: "History of all revisions"
|
|
@@ -1311,12 +1323,7 @@ var ReflectionStateConfig = {
|
|
|
1311
1323
|
/**
|
|
1312
1324
|
* Current iteration number
|
|
1313
1325
|
*/
|
|
1314
|
-
iteration:
|
|
1315
|
-
schema: z6.number().int().nonnegative(),
|
|
1316
|
-
reducer: (left, right) => left + right,
|
|
1317
|
-
default: () => 0,
|
|
1318
|
-
description: "Current iteration number"
|
|
1319
|
-
},
|
|
1326
|
+
iteration: iterationField,
|
|
1320
1327
|
/**
|
|
1321
1328
|
* Current status
|
|
1322
1329
|
*/
|
|
@@ -1335,25 +1342,15 @@ var ReflectionStateConfig = {
|
|
|
1335
1342
|
/**
|
|
1336
1343
|
* Maximum iterations allowed
|
|
1337
1344
|
*/
|
|
1338
|
-
maxIterations:
|
|
1339
|
-
schema: z6.number().int().positive(),
|
|
1340
|
-
default: () => 3,
|
|
1341
|
-
description: "Maximum number of reflection iterations allowed"
|
|
1342
|
-
},
|
|
1345
|
+
maxIterations: maxIterationsField(3),
|
|
1343
1346
|
/**
|
|
1344
1347
|
* Final response (when completed)
|
|
1345
1348
|
*/
|
|
1346
|
-
response:
|
|
1347
|
-
schema: z6.string().optional(),
|
|
1348
|
-
description: "Final response after reflection process"
|
|
1349
|
-
},
|
|
1349
|
+
response: responseField,
|
|
1350
1350
|
/**
|
|
1351
1351
|
* Error message if failed
|
|
1352
1352
|
*/
|
|
1353
|
-
error:
|
|
1354
|
-
schema: z6.string().optional(),
|
|
1355
|
-
description: "Error message if reflection failed"
|
|
1356
|
-
}
|
|
1353
|
+
error: errorField
|
|
1357
1354
|
};
|
|
1358
1355
|
var ReflectionState = createStateAnnotation3(ReflectionStateConfig);
|
|
1359
1356
|
|
|
@@ -1502,14 +1499,15 @@ ${lastReflection.critique}`;
|
|
|
1502
1499
|
iteration: 1
|
|
1503
1500
|
};
|
|
1504
1501
|
} catch (error) {
|
|
1502
|
+
const errorMessage = handleNodeError(error, "generator", false);
|
|
1505
1503
|
generatorLogger.error("Response generation failed", {
|
|
1506
1504
|
attempt: state.iteration + 1,
|
|
1507
|
-
error:
|
|
1505
|
+
error: errorMessage,
|
|
1508
1506
|
duration: Date.now() - startTime
|
|
1509
1507
|
});
|
|
1510
1508
|
return {
|
|
1511
1509
|
status: "failed",
|
|
1512
|
-
error:
|
|
1510
|
+
error: errorMessage
|
|
1513
1511
|
};
|
|
1514
1512
|
}
|
|
1515
1513
|
};
|
|
@@ -1591,14 +1589,15 @@ function createReflectorNode(config) {
|
|
|
1591
1589
|
status: reflection.meetsStandards ? "completed" : "revising"
|
|
1592
1590
|
};
|
|
1593
1591
|
} catch (error) {
|
|
1592
|
+
const errorMessage = handleNodeError(error, "reflector", false);
|
|
1594
1593
|
reflectorLogger.error("Reflection failed", {
|
|
1595
1594
|
attempt: state.iteration,
|
|
1596
|
-
error:
|
|
1595
|
+
error: errorMessage,
|
|
1597
1596
|
duration: Date.now() - startTime
|
|
1598
1597
|
});
|
|
1599
1598
|
return {
|
|
1600
1599
|
status: "failed",
|
|
1601
|
-
error:
|
|
1600
|
+
error: errorMessage
|
|
1602
1601
|
};
|
|
1603
1602
|
}
|
|
1604
1603
|
};
|
|
@@ -1659,14 +1658,15 @@ ${revisionsText}`;
|
|
|
1659
1658
|
iteration: 1
|
|
1660
1659
|
};
|
|
1661
1660
|
} catch (error) {
|
|
1661
|
+
const errorMessage = handleNodeError(error, "reviser", false);
|
|
1662
1662
|
reviserLogger.error("Revision failed", {
|
|
1663
1663
|
attempt: state.iteration,
|
|
1664
|
-
error:
|
|
1664
|
+
error: errorMessage,
|
|
1665
1665
|
duration: Date.now() - startTime
|
|
1666
1666
|
});
|
|
1667
1667
|
return {
|
|
1668
1668
|
status: "failed",
|
|
1669
|
-
error:
|
|
1669
|
+
error: errorMessage
|
|
1670
1670
|
};
|
|
1671
1671
|
}
|
|
1672
1672
|
};
|
|
@@ -1752,13 +1752,13 @@ function createReflectionAgent(config) {
|
|
|
1752
1752
|
}
|
|
1753
1753
|
|
|
1754
1754
|
// src/multi-agent/state.ts
|
|
1755
|
-
import { z as
|
|
1755
|
+
import { z as z9 } from "zod";
|
|
1756
1756
|
import { createStateAnnotation as createStateAnnotation4 } from "@agentforge/core";
|
|
1757
1757
|
|
|
1758
1758
|
// src/multi-agent/schemas.ts
|
|
1759
|
-
import { z as
|
|
1760
|
-
var AgentRoleSchema =
|
|
1761
|
-
var MessageTypeSchema =
|
|
1759
|
+
import { z as z8 } from "zod";
|
|
1760
|
+
var AgentRoleSchema = z8.enum(["supervisor", "worker"]);
|
|
1761
|
+
var MessageTypeSchema = z8.enum([
|
|
1762
1762
|
"user_input",
|
|
1763
1763
|
// Initial user message
|
|
1764
1764
|
"task_assignment",
|
|
@@ -1772,11 +1772,11 @@ var MessageTypeSchema = z7.enum([
|
|
|
1772
1772
|
"completion"
|
|
1773
1773
|
// Final completion message
|
|
1774
1774
|
]);
|
|
1775
|
-
var AgentMessageSchema =
|
|
1775
|
+
var AgentMessageSchema = z8.object({
|
|
1776
1776
|
/**
|
|
1777
1777
|
* Unique identifier for the message
|
|
1778
1778
|
*/
|
|
1779
|
-
id:
|
|
1779
|
+
id: z8.string().describe("Unique message identifier"),
|
|
1780
1780
|
/**
|
|
1781
1781
|
* Type of message
|
|
1782
1782
|
*/
|
|
@@ -1784,25 +1784,25 @@ var AgentMessageSchema = z7.object({
|
|
|
1784
1784
|
/**
|
|
1785
1785
|
* Agent that sent the message
|
|
1786
1786
|
*/
|
|
1787
|
-
from:
|
|
1787
|
+
from: z8.string().describe("Agent identifier that sent the message"),
|
|
1788
1788
|
/**
|
|
1789
1789
|
* Agent(s) that should receive the message
|
|
1790
1790
|
*/
|
|
1791
|
-
to:
|
|
1791
|
+
to: z8.union([z8.string(), z8.array(z8.string())]).describe("Target agent(s)"),
|
|
1792
1792
|
/**
|
|
1793
1793
|
* Message content
|
|
1794
1794
|
*/
|
|
1795
|
-
content:
|
|
1795
|
+
content: z8.string().describe("Message content"),
|
|
1796
1796
|
/**
|
|
1797
1797
|
* Optional metadata
|
|
1798
1798
|
*/
|
|
1799
|
-
metadata:
|
|
1799
|
+
metadata: z8.record(z8.any()).optional().describe("Additional message metadata"),
|
|
1800
1800
|
/**
|
|
1801
1801
|
* Timestamp when message was created
|
|
1802
1802
|
*/
|
|
1803
|
-
timestamp:
|
|
1803
|
+
timestamp: z8.number().describe("Timestamp when message was created")
|
|
1804
1804
|
});
|
|
1805
|
-
var RoutingStrategySchema =
|
|
1805
|
+
var RoutingStrategySchema = z8.enum([
|
|
1806
1806
|
"llm-based",
|
|
1807
1807
|
// LLM decides which agent to route to
|
|
1808
1808
|
"rule-based",
|
|
@@ -1814,25 +1814,25 @@ var RoutingStrategySchema = z7.enum([
|
|
|
1814
1814
|
"load-balanced"
|
|
1815
1815
|
// Route based on agent workload
|
|
1816
1816
|
]);
|
|
1817
|
-
var RoutingDecisionSchema =
|
|
1817
|
+
var RoutingDecisionSchema = z8.object({
|
|
1818
1818
|
/**
|
|
1819
1819
|
* Target agent to route to (single agent routing)
|
|
1820
1820
|
* @deprecated Use targetAgents for parallel routing support
|
|
1821
1821
|
*/
|
|
1822
|
-
targetAgent:
|
|
1822
|
+
targetAgent: z8.string().nullable().default(null).describe("Agent to route the task to (single routing)"),
|
|
1823
1823
|
/**
|
|
1824
1824
|
* Target agents to route to (parallel routing)
|
|
1825
1825
|
* When multiple agents are specified, they execute in parallel
|
|
1826
1826
|
*/
|
|
1827
|
-
targetAgents:
|
|
1827
|
+
targetAgents: z8.array(z8.string()).nullable().default(null).describe("Agents to route the task to (parallel routing)"),
|
|
1828
1828
|
/**
|
|
1829
1829
|
* Reasoning for the routing decision
|
|
1830
1830
|
*/
|
|
1831
|
-
reasoning:
|
|
1831
|
+
reasoning: z8.string().default("").describe("Explanation for routing decision"),
|
|
1832
1832
|
/**
|
|
1833
1833
|
* Confidence in the routing decision (0-1)
|
|
1834
1834
|
*/
|
|
1835
|
-
confidence:
|
|
1835
|
+
confidence: z8.number().min(0).max(1).default(0.8).describe("Confidence score"),
|
|
1836
1836
|
/**
|
|
1837
1837
|
* Strategy used for routing
|
|
1838
1838
|
*/
|
|
@@ -1840,86 +1840,86 @@ var RoutingDecisionSchema = z7.object({
|
|
|
1840
1840
|
/**
|
|
1841
1841
|
* Timestamp of the routing decision
|
|
1842
1842
|
*/
|
|
1843
|
-
timestamp:
|
|
1843
|
+
timestamp: z8.number().default(() => Date.now()).describe("Timestamp of the decision")
|
|
1844
1844
|
}).refine(
|
|
1845
1845
|
(data) => data.targetAgent || data.targetAgents && data.targetAgents.length > 0,
|
|
1846
1846
|
{ message: "Either targetAgent or targetAgents must be provided" }
|
|
1847
1847
|
);
|
|
1848
|
-
var WorkerCapabilitiesSchema =
|
|
1848
|
+
var WorkerCapabilitiesSchema = z8.object({
|
|
1849
1849
|
/**
|
|
1850
1850
|
* Skills/capabilities the agent has
|
|
1851
1851
|
*/
|
|
1852
|
-
skills:
|
|
1852
|
+
skills: z8.array(z8.string()).describe("List of agent skills"),
|
|
1853
1853
|
/**
|
|
1854
1854
|
* Tools available to the agent
|
|
1855
1855
|
*/
|
|
1856
|
-
tools:
|
|
1856
|
+
tools: z8.array(z8.string()).describe("List of tool names available to agent"),
|
|
1857
1857
|
/**
|
|
1858
1858
|
* Whether the agent is currently available
|
|
1859
1859
|
*/
|
|
1860
|
-
available:
|
|
1860
|
+
available: z8.boolean().default(true).describe("Whether agent is available"),
|
|
1861
1861
|
/**
|
|
1862
1862
|
* Current workload (number of active tasks)
|
|
1863
1863
|
*/
|
|
1864
|
-
currentWorkload:
|
|
1864
|
+
currentWorkload: z8.number().int().nonnegative().default(0).describe("Current number of active tasks")
|
|
1865
1865
|
});
|
|
1866
|
-
var TaskAssignmentSchema =
|
|
1866
|
+
var TaskAssignmentSchema = z8.object({
|
|
1867
1867
|
/**
|
|
1868
1868
|
* Unique assignment identifier
|
|
1869
1869
|
*/
|
|
1870
|
-
id:
|
|
1870
|
+
id: z8.string().describe("Unique assignment identifier"),
|
|
1871
1871
|
/**
|
|
1872
1872
|
* Worker ID assigned to the task
|
|
1873
1873
|
*/
|
|
1874
|
-
workerId:
|
|
1874
|
+
workerId: z8.string().describe("Worker identifier assigned to task"),
|
|
1875
1875
|
/**
|
|
1876
1876
|
* Task description
|
|
1877
1877
|
*/
|
|
1878
|
-
task:
|
|
1878
|
+
task: z8.string().describe("Description of the task"),
|
|
1879
1879
|
/**
|
|
1880
1880
|
* Task priority (1-10, higher is more urgent)
|
|
1881
1881
|
*/
|
|
1882
|
-
priority:
|
|
1882
|
+
priority: z8.number().int().min(1).max(10).default(5).describe("Task priority"),
|
|
1883
1883
|
/**
|
|
1884
1884
|
* Timestamp when task was assigned
|
|
1885
1885
|
*/
|
|
1886
|
-
assignedAt:
|
|
1886
|
+
assignedAt: z8.number().describe("Timestamp when task was assigned"),
|
|
1887
1887
|
/**
|
|
1888
1888
|
* Optional deadline for task completion
|
|
1889
1889
|
*/
|
|
1890
|
-
deadline:
|
|
1890
|
+
deadline: z8.number().optional().describe("Optional task deadline timestamp")
|
|
1891
1891
|
});
|
|
1892
|
-
var TaskResultSchema =
|
|
1892
|
+
var TaskResultSchema = z8.object({
|
|
1893
1893
|
/**
|
|
1894
1894
|
* Assignment identifier
|
|
1895
1895
|
*/
|
|
1896
|
-
assignmentId:
|
|
1896
|
+
assignmentId: z8.string().describe("Assignment identifier"),
|
|
1897
1897
|
/**
|
|
1898
1898
|
* Worker that completed the task
|
|
1899
1899
|
*/
|
|
1900
|
-
workerId:
|
|
1900
|
+
workerId: z8.string().describe("Worker that completed the task"),
|
|
1901
1901
|
/**
|
|
1902
1902
|
* Whether the task succeeded
|
|
1903
1903
|
*/
|
|
1904
|
-
success:
|
|
1904
|
+
success: z8.boolean().describe("Whether the task succeeded"),
|
|
1905
1905
|
/**
|
|
1906
1906
|
* Task result/output
|
|
1907
1907
|
*/
|
|
1908
|
-
result:
|
|
1908
|
+
result: z8.string().describe("Task result or output"),
|
|
1909
1909
|
/**
|
|
1910
1910
|
* Optional error message if task failed
|
|
1911
1911
|
*/
|
|
1912
|
-
error:
|
|
1912
|
+
error: z8.string().optional().describe("Error message if task failed"),
|
|
1913
1913
|
/**
|
|
1914
1914
|
* Timestamp when task was completed
|
|
1915
1915
|
*/
|
|
1916
|
-
completedAt:
|
|
1916
|
+
completedAt: z8.number().describe("Timestamp when task was completed"),
|
|
1917
1917
|
/**
|
|
1918
1918
|
* Optional metadata about execution
|
|
1919
1919
|
*/
|
|
1920
|
-
metadata:
|
|
1920
|
+
metadata: z8.record(z8.any()).optional().describe("Execution metadata")
|
|
1921
1921
|
});
|
|
1922
|
-
var MultiAgentStatusSchema =
|
|
1922
|
+
var MultiAgentStatusSchema = z8.enum([
|
|
1923
1923
|
"initializing",
|
|
1924
1924
|
// System is initializing
|
|
1925
1925
|
"routing",
|
|
@@ -1935,27 +1935,27 @@ var MultiAgentStatusSchema = z7.enum([
|
|
|
1935
1935
|
"failed"
|
|
1936
1936
|
// Task failed
|
|
1937
1937
|
]);
|
|
1938
|
-
var HandoffRequestSchema =
|
|
1938
|
+
var HandoffRequestSchema = z8.object({
|
|
1939
1939
|
/**
|
|
1940
1940
|
* Agent requesting the handoff
|
|
1941
1941
|
*/
|
|
1942
|
-
from:
|
|
1942
|
+
from: z8.string().describe("Agent requesting handoff"),
|
|
1943
1943
|
/**
|
|
1944
1944
|
* Target agent for handoff
|
|
1945
1945
|
*/
|
|
1946
|
-
to:
|
|
1946
|
+
to: z8.string().describe("Target agent for handoff"),
|
|
1947
1947
|
/**
|
|
1948
1948
|
* Reason for handoff
|
|
1949
1949
|
*/
|
|
1950
|
-
reason:
|
|
1950
|
+
reason: z8.string().describe("Reason for requesting handoff"),
|
|
1951
1951
|
/**
|
|
1952
1952
|
* Context to pass to next agent
|
|
1953
1953
|
*/
|
|
1954
|
-
context:
|
|
1954
|
+
context: z8.any().describe("Context to pass to next agent"),
|
|
1955
1955
|
/**
|
|
1956
1956
|
* Timestamp of handoff request
|
|
1957
1957
|
*/
|
|
1958
|
-
timestamp:
|
|
1958
|
+
timestamp: z8.string().datetime().describe("ISO timestamp of handoff request")
|
|
1959
1959
|
});
|
|
1960
1960
|
|
|
1961
1961
|
// src/multi-agent/state.ts
|
|
@@ -1963,17 +1963,13 @@ var MultiAgentStateConfig = {
|
|
|
1963
1963
|
/**
|
|
1964
1964
|
* Original user input/query
|
|
1965
1965
|
*/
|
|
1966
|
-
input:
|
|
1967
|
-
schema: z8.string(),
|
|
1968
|
-
default: () => "",
|
|
1969
|
-
description: "Original user input or query"
|
|
1970
|
-
},
|
|
1966
|
+
input: inputField,
|
|
1971
1967
|
/**
|
|
1972
1968
|
* All messages in the multi-agent conversation
|
|
1973
1969
|
* Accumulates all messages between agents
|
|
1974
1970
|
*/
|
|
1975
1971
|
messages: {
|
|
1976
|
-
schema:
|
|
1972
|
+
schema: z9.array(AgentMessageSchema),
|
|
1977
1973
|
reducer: (left, right) => [...left, ...right],
|
|
1978
1974
|
default: () => [],
|
|
1979
1975
|
description: "All messages in the multi-agent conversation"
|
|
@@ -1982,7 +1978,7 @@ var MultiAgentStateConfig = {
|
|
|
1982
1978
|
* Available worker agents and their capabilities
|
|
1983
1979
|
*/
|
|
1984
1980
|
workers: {
|
|
1985
|
-
schema:
|
|
1981
|
+
schema: z9.record(z9.string(), WorkerCapabilitiesSchema),
|
|
1986
1982
|
reducer: (left, right) => ({
|
|
1987
1983
|
...left,
|
|
1988
1984
|
...right
|
|
@@ -1994,7 +1990,7 @@ var MultiAgentStateConfig = {
|
|
|
1994
1990
|
* Current active agent
|
|
1995
1991
|
*/
|
|
1996
1992
|
currentAgent: {
|
|
1997
|
-
schema:
|
|
1993
|
+
schema: z9.string().optional(),
|
|
1998
1994
|
description: "Identifier of the currently active agent"
|
|
1999
1995
|
},
|
|
2000
1996
|
/**
|
|
@@ -2002,7 +1998,7 @@ var MultiAgentStateConfig = {
|
|
|
2002
1998
|
* Accumulates all routing decisions
|
|
2003
1999
|
*/
|
|
2004
2000
|
routingHistory: {
|
|
2005
|
-
schema:
|
|
2001
|
+
schema: z9.array(RoutingDecisionSchema),
|
|
2006
2002
|
reducer: (left, right) => [...left, ...right],
|
|
2007
2003
|
default: () => [],
|
|
2008
2004
|
description: "History of routing decisions"
|
|
@@ -2011,7 +2007,7 @@ var MultiAgentStateConfig = {
|
|
|
2011
2007
|
* Active task assignments
|
|
2012
2008
|
*/
|
|
2013
2009
|
activeAssignments: {
|
|
2014
|
-
schema:
|
|
2010
|
+
schema: z9.array(TaskAssignmentSchema),
|
|
2015
2011
|
reducer: (left, right) => [...left, ...right],
|
|
2016
2012
|
default: () => [],
|
|
2017
2013
|
description: "Currently active task assignments"
|
|
@@ -2021,7 +2017,7 @@ var MultiAgentStateConfig = {
|
|
|
2021
2017
|
* Accumulates all completed tasks
|
|
2022
2018
|
*/
|
|
2023
2019
|
completedTasks: {
|
|
2024
|
-
schema:
|
|
2020
|
+
schema: z9.array(TaskResultSchema),
|
|
2025
2021
|
reducer: (left, right) => [...left, ...right],
|
|
2026
2022
|
default: () => [],
|
|
2027
2023
|
description: "Completed task results"
|
|
@@ -2031,7 +2027,7 @@ var MultiAgentStateConfig = {
|
|
|
2031
2027
|
* Accumulates all handoff requests
|
|
2032
2028
|
*/
|
|
2033
2029
|
handoffs: {
|
|
2034
|
-
schema:
|
|
2030
|
+
schema: z9.array(HandoffRequestSchema),
|
|
2035
2031
|
reducer: (left, right) => [...left, ...right],
|
|
2036
2032
|
default: () => [],
|
|
2037
2033
|
description: "Handoff requests between agents"
|
|
@@ -2047,34 +2043,19 @@ var MultiAgentStateConfig = {
|
|
|
2047
2043
|
/**
|
|
2048
2044
|
* Iteration counter
|
|
2049
2045
|
*/
|
|
2050
|
-
iteration:
|
|
2051
|
-
schema: z8.number().int().nonnegative(),
|
|
2052
|
-
reducer: (left, right) => left + right,
|
|
2053
|
-
default: () => 0,
|
|
2054
|
-
description: "Current iteration number"
|
|
2055
|
-
},
|
|
2046
|
+
iteration: iterationField,
|
|
2056
2047
|
/**
|
|
2057
2048
|
* Maximum iterations allowed
|
|
2058
2049
|
*/
|
|
2059
|
-
maxIterations:
|
|
2060
|
-
schema: z8.number().int().positive(),
|
|
2061
|
-
default: () => 10,
|
|
2062
|
-
description: "Maximum number of iterations allowed"
|
|
2063
|
-
},
|
|
2050
|
+
maxIterations: maxIterationsField(10),
|
|
2064
2051
|
/**
|
|
2065
2052
|
* Final aggregated response
|
|
2066
2053
|
*/
|
|
2067
|
-
response:
|
|
2068
|
-
schema: z8.string().optional(),
|
|
2069
|
-
description: "Final aggregated response"
|
|
2070
|
-
},
|
|
2054
|
+
response: responseField,
|
|
2071
2055
|
/**
|
|
2072
2056
|
* Error message if execution failed
|
|
2073
2057
|
*/
|
|
2074
|
-
error:
|
|
2075
|
-
schema: z8.string().optional(),
|
|
2076
|
-
description: "Error message if execution failed"
|
|
2077
|
-
}
|
|
2058
|
+
error: errorField
|
|
2078
2059
|
};
|
|
2079
2060
|
var MultiAgentState = createStateAnnotation4(MultiAgentStateConfig);
|
|
2080
2061
|
|
|
@@ -2521,14 +2502,10 @@ function wrapReActAgent(workerId, agent, verbose = false) {
|
|
|
2521
2502
|
completedTasks: [taskResult]
|
|
2522
2503
|
};
|
|
2523
2504
|
} catch (error) {
|
|
2524
|
-
|
|
2525
|
-
logger2.debug("GraphInterrupt detected - re-throwing", { workerId });
|
|
2526
|
-
throw error;
|
|
2527
|
-
}
|
|
2505
|
+
const errorMessage = handleNodeError(error, `react-agent:${workerId}`, false);
|
|
2528
2506
|
logger2.error("Error in ReAct agent execution", {
|
|
2529
2507
|
workerId,
|
|
2530
|
-
error:
|
|
2531
|
-
stack: error instanceof Error ? error.stack : void 0
|
|
2508
|
+
error: errorMessage
|
|
2532
2509
|
});
|
|
2533
2510
|
const currentAssignment = state.activeAssignments.find(
|
|
2534
2511
|
(assignment) => assignment.workerId === workerId
|
|
@@ -2539,7 +2516,7 @@ function wrapReActAgent(workerId, agent, verbose = false) {
|
|
|
2539
2516
|
workerId,
|
|
2540
2517
|
success: false,
|
|
2541
2518
|
result: "",
|
|
2542
|
-
error:
|
|
2519
|
+
error: errorMessage,
|
|
2543
2520
|
completedAt: Date.now()
|
|
2544
2521
|
};
|
|
2545
2522
|
return {
|
|
@@ -2550,7 +2527,7 @@ function wrapReActAgent(workerId, agent, verbose = false) {
|
|
|
2550
2527
|
}
|
|
2551
2528
|
return {
|
|
2552
2529
|
status: "failed",
|
|
2553
|
-
error:
|
|
2530
|
+
error: errorMessage
|
|
2554
2531
|
};
|
|
2555
2532
|
}
|
|
2556
2533
|
};
|
|
@@ -2832,14 +2809,10 @@ Execute the assigned task using your skills and tools. Provide a clear, actionab
|
|
|
2832
2809
|
workers: updatedWorkers
|
|
2833
2810
|
};
|
|
2834
2811
|
} catch (error) {
|
|
2835
|
-
|
|
2836
|
-
logger3.info("GraphInterrupt detected, re-throwing", { workerId: id });
|
|
2837
|
-
throw error;
|
|
2838
|
-
}
|
|
2812
|
+
const errorMessage = handleNodeError(error, `worker:${id}`, false);
|
|
2839
2813
|
logger3.error("Worker node error", {
|
|
2840
2814
|
workerId: id,
|
|
2841
|
-
error:
|
|
2842
|
-
stack: error instanceof Error ? error.stack : void 0
|
|
2815
|
+
error: errorMessage
|
|
2843
2816
|
});
|
|
2844
2817
|
const currentAssignment = state.activeAssignments.find(
|
|
2845
2818
|
(assignment) => assignment.workerId === id
|
|
@@ -2854,7 +2827,7 @@ Execute the assigned task using your skills and tools. Provide a clear, actionab
|
|
|
2854
2827
|
workerId: id,
|
|
2855
2828
|
success: false,
|
|
2856
2829
|
result: "",
|
|
2857
|
-
error:
|
|
2830
|
+
error: errorMessage,
|
|
2858
2831
|
completedAt: Date.now()
|
|
2859
2832
|
};
|
|
2860
2833
|
return {
|
|
@@ -2866,7 +2839,7 @@ Execute the assigned task using your skills and tools. Provide a clear, actionab
|
|
|
2866
2839
|
logger3.error("No assignment found for error handling", { workerId: id });
|
|
2867
2840
|
return {
|
|
2868
2841
|
status: "failed",
|
|
2869
|
-
error:
|
|
2842
|
+
error: errorMessage
|
|
2870
2843
|
};
|
|
2871
2844
|
}
|
|
2872
2845
|
};
|