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