@agentforge/patterns 0.16.46 → 0.16.48
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 +151 -142
- package/dist/index.d.cts +34 -53
- package/dist/index.d.ts +34 -53
- package/dist/index.js +151 -142
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -101,8 +101,12 @@ __export(index_exports, {
|
|
|
101
101
|
});
|
|
102
102
|
module.exports = __toCommonJS(index_exports);
|
|
103
103
|
|
|
104
|
-
// src/
|
|
104
|
+
// src/shared/json-schemas.ts
|
|
105
105
|
var import_zod = require("zod");
|
|
106
|
+
function isPlainJsonObject(value) {
|
|
107
|
+
const prototype = typeof value === "object" && value !== null ? Object.getPrototypeOf(value) : null;
|
|
108
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && (prototype === Object.prototype || prototype === null);
|
|
109
|
+
}
|
|
106
110
|
var JsonValueSchema = import_zod.z.lazy(
|
|
107
111
|
() => import_zod.z.union([
|
|
108
112
|
import_zod.z.string(),
|
|
@@ -110,74 +114,79 @@ var JsonValueSchema = import_zod.z.lazy(
|
|
|
110
114
|
import_zod.z.boolean(),
|
|
111
115
|
import_zod.z.null(),
|
|
112
116
|
import_zod.z.array(JsonValueSchema),
|
|
113
|
-
|
|
117
|
+
JsonObjectSchema
|
|
114
118
|
])
|
|
115
119
|
);
|
|
116
|
-
var JsonObjectSchema = import_zod.z.
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
var JsonObjectSchema = import_zod.z.custom(isPlainJsonObject, {
|
|
121
|
+
message: "Expected a plain JSON object"
|
|
122
|
+
}).pipe(import_zod.z.record(JsonValueSchema));
|
|
123
|
+
|
|
124
|
+
// src/react/schemas.ts
|
|
125
|
+
var import_zod2 = require("zod");
|
|
126
|
+
var MessageRoleSchema = import_zod2.z.enum(["system", "user", "assistant", "tool"]);
|
|
127
|
+
var MessageSchema = import_zod2.z.object({
|
|
119
128
|
role: MessageRoleSchema,
|
|
120
|
-
content:
|
|
121
|
-
name:
|
|
122
|
-
tool_call_id:
|
|
129
|
+
content: import_zod2.z.string(),
|
|
130
|
+
name: import_zod2.z.string().optional(),
|
|
131
|
+
tool_call_id: import_zod2.z.string().optional(),
|
|
123
132
|
metadata: JsonObjectSchema.optional()
|
|
124
133
|
});
|
|
125
|
-
var ThoughtSchema =
|
|
126
|
-
content:
|
|
127
|
-
timestamp:
|
|
134
|
+
var ThoughtSchema = import_zod2.z.object({
|
|
135
|
+
content: import_zod2.z.string(),
|
|
136
|
+
timestamp: import_zod2.z.number().optional(),
|
|
128
137
|
metadata: JsonObjectSchema.optional()
|
|
129
138
|
});
|
|
130
|
-
var ToolCallSchema =
|
|
131
|
-
id:
|
|
132
|
-
name:
|
|
133
|
-
arguments:
|
|
134
|
-
timestamp:
|
|
139
|
+
var ToolCallSchema = import_zod2.z.object({
|
|
140
|
+
id: import_zod2.z.string(),
|
|
141
|
+
name: import_zod2.z.string(),
|
|
142
|
+
arguments: import_zod2.z.record(import_zod2.z.unknown()),
|
|
143
|
+
timestamp: import_zod2.z.number().optional()
|
|
135
144
|
});
|
|
136
|
-
var ToolResultSchema =
|
|
137
|
-
toolCallId:
|
|
138
|
-
result:
|
|
139
|
-
error:
|
|
140
|
-
timestamp:
|
|
141
|
-
isDuplicate:
|
|
145
|
+
var ToolResultSchema = import_zod2.z.object({
|
|
146
|
+
toolCallId: import_zod2.z.string(),
|
|
147
|
+
result: import_zod2.z.unknown(),
|
|
148
|
+
error: import_zod2.z.string().optional(),
|
|
149
|
+
timestamp: import_zod2.z.number().optional(),
|
|
150
|
+
isDuplicate: import_zod2.z.boolean().optional()
|
|
142
151
|
// Flag indicating this was a duplicate tool call
|
|
143
152
|
});
|
|
144
|
-
var ScratchpadEntrySchema =
|
|
145
|
-
step:
|
|
146
|
-
thought:
|
|
147
|
-
action:
|
|
148
|
-
observation:
|
|
149
|
-
timestamp:
|
|
153
|
+
var ScratchpadEntrySchema = import_zod2.z.object({
|
|
154
|
+
step: import_zod2.z.number(),
|
|
155
|
+
thought: import_zod2.z.string().optional(),
|
|
156
|
+
action: import_zod2.z.string().optional(),
|
|
157
|
+
observation: import_zod2.z.string().optional(),
|
|
158
|
+
timestamp: import_zod2.z.number().optional()
|
|
150
159
|
});
|
|
151
160
|
|
|
152
161
|
// src/react/state.ts
|
|
153
|
-
var
|
|
162
|
+
var import_zod4 = require("zod");
|
|
154
163
|
var import_core = require("@agentforge/core");
|
|
155
164
|
|
|
156
165
|
// src/shared/state-fields.ts
|
|
157
|
-
var
|
|
166
|
+
var import_zod3 = require("zod");
|
|
158
167
|
var iterationField = {
|
|
159
|
-
schema:
|
|
168
|
+
schema: import_zod3.z.number().int().nonnegative(),
|
|
160
169
|
reducer: (left, right) => left + right,
|
|
161
170
|
default: () => 0,
|
|
162
171
|
description: "Current iteration number"
|
|
163
172
|
};
|
|
164
173
|
function maxIterationsField(defaultValue) {
|
|
165
174
|
return {
|
|
166
|
-
schema:
|
|
175
|
+
schema: import_zod3.z.number().int().positive(),
|
|
167
176
|
default: () => defaultValue,
|
|
168
177
|
description: "Maximum number of iterations allowed"
|
|
169
178
|
};
|
|
170
179
|
}
|
|
171
180
|
var errorField = {
|
|
172
|
-
schema:
|
|
181
|
+
schema: import_zod3.z.string().optional(),
|
|
173
182
|
description: "Error message if execution failed"
|
|
174
183
|
};
|
|
175
184
|
var responseField = {
|
|
176
|
-
schema:
|
|
185
|
+
schema: import_zod3.z.string().optional(),
|
|
177
186
|
description: "Final response after completion"
|
|
178
187
|
};
|
|
179
188
|
var inputField = {
|
|
180
|
-
schema:
|
|
189
|
+
schema: import_zod3.z.string(),
|
|
181
190
|
default: () => "",
|
|
182
191
|
description: "Original user input or query"
|
|
183
192
|
};
|
|
@@ -189,7 +198,7 @@ var ReActStateConfig = {
|
|
|
189
198
|
* Accumulates all messages in the conversation
|
|
190
199
|
*/
|
|
191
200
|
messages: {
|
|
192
|
-
schema:
|
|
201
|
+
schema: import_zod4.z.array(MessageSchema),
|
|
193
202
|
reducer: (left, right) => [...left, ...right],
|
|
194
203
|
default: () => [],
|
|
195
204
|
description: "Conversation message history"
|
|
@@ -199,7 +208,7 @@ var ReActStateConfig = {
|
|
|
199
208
|
* Accumulates all reasoning steps the agent takes
|
|
200
209
|
*/
|
|
201
210
|
thoughts: {
|
|
202
|
-
schema:
|
|
211
|
+
schema: import_zod4.z.array(ThoughtSchema),
|
|
203
212
|
reducer: (left, right) => [...left, ...right],
|
|
204
213
|
default: () => [],
|
|
205
214
|
description: "Agent reasoning steps"
|
|
@@ -209,7 +218,7 @@ var ReActStateConfig = {
|
|
|
209
218
|
* Accumulates all tool calls made by the agent
|
|
210
219
|
*/
|
|
211
220
|
actions: {
|
|
212
|
-
schema:
|
|
221
|
+
schema: import_zod4.z.array(ToolCallSchema),
|
|
213
222
|
reducer: (left, right) => [...left, ...right],
|
|
214
223
|
default: () => [],
|
|
215
224
|
description: "Tool calls made by the agent"
|
|
@@ -219,7 +228,7 @@ var ReActStateConfig = {
|
|
|
219
228
|
* Accumulates all observations from tool executions
|
|
220
229
|
*/
|
|
221
230
|
observations: {
|
|
222
|
-
schema:
|
|
231
|
+
schema: import_zod4.z.array(ToolResultSchema),
|
|
223
232
|
reducer: (left, right) => [...left, ...right],
|
|
224
233
|
default: () => [],
|
|
225
234
|
description: "Results from tool executions"
|
|
@@ -229,7 +238,7 @@ var ReActStateConfig = {
|
|
|
229
238
|
* Accumulates step-by-step reasoning process
|
|
230
239
|
*/
|
|
231
240
|
scratchpad: {
|
|
232
|
-
schema:
|
|
241
|
+
schema: import_zod4.z.array(ScratchpadEntrySchema),
|
|
233
242
|
reducer: (left, right) => [...left, ...right],
|
|
234
243
|
default: () => [],
|
|
235
244
|
description: "Intermediate reasoning scratchpad"
|
|
@@ -243,7 +252,7 @@ var ReActStateConfig = {
|
|
|
243
252
|
* Whether the agent should continue iterating
|
|
244
253
|
*/
|
|
245
254
|
shouldContinue: {
|
|
246
|
-
schema:
|
|
255
|
+
schema: import_zod4.z.boolean().optional(),
|
|
247
256
|
default: () => true,
|
|
248
257
|
description: "Whether to continue the ReAct loop"
|
|
249
258
|
},
|
|
@@ -877,34 +886,34 @@ function createReActAgentBuilder() {
|
|
|
877
886
|
var import_langgraph2 = require("@langchain/langgraph");
|
|
878
887
|
|
|
879
888
|
// src/plan-execute/state.ts
|
|
880
|
-
var
|
|
889
|
+
var import_zod6 = require("zod");
|
|
881
890
|
var import_core5 = require("@agentforge/core");
|
|
882
891
|
|
|
883
892
|
// src/plan-execute/schemas.ts
|
|
884
|
-
var
|
|
885
|
-
var PlanStepSchema =
|
|
893
|
+
var import_zod5 = require("zod");
|
|
894
|
+
var PlanStepSchema = import_zod5.z.object({
|
|
886
895
|
/**
|
|
887
896
|
* Unique identifier for the step
|
|
888
897
|
*/
|
|
889
|
-
id:
|
|
898
|
+
id: import_zod5.z.string().describe("Unique identifier for the step"),
|
|
890
899
|
/**
|
|
891
900
|
* Description of what this step should accomplish
|
|
892
901
|
*/
|
|
893
|
-
description:
|
|
902
|
+
description: import_zod5.z.string().describe("Description of what this step should accomplish"),
|
|
894
903
|
/**
|
|
895
904
|
* Optional dependencies on other steps (by ID)
|
|
896
905
|
*/
|
|
897
|
-
dependencies:
|
|
906
|
+
dependencies: import_zod5.z.array(import_zod5.z.string()).optional().describe("IDs of steps that must complete before this one"),
|
|
898
907
|
/**
|
|
899
908
|
* Optional tool to use for this step
|
|
900
909
|
*/
|
|
901
|
-
tool:
|
|
910
|
+
tool: import_zod5.z.string().optional().describe("Name of the tool to use for this step"),
|
|
902
911
|
/**
|
|
903
912
|
* Optional arguments for the tool
|
|
904
913
|
*/
|
|
905
|
-
args:
|
|
914
|
+
args: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional().describe("Arguments to pass to the tool")
|
|
906
915
|
});
|
|
907
|
-
var CompletedStepSchema =
|
|
916
|
+
var CompletedStepSchema = import_zod5.z.object({
|
|
908
917
|
/**
|
|
909
918
|
* The step that was executed
|
|
910
919
|
*/
|
|
@@ -912,53 +921,53 @@ var CompletedStepSchema = import_zod4.z.object({
|
|
|
912
921
|
/**
|
|
913
922
|
* The result of executing the step
|
|
914
923
|
*/
|
|
915
|
-
result:
|
|
924
|
+
result: import_zod5.z.unknown().describe("The result of executing the step"),
|
|
916
925
|
/**
|
|
917
926
|
* Whether the step succeeded
|
|
918
927
|
*/
|
|
919
|
-
success:
|
|
928
|
+
success: import_zod5.z.boolean().describe("Whether the step succeeded"),
|
|
920
929
|
/**
|
|
921
930
|
* Optional error message if the step failed
|
|
922
931
|
*/
|
|
923
|
-
error:
|
|
932
|
+
error: import_zod5.z.string().optional().describe("Error message if the step failed"),
|
|
924
933
|
/**
|
|
925
934
|
* Timestamp when the step was completed
|
|
926
935
|
*/
|
|
927
|
-
timestamp:
|
|
936
|
+
timestamp: import_zod5.z.string().datetime().describe("ISO timestamp when the step was completed")
|
|
928
937
|
});
|
|
929
|
-
var PlanSchema =
|
|
938
|
+
var PlanSchema = import_zod5.z.object({
|
|
930
939
|
/**
|
|
931
940
|
* List of steps in the plan
|
|
932
941
|
*/
|
|
933
|
-
steps:
|
|
942
|
+
steps: import_zod5.z.array(PlanStepSchema).describe("List of steps in the plan"),
|
|
934
943
|
/**
|
|
935
944
|
* Overall goal of the plan
|
|
936
945
|
*/
|
|
937
|
-
goal:
|
|
946
|
+
goal: import_zod5.z.string().describe("Overall goal of the plan"),
|
|
938
947
|
/**
|
|
939
948
|
* Timestamp when the plan was created
|
|
940
949
|
*/
|
|
941
|
-
createdAt:
|
|
950
|
+
createdAt: import_zod5.z.string().datetime().describe("ISO timestamp when the plan was created"),
|
|
942
951
|
/**
|
|
943
952
|
* Optional confidence score (0-1)
|
|
944
953
|
*/
|
|
945
|
-
confidence:
|
|
954
|
+
confidence: import_zod5.z.number().min(0).max(1).optional().describe("Confidence score for the plan (0-1)")
|
|
946
955
|
});
|
|
947
|
-
var ReplanDecisionSchema =
|
|
956
|
+
var ReplanDecisionSchema = import_zod5.z.object({
|
|
948
957
|
/**
|
|
949
958
|
* Whether to replan
|
|
950
959
|
*/
|
|
951
|
-
shouldReplan:
|
|
960
|
+
shouldReplan: import_zod5.z.boolean().describe("Whether to replan based on current results"),
|
|
952
961
|
/**
|
|
953
962
|
* Reason for the decision
|
|
954
963
|
*/
|
|
955
|
-
reason:
|
|
964
|
+
reason: import_zod5.z.string().describe("Reason for the replan decision"),
|
|
956
965
|
/**
|
|
957
966
|
* Optional new goal if replanning
|
|
958
967
|
*/
|
|
959
|
-
newGoal:
|
|
968
|
+
newGoal: import_zod5.z.string().optional().describe("Updated goal if replanning")
|
|
960
969
|
});
|
|
961
|
-
var ExecutionStatusSchema =
|
|
970
|
+
var ExecutionStatusSchema = import_zod5.z.enum([
|
|
962
971
|
"planning",
|
|
963
972
|
"executing",
|
|
964
973
|
"replanning",
|
|
@@ -984,7 +993,7 @@ var PlanExecuteStateConfig = {
|
|
|
984
993
|
* Accumulates all completed steps
|
|
985
994
|
*/
|
|
986
995
|
pastSteps: {
|
|
987
|
-
schema:
|
|
996
|
+
schema: import_zod6.z.array(CompletedStepSchema),
|
|
988
997
|
reducer: (left, right) => [...left, ...right],
|
|
989
998
|
default: () => [],
|
|
990
999
|
description: "Completed steps with their results"
|
|
@@ -993,7 +1002,7 @@ var PlanExecuteStateConfig = {
|
|
|
993
1002
|
* Index of the current step being executed
|
|
994
1003
|
*/
|
|
995
1004
|
currentStepIndex: {
|
|
996
|
-
schema:
|
|
1005
|
+
schema: import_zod6.z.number().int().nonnegative().optional(),
|
|
997
1006
|
description: "Index of the current step being executed"
|
|
998
1007
|
},
|
|
999
1008
|
/**
|
|
@@ -1537,46 +1546,46 @@ function createPlanExecuteAgent(config) {
|
|
|
1537
1546
|
}
|
|
1538
1547
|
|
|
1539
1548
|
// src/reflection/state.ts
|
|
1540
|
-
var
|
|
1549
|
+
var import_zod8 = require("zod");
|
|
1541
1550
|
var import_core6 = require("@agentforge/core");
|
|
1542
1551
|
|
|
1543
1552
|
// src/reflection/schemas.ts
|
|
1544
|
-
var
|
|
1545
|
-
var ReflectionSchema =
|
|
1553
|
+
var import_zod7 = require("zod");
|
|
1554
|
+
var ReflectionSchema = import_zod7.z.object({
|
|
1546
1555
|
/**
|
|
1547
1556
|
* The critique or feedback on the current response
|
|
1548
1557
|
*/
|
|
1549
|
-
critique:
|
|
1558
|
+
critique: import_zod7.z.string().describe("Critique or feedback on the current response"),
|
|
1550
1559
|
/**
|
|
1551
1560
|
* Specific issues identified
|
|
1552
1561
|
*/
|
|
1553
|
-
issues:
|
|
1562
|
+
issues: import_zod7.z.array(import_zod7.z.string()).describe("Specific issues or problems identified"),
|
|
1554
1563
|
/**
|
|
1555
1564
|
* Suggestions for improvement
|
|
1556
1565
|
*/
|
|
1557
|
-
suggestions:
|
|
1566
|
+
suggestions: import_zod7.z.array(import_zod7.z.string()).describe("Suggestions for improving the response"),
|
|
1558
1567
|
/**
|
|
1559
1568
|
* Quality score (0-10)
|
|
1560
1569
|
*/
|
|
1561
|
-
score:
|
|
1570
|
+
score: import_zod7.z.number().min(0).max(10).optional().describe("Quality score from 0 to 10"),
|
|
1562
1571
|
/**
|
|
1563
1572
|
* Whether the response meets quality standards
|
|
1564
1573
|
*/
|
|
1565
|
-
meetsStandards:
|
|
1574
|
+
meetsStandards: import_zod7.z.boolean().describe("Whether the response meets quality standards"),
|
|
1566
1575
|
/**
|
|
1567
1576
|
* Timestamp of the reflection
|
|
1568
1577
|
*/
|
|
1569
|
-
timestamp:
|
|
1578
|
+
timestamp: import_zod7.z.date().optional().describe("When this reflection was created")
|
|
1570
1579
|
});
|
|
1571
|
-
var RevisionSchema =
|
|
1580
|
+
var RevisionSchema = import_zod7.z.object({
|
|
1572
1581
|
/**
|
|
1573
1582
|
* The revised content
|
|
1574
1583
|
*/
|
|
1575
|
-
content:
|
|
1584
|
+
content: import_zod7.z.string().describe("The revised content"),
|
|
1576
1585
|
/**
|
|
1577
1586
|
* Which iteration this revision is from
|
|
1578
1587
|
*/
|
|
1579
|
-
iteration:
|
|
1588
|
+
iteration: import_zod7.z.number().int().nonnegative().describe("Iteration number"),
|
|
1580
1589
|
/**
|
|
1581
1590
|
* The reflection that prompted this revision
|
|
1582
1591
|
*/
|
|
@@ -1584,9 +1593,9 @@ var RevisionSchema = import_zod6.z.object({
|
|
|
1584
1593
|
/**
|
|
1585
1594
|
* Timestamp of the revision
|
|
1586
1595
|
*/
|
|
1587
|
-
timestamp:
|
|
1596
|
+
timestamp: import_zod7.z.date().optional().describe("When this revision was created")
|
|
1588
1597
|
});
|
|
1589
|
-
var ReflectionStatusSchema =
|
|
1598
|
+
var ReflectionStatusSchema = import_zod7.z.enum([
|
|
1590
1599
|
"generating",
|
|
1591
1600
|
// Initial generation
|
|
1592
1601
|
"reflecting",
|
|
@@ -1598,25 +1607,25 @@ var ReflectionStatusSchema = import_zod6.z.enum([
|
|
|
1598
1607
|
"failed"
|
|
1599
1608
|
// Max iterations reached without meeting standards
|
|
1600
1609
|
]);
|
|
1601
|
-
var QualityCriteriaSchema =
|
|
1610
|
+
var QualityCriteriaSchema = import_zod7.z.object({
|
|
1602
1611
|
/**
|
|
1603
1612
|
* Minimum quality score required (0-10)
|
|
1604
1613
|
*/
|
|
1605
|
-
minScore:
|
|
1614
|
+
minScore: import_zod7.z.number().min(0).max(10).default(7).describe("Minimum quality score required"),
|
|
1606
1615
|
/**
|
|
1607
1616
|
* Specific criteria to evaluate
|
|
1608
1617
|
*/
|
|
1609
|
-
criteria:
|
|
1618
|
+
criteria: import_zod7.z.array(import_zod7.z.string()).optional().describe("Specific criteria to evaluate"),
|
|
1610
1619
|
/**
|
|
1611
1620
|
* Whether all criteria must be met
|
|
1612
1621
|
*/
|
|
1613
|
-
requireAll:
|
|
1622
|
+
requireAll: import_zod7.z.boolean().default(true).describe("Whether all criteria must be met")
|
|
1614
1623
|
});
|
|
1615
|
-
var ReflectionConfigSchema =
|
|
1624
|
+
var ReflectionConfigSchema = import_zod7.z.object({
|
|
1616
1625
|
/**
|
|
1617
1626
|
* Maximum number of reflection iterations
|
|
1618
1627
|
*/
|
|
1619
|
-
maxIterations:
|
|
1628
|
+
maxIterations: import_zod7.z.number().int().positive().default(3).describe("Maximum reflection iterations"),
|
|
1620
1629
|
/**
|
|
1621
1630
|
* Quality criteria for completion
|
|
1622
1631
|
*/
|
|
@@ -1624,7 +1633,7 @@ var ReflectionConfigSchema = import_zod6.z.object({
|
|
|
1624
1633
|
/**
|
|
1625
1634
|
* Whether to include previous reflections in context
|
|
1626
1635
|
*/
|
|
1627
|
-
includeHistory:
|
|
1636
|
+
includeHistory: import_zod7.z.boolean().default(true).describe("Include previous reflections in context")
|
|
1628
1637
|
});
|
|
1629
1638
|
|
|
1630
1639
|
// src/reflection/state.ts
|
|
@@ -1637,7 +1646,7 @@ var ReflectionStateConfig = {
|
|
|
1637
1646
|
* Current response/output
|
|
1638
1647
|
*/
|
|
1639
1648
|
currentResponse: {
|
|
1640
|
-
schema:
|
|
1649
|
+
schema: import_zod8.z.string().optional(),
|
|
1641
1650
|
description: "Current response or output"
|
|
1642
1651
|
},
|
|
1643
1652
|
/**
|
|
@@ -1645,7 +1654,7 @@ var ReflectionStateConfig = {
|
|
|
1645
1654
|
* Accumulates all reflections
|
|
1646
1655
|
*/
|
|
1647
1656
|
reflections: {
|
|
1648
|
-
schema:
|
|
1657
|
+
schema: import_zod8.z.array(ReflectionSchema),
|
|
1649
1658
|
reducer: (left, right) => [...left, ...right],
|
|
1650
1659
|
default: () => [],
|
|
1651
1660
|
description: "History of all reflections and critiques"
|
|
@@ -1655,7 +1664,7 @@ var ReflectionStateConfig = {
|
|
|
1655
1664
|
* Accumulates all revisions
|
|
1656
1665
|
*/
|
|
1657
1666
|
revisions: {
|
|
1658
|
-
schema:
|
|
1667
|
+
schema: import_zod8.z.array(RevisionSchema),
|
|
1659
1668
|
reducer: (left, right) => [...left, ...right],
|
|
1660
1669
|
default: () => [],
|
|
1661
1670
|
description: "History of all revisions"
|
|
@@ -2095,13 +2104,13 @@ function createReflectionAgent(config) {
|
|
|
2095
2104
|
}
|
|
2096
2105
|
|
|
2097
2106
|
// src/multi-agent/state.ts
|
|
2098
|
-
var
|
|
2107
|
+
var import_zod10 = require("zod");
|
|
2099
2108
|
var import_core7 = require("@agentforge/core");
|
|
2100
2109
|
|
|
2101
2110
|
// src/multi-agent/schemas.ts
|
|
2102
|
-
var
|
|
2103
|
-
var AgentRoleSchema =
|
|
2104
|
-
var MessageTypeSchema =
|
|
2111
|
+
var import_zod9 = require("zod");
|
|
2112
|
+
var AgentRoleSchema = import_zod9.z.enum(["supervisor", "worker"]);
|
|
2113
|
+
var MessageTypeSchema = import_zod9.z.enum([
|
|
2105
2114
|
"user_input",
|
|
2106
2115
|
// Initial user message
|
|
2107
2116
|
"task_assignment",
|
|
@@ -2115,11 +2124,11 @@ var MessageTypeSchema = import_zod8.z.enum([
|
|
|
2115
2124
|
"completion"
|
|
2116
2125
|
// Final completion message
|
|
2117
2126
|
]);
|
|
2118
|
-
var AgentMessageSchema =
|
|
2127
|
+
var AgentMessageSchema = import_zod9.z.object({
|
|
2119
2128
|
/**
|
|
2120
2129
|
* Unique identifier for the message
|
|
2121
2130
|
*/
|
|
2122
|
-
id:
|
|
2131
|
+
id: import_zod9.z.string().describe("Unique message identifier"),
|
|
2123
2132
|
/**
|
|
2124
2133
|
* Type of message
|
|
2125
2134
|
*/
|
|
@@ -2127,25 +2136,25 @@ var AgentMessageSchema = import_zod8.z.object({
|
|
|
2127
2136
|
/**
|
|
2128
2137
|
* Agent that sent the message
|
|
2129
2138
|
*/
|
|
2130
|
-
from:
|
|
2139
|
+
from: import_zod9.z.string().describe("Agent identifier that sent the message"),
|
|
2131
2140
|
/**
|
|
2132
2141
|
* Agent(s) that should receive the message
|
|
2133
2142
|
*/
|
|
2134
|
-
to:
|
|
2143
|
+
to: import_zod9.z.union([import_zod9.z.string(), import_zod9.z.array(import_zod9.z.string())]).describe("Target agent(s)"),
|
|
2135
2144
|
/**
|
|
2136
2145
|
* Message content
|
|
2137
2146
|
*/
|
|
2138
|
-
content:
|
|
2147
|
+
content: import_zod9.z.string().describe("Message content"),
|
|
2139
2148
|
/**
|
|
2140
2149
|
* Optional metadata
|
|
2141
2150
|
*/
|
|
2142
|
-
metadata:
|
|
2151
|
+
metadata: JsonObjectSchema.optional().describe("Additional message metadata"),
|
|
2143
2152
|
/**
|
|
2144
2153
|
* Timestamp when message was created
|
|
2145
2154
|
*/
|
|
2146
|
-
timestamp:
|
|
2155
|
+
timestamp: import_zod9.z.number().describe("Timestamp when message was created")
|
|
2147
2156
|
});
|
|
2148
|
-
var RoutingStrategySchema =
|
|
2157
|
+
var RoutingStrategySchema = import_zod9.z.enum([
|
|
2149
2158
|
"llm-based",
|
|
2150
2159
|
// LLM decides which agent to route to
|
|
2151
2160
|
"rule-based",
|
|
@@ -2157,25 +2166,25 @@ var RoutingStrategySchema = import_zod8.z.enum([
|
|
|
2157
2166
|
"load-balanced"
|
|
2158
2167
|
// Route based on agent workload
|
|
2159
2168
|
]);
|
|
2160
|
-
var RoutingDecisionSchema =
|
|
2169
|
+
var RoutingDecisionSchema = import_zod9.z.object({
|
|
2161
2170
|
/**
|
|
2162
2171
|
* Target agent to route to (single agent routing)
|
|
2163
2172
|
* @deprecated Use targetAgents for parallel routing support
|
|
2164
2173
|
*/
|
|
2165
|
-
targetAgent:
|
|
2174
|
+
targetAgent: import_zod9.z.string().nullable().default(null).describe("Agent to route the task to (single routing)"),
|
|
2166
2175
|
/**
|
|
2167
2176
|
* Target agents to route to (parallel routing)
|
|
2168
2177
|
* When multiple agents are specified, they execute in parallel
|
|
2169
2178
|
*/
|
|
2170
|
-
targetAgents:
|
|
2179
|
+
targetAgents: import_zod9.z.array(import_zod9.z.string()).nullable().default(null).describe("Agents to route the task to (parallel routing)"),
|
|
2171
2180
|
/**
|
|
2172
2181
|
* Reasoning for the routing decision
|
|
2173
2182
|
*/
|
|
2174
|
-
reasoning:
|
|
2183
|
+
reasoning: import_zod9.z.string().default("").describe("Explanation for routing decision"),
|
|
2175
2184
|
/**
|
|
2176
2185
|
* Confidence in the routing decision (0-1)
|
|
2177
2186
|
*/
|
|
2178
|
-
confidence:
|
|
2187
|
+
confidence: import_zod9.z.number().min(0).max(1).default(0.8).describe("Confidence score"),
|
|
2179
2188
|
/**
|
|
2180
2189
|
* Strategy used for routing
|
|
2181
2190
|
*/
|
|
@@ -2183,86 +2192,86 @@ var RoutingDecisionSchema = import_zod8.z.object({
|
|
|
2183
2192
|
/**
|
|
2184
2193
|
* Timestamp of the routing decision
|
|
2185
2194
|
*/
|
|
2186
|
-
timestamp:
|
|
2195
|
+
timestamp: import_zod9.z.number().default(() => Date.now()).describe("Timestamp of the decision")
|
|
2187
2196
|
}).refine(
|
|
2188
2197
|
(data) => data.targetAgent || data.targetAgents && data.targetAgents.length > 0,
|
|
2189
2198
|
{ message: "Either targetAgent or targetAgents must be provided" }
|
|
2190
2199
|
);
|
|
2191
|
-
var WorkerCapabilitiesSchema =
|
|
2200
|
+
var WorkerCapabilitiesSchema = import_zod9.z.object({
|
|
2192
2201
|
/**
|
|
2193
2202
|
* Skills/capabilities the agent has
|
|
2194
2203
|
*/
|
|
2195
|
-
skills:
|
|
2204
|
+
skills: import_zod9.z.array(import_zod9.z.string()).describe("List of agent skills"),
|
|
2196
2205
|
/**
|
|
2197
2206
|
* Tools available to the agent
|
|
2198
2207
|
*/
|
|
2199
|
-
tools:
|
|
2208
|
+
tools: import_zod9.z.array(import_zod9.z.string()).describe("List of tool names available to agent"),
|
|
2200
2209
|
/**
|
|
2201
2210
|
* Whether the agent is currently available
|
|
2202
2211
|
*/
|
|
2203
|
-
available:
|
|
2212
|
+
available: import_zod9.z.boolean().default(true).describe("Whether agent is available"),
|
|
2204
2213
|
/**
|
|
2205
2214
|
* Current workload (number of active tasks)
|
|
2206
2215
|
*/
|
|
2207
|
-
currentWorkload:
|
|
2216
|
+
currentWorkload: import_zod9.z.number().int().nonnegative().default(0).describe("Current number of active tasks")
|
|
2208
2217
|
});
|
|
2209
|
-
var TaskAssignmentSchema =
|
|
2218
|
+
var TaskAssignmentSchema = import_zod9.z.object({
|
|
2210
2219
|
/**
|
|
2211
2220
|
* Unique assignment identifier
|
|
2212
2221
|
*/
|
|
2213
|
-
id:
|
|
2222
|
+
id: import_zod9.z.string().describe("Unique assignment identifier"),
|
|
2214
2223
|
/**
|
|
2215
2224
|
* Worker ID assigned to the task
|
|
2216
2225
|
*/
|
|
2217
|
-
workerId:
|
|
2226
|
+
workerId: import_zod9.z.string().describe("Worker identifier assigned to task"),
|
|
2218
2227
|
/**
|
|
2219
2228
|
* Task description
|
|
2220
2229
|
*/
|
|
2221
|
-
task:
|
|
2230
|
+
task: import_zod9.z.string().describe("Description of the task"),
|
|
2222
2231
|
/**
|
|
2223
2232
|
* Task priority (1-10, higher is more urgent)
|
|
2224
2233
|
*/
|
|
2225
|
-
priority:
|
|
2234
|
+
priority: import_zod9.z.number().int().min(1).max(10).default(5).describe("Task priority"),
|
|
2226
2235
|
/**
|
|
2227
2236
|
* Timestamp when task was assigned
|
|
2228
2237
|
*/
|
|
2229
|
-
assignedAt:
|
|
2238
|
+
assignedAt: import_zod9.z.number().describe("Timestamp when task was assigned"),
|
|
2230
2239
|
/**
|
|
2231
2240
|
* Optional deadline for task completion
|
|
2232
2241
|
*/
|
|
2233
|
-
deadline:
|
|
2242
|
+
deadline: import_zod9.z.number().optional().describe("Optional task deadline timestamp")
|
|
2234
2243
|
});
|
|
2235
|
-
var TaskResultSchema =
|
|
2244
|
+
var TaskResultSchema = import_zod9.z.object({
|
|
2236
2245
|
/**
|
|
2237
2246
|
* Assignment identifier
|
|
2238
2247
|
*/
|
|
2239
|
-
assignmentId:
|
|
2248
|
+
assignmentId: import_zod9.z.string().describe("Assignment identifier"),
|
|
2240
2249
|
/**
|
|
2241
2250
|
* Worker that completed the task
|
|
2242
2251
|
*/
|
|
2243
|
-
workerId:
|
|
2252
|
+
workerId: import_zod9.z.string().describe("Worker that completed the task"),
|
|
2244
2253
|
/**
|
|
2245
2254
|
* Whether the task succeeded
|
|
2246
2255
|
*/
|
|
2247
|
-
success:
|
|
2256
|
+
success: import_zod9.z.boolean().describe("Whether the task succeeded"),
|
|
2248
2257
|
/**
|
|
2249
2258
|
* Task result/output
|
|
2250
2259
|
*/
|
|
2251
|
-
result:
|
|
2260
|
+
result: import_zod9.z.string().describe("Task result or output"),
|
|
2252
2261
|
/**
|
|
2253
2262
|
* Optional error message if task failed
|
|
2254
2263
|
*/
|
|
2255
|
-
error:
|
|
2264
|
+
error: import_zod9.z.string().optional().describe("Error message if task failed"),
|
|
2256
2265
|
/**
|
|
2257
2266
|
* Timestamp when task was completed
|
|
2258
2267
|
*/
|
|
2259
|
-
completedAt:
|
|
2268
|
+
completedAt: import_zod9.z.number().describe("Timestamp when task was completed"),
|
|
2260
2269
|
/**
|
|
2261
2270
|
* Optional metadata about execution
|
|
2262
2271
|
*/
|
|
2263
|
-
metadata:
|
|
2272
|
+
metadata: JsonObjectSchema.optional().describe("Execution metadata")
|
|
2264
2273
|
});
|
|
2265
|
-
var MultiAgentStatusSchema =
|
|
2274
|
+
var MultiAgentStatusSchema = import_zod9.z.enum([
|
|
2266
2275
|
"initializing",
|
|
2267
2276
|
// System is initializing
|
|
2268
2277
|
"routing",
|
|
@@ -2278,27 +2287,27 @@ var MultiAgentStatusSchema = import_zod8.z.enum([
|
|
|
2278
2287
|
"failed"
|
|
2279
2288
|
// Task failed
|
|
2280
2289
|
]);
|
|
2281
|
-
var HandoffRequestSchema =
|
|
2290
|
+
var HandoffRequestSchema = import_zod9.z.object({
|
|
2282
2291
|
/**
|
|
2283
2292
|
* Agent requesting the handoff
|
|
2284
2293
|
*/
|
|
2285
|
-
from:
|
|
2294
|
+
from: import_zod9.z.string().describe("Agent requesting handoff"),
|
|
2286
2295
|
/**
|
|
2287
2296
|
* Target agent for handoff
|
|
2288
2297
|
*/
|
|
2289
|
-
to:
|
|
2298
|
+
to: import_zod9.z.string().describe("Target agent for handoff"),
|
|
2290
2299
|
/**
|
|
2291
2300
|
* Reason for handoff
|
|
2292
2301
|
*/
|
|
2293
|
-
reason:
|
|
2302
|
+
reason: import_zod9.z.string().describe("Reason for requesting handoff"),
|
|
2294
2303
|
/**
|
|
2295
2304
|
* Context to pass to next agent
|
|
2296
2305
|
*/
|
|
2297
|
-
context:
|
|
2306
|
+
context: import_zod9.z.unknown().describe("Context to pass to next agent"),
|
|
2298
2307
|
/**
|
|
2299
2308
|
* Timestamp of handoff request
|
|
2300
2309
|
*/
|
|
2301
|
-
timestamp:
|
|
2310
|
+
timestamp: import_zod9.z.string().datetime().describe("ISO timestamp of handoff request")
|
|
2302
2311
|
});
|
|
2303
2312
|
|
|
2304
2313
|
// src/multi-agent/state.ts
|
|
@@ -2312,7 +2321,7 @@ var MultiAgentStateConfig = {
|
|
|
2312
2321
|
* Accumulates all messages between agents
|
|
2313
2322
|
*/
|
|
2314
2323
|
messages: {
|
|
2315
|
-
schema:
|
|
2324
|
+
schema: import_zod10.z.array(AgentMessageSchema),
|
|
2316
2325
|
reducer: (left, right) => [...left, ...right],
|
|
2317
2326
|
default: () => [],
|
|
2318
2327
|
description: "All messages in the multi-agent conversation"
|
|
@@ -2321,7 +2330,7 @@ var MultiAgentStateConfig = {
|
|
|
2321
2330
|
* Available worker agents and their capabilities
|
|
2322
2331
|
*/
|
|
2323
2332
|
workers: {
|
|
2324
|
-
schema:
|
|
2333
|
+
schema: import_zod10.z.record(import_zod10.z.string(), WorkerCapabilitiesSchema),
|
|
2325
2334
|
reducer: (left, right) => ({
|
|
2326
2335
|
...left,
|
|
2327
2336
|
...right
|
|
@@ -2333,7 +2342,7 @@ var MultiAgentStateConfig = {
|
|
|
2333
2342
|
* Current active agent
|
|
2334
2343
|
*/
|
|
2335
2344
|
currentAgent: {
|
|
2336
|
-
schema:
|
|
2345
|
+
schema: import_zod10.z.string().optional(),
|
|
2337
2346
|
description: "Identifier of the currently active agent"
|
|
2338
2347
|
},
|
|
2339
2348
|
/**
|
|
@@ -2341,7 +2350,7 @@ var MultiAgentStateConfig = {
|
|
|
2341
2350
|
* Accumulates all routing decisions
|
|
2342
2351
|
*/
|
|
2343
2352
|
routingHistory: {
|
|
2344
|
-
schema:
|
|
2353
|
+
schema: import_zod10.z.array(RoutingDecisionSchema),
|
|
2345
2354
|
reducer: (left, right) => [...left, ...right],
|
|
2346
2355
|
default: () => [],
|
|
2347
2356
|
description: "History of routing decisions"
|
|
@@ -2350,7 +2359,7 @@ var MultiAgentStateConfig = {
|
|
|
2350
2359
|
* Active task assignments
|
|
2351
2360
|
*/
|
|
2352
2361
|
activeAssignments: {
|
|
2353
|
-
schema:
|
|
2362
|
+
schema: import_zod10.z.array(TaskAssignmentSchema),
|
|
2354
2363
|
reducer: (left, right) => [...left, ...right],
|
|
2355
2364
|
default: () => [],
|
|
2356
2365
|
description: "Currently active task assignments"
|
|
@@ -2360,7 +2369,7 @@ var MultiAgentStateConfig = {
|
|
|
2360
2369
|
* Accumulates all completed tasks
|
|
2361
2370
|
*/
|
|
2362
2371
|
completedTasks: {
|
|
2363
|
-
schema:
|
|
2372
|
+
schema: import_zod10.z.array(TaskResultSchema),
|
|
2364
2373
|
reducer: (left, right) => [...left, ...right],
|
|
2365
2374
|
default: () => [],
|
|
2366
2375
|
description: "Completed task results"
|
|
@@ -2370,7 +2379,7 @@ var MultiAgentStateConfig = {
|
|
|
2370
2379
|
* Accumulates all handoff requests
|
|
2371
2380
|
*/
|
|
2372
2381
|
handoffs: {
|
|
2373
|
-
schema:
|
|
2382
|
+
schema: import_zod10.z.array(HandoffRequestSchema),
|
|
2374
2383
|
reducer: (left, right) => [...left, ...right],
|
|
2375
2384
|
default: () => [],
|
|
2376
2385
|
description: "Handoff requests between agents"
|