@agentforge/patterns 0.16.46 → 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 +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.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/shared/json-schemas.ts
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
function isPlainJsonObject(value) {
|
|
4
|
+
const prototype = typeof value === "object" && value !== null ? Object.getPrototypeOf(value) : null;
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && (prototype === Object.prototype || prototype === null);
|
|
6
|
+
}
|
|
3
7
|
var JsonValueSchema = z.lazy(
|
|
4
8
|
() => z.union([
|
|
5
9
|
z.string(),
|
|
@@ -7,74 +11,79 @@ var JsonValueSchema = z.lazy(
|
|
|
7
11
|
z.boolean(),
|
|
8
12
|
z.null(),
|
|
9
13
|
z.array(JsonValueSchema),
|
|
10
|
-
|
|
14
|
+
JsonObjectSchema
|
|
11
15
|
])
|
|
12
16
|
);
|
|
13
|
-
var JsonObjectSchema = z.
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
var JsonObjectSchema = z.custom(isPlainJsonObject, {
|
|
18
|
+
message: "Expected a plain JSON object"
|
|
19
|
+
}).pipe(z.record(JsonValueSchema));
|
|
20
|
+
|
|
21
|
+
// src/react/schemas.ts
|
|
22
|
+
import { z as z2 } from "zod";
|
|
23
|
+
var MessageRoleSchema = z2.enum(["system", "user", "assistant", "tool"]);
|
|
24
|
+
var MessageSchema = z2.object({
|
|
16
25
|
role: MessageRoleSchema,
|
|
17
|
-
content:
|
|
18
|
-
name:
|
|
19
|
-
tool_call_id:
|
|
26
|
+
content: z2.string(),
|
|
27
|
+
name: z2.string().optional(),
|
|
28
|
+
tool_call_id: z2.string().optional(),
|
|
20
29
|
metadata: JsonObjectSchema.optional()
|
|
21
30
|
});
|
|
22
|
-
var ThoughtSchema =
|
|
23
|
-
content:
|
|
24
|
-
timestamp:
|
|
31
|
+
var ThoughtSchema = z2.object({
|
|
32
|
+
content: z2.string(),
|
|
33
|
+
timestamp: z2.number().optional(),
|
|
25
34
|
metadata: JsonObjectSchema.optional()
|
|
26
35
|
});
|
|
27
|
-
var ToolCallSchema =
|
|
28
|
-
id:
|
|
29
|
-
name:
|
|
30
|
-
arguments:
|
|
31
|
-
timestamp:
|
|
36
|
+
var ToolCallSchema = z2.object({
|
|
37
|
+
id: z2.string(),
|
|
38
|
+
name: z2.string(),
|
|
39
|
+
arguments: z2.record(z2.unknown()),
|
|
40
|
+
timestamp: z2.number().optional()
|
|
32
41
|
});
|
|
33
|
-
var ToolResultSchema =
|
|
34
|
-
toolCallId:
|
|
35
|
-
result:
|
|
36
|
-
error:
|
|
37
|
-
timestamp:
|
|
38
|
-
isDuplicate:
|
|
42
|
+
var ToolResultSchema = z2.object({
|
|
43
|
+
toolCallId: z2.string(),
|
|
44
|
+
result: z2.unknown(),
|
|
45
|
+
error: z2.string().optional(),
|
|
46
|
+
timestamp: z2.number().optional(),
|
|
47
|
+
isDuplicate: z2.boolean().optional()
|
|
39
48
|
// Flag indicating this was a duplicate tool call
|
|
40
49
|
});
|
|
41
|
-
var ScratchpadEntrySchema =
|
|
42
|
-
step:
|
|
43
|
-
thought:
|
|
44
|
-
action:
|
|
45
|
-
observation:
|
|
46
|
-
timestamp:
|
|
50
|
+
var ScratchpadEntrySchema = z2.object({
|
|
51
|
+
step: z2.number(),
|
|
52
|
+
thought: z2.string().optional(),
|
|
53
|
+
action: z2.string().optional(),
|
|
54
|
+
observation: z2.string().optional(),
|
|
55
|
+
timestamp: z2.number().optional()
|
|
47
56
|
});
|
|
48
57
|
|
|
49
58
|
// src/react/state.ts
|
|
50
|
-
import { z as
|
|
59
|
+
import { z as z4 } from "zod";
|
|
51
60
|
import { createStateAnnotation } from "@agentforge/core";
|
|
52
61
|
|
|
53
62
|
// src/shared/state-fields.ts
|
|
54
|
-
import { z as
|
|
63
|
+
import { z as z3 } from "zod";
|
|
55
64
|
var iterationField = {
|
|
56
|
-
schema:
|
|
65
|
+
schema: z3.number().int().nonnegative(),
|
|
57
66
|
reducer: (left, right) => left + right,
|
|
58
67
|
default: () => 0,
|
|
59
68
|
description: "Current iteration number"
|
|
60
69
|
};
|
|
61
70
|
function maxIterationsField(defaultValue) {
|
|
62
71
|
return {
|
|
63
|
-
schema:
|
|
72
|
+
schema: z3.number().int().positive(),
|
|
64
73
|
default: () => defaultValue,
|
|
65
74
|
description: "Maximum number of iterations allowed"
|
|
66
75
|
};
|
|
67
76
|
}
|
|
68
77
|
var errorField = {
|
|
69
|
-
schema:
|
|
78
|
+
schema: z3.string().optional(),
|
|
70
79
|
description: "Error message if execution failed"
|
|
71
80
|
};
|
|
72
81
|
var responseField = {
|
|
73
|
-
schema:
|
|
82
|
+
schema: z3.string().optional(),
|
|
74
83
|
description: "Final response after completion"
|
|
75
84
|
};
|
|
76
85
|
var inputField = {
|
|
77
|
-
schema:
|
|
86
|
+
schema: z3.string(),
|
|
78
87
|
default: () => "",
|
|
79
88
|
description: "Original user input or query"
|
|
80
89
|
};
|
|
@@ -86,7 +95,7 @@ var ReActStateConfig = {
|
|
|
86
95
|
* Accumulates all messages in the conversation
|
|
87
96
|
*/
|
|
88
97
|
messages: {
|
|
89
|
-
schema:
|
|
98
|
+
schema: z4.array(MessageSchema),
|
|
90
99
|
reducer: (left, right) => [...left, ...right],
|
|
91
100
|
default: () => [],
|
|
92
101
|
description: "Conversation message history"
|
|
@@ -96,7 +105,7 @@ var ReActStateConfig = {
|
|
|
96
105
|
* Accumulates all reasoning steps the agent takes
|
|
97
106
|
*/
|
|
98
107
|
thoughts: {
|
|
99
|
-
schema:
|
|
108
|
+
schema: z4.array(ThoughtSchema),
|
|
100
109
|
reducer: (left, right) => [...left, ...right],
|
|
101
110
|
default: () => [],
|
|
102
111
|
description: "Agent reasoning steps"
|
|
@@ -106,7 +115,7 @@ var ReActStateConfig = {
|
|
|
106
115
|
* Accumulates all tool calls made by the agent
|
|
107
116
|
*/
|
|
108
117
|
actions: {
|
|
109
|
-
schema:
|
|
118
|
+
schema: z4.array(ToolCallSchema),
|
|
110
119
|
reducer: (left, right) => [...left, ...right],
|
|
111
120
|
default: () => [],
|
|
112
121
|
description: "Tool calls made by the agent"
|
|
@@ -116,7 +125,7 @@ var ReActStateConfig = {
|
|
|
116
125
|
* Accumulates all observations from tool executions
|
|
117
126
|
*/
|
|
118
127
|
observations: {
|
|
119
|
-
schema:
|
|
128
|
+
schema: z4.array(ToolResultSchema),
|
|
120
129
|
reducer: (left, right) => [...left, ...right],
|
|
121
130
|
default: () => [],
|
|
122
131
|
description: "Results from tool executions"
|
|
@@ -126,7 +135,7 @@ var ReActStateConfig = {
|
|
|
126
135
|
* Accumulates step-by-step reasoning process
|
|
127
136
|
*/
|
|
128
137
|
scratchpad: {
|
|
129
|
-
schema:
|
|
138
|
+
schema: z4.array(ScratchpadEntrySchema),
|
|
130
139
|
reducer: (left, right) => [...left, ...right],
|
|
131
140
|
default: () => [],
|
|
132
141
|
description: "Intermediate reasoning scratchpad"
|
|
@@ -140,7 +149,7 @@ var ReActStateConfig = {
|
|
|
140
149
|
* Whether the agent should continue iterating
|
|
141
150
|
*/
|
|
142
151
|
shouldContinue: {
|
|
143
|
-
schema:
|
|
152
|
+
schema: z4.boolean().optional(),
|
|
144
153
|
default: () => true,
|
|
145
154
|
description: "Whether to continue the ReAct loop"
|
|
146
155
|
},
|
|
@@ -779,34 +788,34 @@ function createReActAgentBuilder() {
|
|
|
779
788
|
import { StateGraph as StateGraph2, END as END2 } from "@langchain/langgraph";
|
|
780
789
|
|
|
781
790
|
// src/plan-execute/state.ts
|
|
782
|
-
import { z as
|
|
791
|
+
import { z as z6 } from "zod";
|
|
783
792
|
import { createStateAnnotation as createStateAnnotation2 } from "@agentforge/core";
|
|
784
793
|
|
|
785
794
|
// src/plan-execute/schemas.ts
|
|
786
|
-
import { z as
|
|
787
|
-
var PlanStepSchema =
|
|
795
|
+
import { z as z5 } from "zod";
|
|
796
|
+
var PlanStepSchema = z5.object({
|
|
788
797
|
/**
|
|
789
798
|
* Unique identifier for the step
|
|
790
799
|
*/
|
|
791
|
-
id:
|
|
800
|
+
id: z5.string().describe("Unique identifier for the step"),
|
|
792
801
|
/**
|
|
793
802
|
* Description of what this step should accomplish
|
|
794
803
|
*/
|
|
795
|
-
description:
|
|
804
|
+
description: z5.string().describe("Description of what this step should accomplish"),
|
|
796
805
|
/**
|
|
797
806
|
* Optional dependencies on other steps (by ID)
|
|
798
807
|
*/
|
|
799
|
-
dependencies:
|
|
808
|
+
dependencies: z5.array(z5.string()).optional().describe("IDs of steps that must complete before this one"),
|
|
800
809
|
/**
|
|
801
810
|
* Optional tool to use for this step
|
|
802
811
|
*/
|
|
803
|
-
tool:
|
|
812
|
+
tool: z5.string().optional().describe("Name of the tool to use for this step"),
|
|
804
813
|
/**
|
|
805
814
|
* Optional arguments for the tool
|
|
806
815
|
*/
|
|
807
|
-
args:
|
|
816
|
+
args: z5.record(z5.string(), z5.unknown()).optional().describe("Arguments to pass to the tool")
|
|
808
817
|
});
|
|
809
|
-
var CompletedStepSchema =
|
|
818
|
+
var CompletedStepSchema = z5.object({
|
|
810
819
|
/**
|
|
811
820
|
* The step that was executed
|
|
812
821
|
*/
|
|
@@ -814,53 +823,53 @@ var CompletedStepSchema = z4.object({
|
|
|
814
823
|
/**
|
|
815
824
|
* The result of executing the step
|
|
816
825
|
*/
|
|
817
|
-
result:
|
|
826
|
+
result: z5.unknown().describe("The result of executing the step"),
|
|
818
827
|
/**
|
|
819
828
|
* Whether the step succeeded
|
|
820
829
|
*/
|
|
821
|
-
success:
|
|
830
|
+
success: z5.boolean().describe("Whether the step succeeded"),
|
|
822
831
|
/**
|
|
823
832
|
* Optional error message if the step failed
|
|
824
833
|
*/
|
|
825
|
-
error:
|
|
834
|
+
error: z5.string().optional().describe("Error message if the step failed"),
|
|
826
835
|
/**
|
|
827
836
|
* Timestamp when the step was completed
|
|
828
837
|
*/
|
|
829
|
-
timestamp:
|
|
838
|
+
timestamp: z5.string().datetime().describe("ISO timestamp when the step was completed")
|
|
830
839
|
});
|
|
831
|
-
var PlanSchema =
|
|
840
|
+
var PlanSchema = z5.object({
|
|
832
841
|
/**
|
|
833
842
|
* List of steps in the plan
|
|
834
843
|
*/
|
|
835
|
-
steps:
|
|
844
|
+
steps: z5.array(PlanStepSchema).describe("List of steps in the plan"),
|
|
836
845
|
/**
|
|
837
846
|
* Overall goal of the plan
|
|
838
847
|
*/
|
|
839
|
-
goal:
|
|
848
|
+
goal: z5.string().describe("Overall goal of the plan"),
|
|
840
849
|
/**
|
|
841
850
|
* Timestamp when the plan was created
|
|
842
851
|
*/
|
|
843
|
-
createdAt:
|
|
852
|
+
createdAt: z5.string().datetime().describe("ISO timestamp when the plan was created"),
|
|
844
853
|
/**
|
|
845
854
|
* Optional confidence score (0-1)
|
|
846
855
|
*/
|
|
847
|
-
confidence:
|
|
856
|
+
confidence: z5.number().min(0).max(1).optional().describe("Confidence score for the plan (0-1)")
|
|
848
857
|
});
|
|
849
|
-
var ReplanDecisionSchema =
|
|
858
|
+
var ReplanDecisionSchema = z5.object({
|
|
850
859
|
/**
|
|
851
860
|
* Whether to replan
|
|
852
861
|
*/
|
|
853
|
-
shouldReplan:
|
|
862
|
+
shouldReplan: z5.boolean().describe("Whether to replan based on current results"),
|
|
854
863
|
/**
|
|
855
864
|
* Reason for the decision
|
|
856
865
|
*/
|
|
857
|
-
reason:
|
|
866
|
+
reason: z5.string().describe("Reason for the replan decision"),
|
|
858
867
|
/**
|
|
859
868
|
* Optional new goal if replanning
|
|
860
869
|
*/
|
|
861
|
-
newGoal:
|
|
870
|
+
newGoal: z5.string().optional().describe("Updated goal if replanning")
|
|
862
871
|
});
|
|
863
|
-
var ExecutionStatusSchema =
|
|
872
|
+
var ExecutionStatusSchema = z5.enum([
|
|
864
873
|
"planning",
|
|
865
874
|
"executing",
|
|
866
875
|
"replanning",
|
|
@@ -886,7 +895,7 @@ var PlanExecuteStateConfig = {
|
|
|
886
895
|
* Accumulates all completed steps
|
|
887
896
|
*/
|
|
888
897
|
pastSteps: {
|
|
889
|
-
schema:
|
|
898
|
+
schema: z6.array(CompletedStepSchema),
|
|
890
899
|
reducer: (left, right) => [...left, ...right],
|
|
891
900
|
default: () => [],
|
|
892
901
|
description: "Completed steps with their results"
|
|
@@ -895,7 +904,7 @@ var PlanExecuteStateConfig = {
|
|
|
895
904
|
* Index of the current step being executed
|
|
896
905
|
*/
|
|
897
906
|
currentStepIndex: {
|
|
898
|
-
schema:
|
|
907
|
+
schema: z6.number().int().nonnegative().optional(),
|
|
899
908
|
description: "Index of the current step being executed"
|
|
900
909
|
},
|
|
901
910
|
/**
|
|
@@ -1439,46 +1448,46 @@ function createPlanExecuteAgent(config) {
|
|
|
1439
1448
|
}
|
|
1440
1449
|
|
|
1441
1450
|
// src/reflection/state.ts
|
|
1442
|
-
import { z as
|
|
1451
|
+
import { z as z8 } from "zod";
|
|
1443
1452
|
import { createStateAnnotation as createStateAnnotation3 } from "@agentforge/core";
|
|
1444
1453
|
|
|
1445
1454
|
// src/reflection/schemas.ts
|
|
1446
|
-
import { z as
|
|
1447
|
-
var ReflectionSchema =
|
|
1455
|
+
import { z as z7 } from "zod";
|
|
1456
|
+
var ReflectionSchema = z7.object({
|
|
1448
1457
|
/**
|
|
1449
1458
|
* The critique or feedback on the current response
|
|
1450
1459
|
*/
|
|
1451
|
-
critique:
|
|
1460
|
+
critique: z7.string().describe("Critique or feedback on the current response"),
|
|
1452
1461
|
/**
|
|
1453
1462
|
* Specific issues identified
|
|
1454
1463
|
*/
|
|
1455
|
-
issues:
|
|
1464
|
+
issues: z7.array(z7.string()).describe("Specific issues or problems identified"),
|
|
1456
1465
|
/**
|
|
1457
1466
|
* Suggestions for improvement
|
|
1458
1467
|
*/
|
|
1459
|
-
suggestions:
|
|
1468
|
+
suggestions: z7.array(z7.string()).describe("Suggestions for improving the response"),
|
|
1460
1469
|
/**
|
|
1461
1470
|
* Quality score (0-10)
|
|
1462
1471
|
*/
|
|
1463
|
-
score:
|
|
1472
|
+
score: z7.number().min(0).max(10).optional().describe("Quality score from 0 to 10"),
|
|
1464
1473
|
/**
|
|
1465
1474
|
* Whether the response meets quality standards
|
|
1466
1475
|
*/
|
|
1467
|
-
meetsStandards:
|
|
1476
|
+
meetsStandards: z7.boolean().describe("Whether the response meets quality standards"),
|
|
1468
1477
|
/**
|
|
1469
1478
|
* Timestamp of the reflection
|
|
1470
1479
|
*/
|
|
1471
|
-
timestamp:
|
|
1480
|
+
timestamp: z7.date().optional().describe("When this reflection was created")
|
|
1472
1481
|
});
|
|
1473
|
-
var RevisionSchema =
|
|
1482
|
+
var RevisionSchema = z7.object({
|
|
1474
1483
|
/**
|
|
1475
1484
|
* The revised content
|
|
1476
1485
|
*/
|
|
1477
|
-
content:
|
|
1486
|
+
content: z7.string().describe("The revised content"),
|
|
1478
1487
|
/**
|
|
1479
1488
|
* Which iteration this revision is from
|
|
1480
1489
|
*/
|
|
1481
|
-
iteration:
|
|
1490
|
+
iteration: z7.number().int().nonnegative().describe("Iteration number"),
|
|
1482
1491
|
/**
|
|
1483
1492
|
* The reflection that prompted this revision
|
|
1484
1493
|
*/
|
|
@@ -1486,9 +1495,9 @@ var RevisionSchema = z6.object({
|
|
|
1486
1495
|
/**
|
|
1487
1496
|
* Timestamp of the revision
|
|
1488
1497
|
*/
|
|
1489
|
-
timestamp:
|
|
1498
|
+
timestamp: z7.date().optional().describe("When this revision was created")
|
|
1490
1499
|
});
|
|
1491
|
-
var ReflectionStatusSchema =
|
|
1500
|
+
var ReflectionStatusSchema = z7.enum([
|
|
1492
1501
|
"generating",
|
|
1493
1502
|
// Initial generation
|
|
1494
1503
|
"reflecting",
|
|
@@ -1500,25 +1509,25 @@ var ReflectionStatusSchema = z6.enum([
|
|
|
1500
1509
|
"failed"
|
|
1501
1510
|
// Max iterations reached without meeting standards
|
|
1502
1511
|
]);
|
|
1503
|
-
var QualityCriteriaSchema =
|
|
1512
|
+
var QualityCriteriaSchema = z7.object({
|
|
1504
1513
|
/**
|
|
1505
1514
|
* Minimum quality score required (0-10)
|
|
1506
1515
|
*/
|
|
1507
|
-
minScore:
|
|
1516
|
+
minScore: z7.number().min(0).max(10).default(7).describe("Minimum quality score required"),
|
|
1508
1517
|
/**
|
|
1509
1518
|
* Specific criteria to evaluate
|
|
1510
1519
|
*/
|
|
1511
|
-
criteria:
|
|
1520
|
+
criteria: z7.array(z7.string()).optional().describe("Specific criteria to evaluate"),
|
|
1512
1521
|
/**
|
|
1513
1522
|
* Whether all criteria must be met
|
|
1514
1523
|
*/
|
|
1515
|
-
requireAll:
|
|
1524
|
+
requireAll: z7.boolean().default(true).describe("Whether all criteria must be met")
|
|
1516
1525
|
});
|
|
1517
|
-
var ReflectionConfigSchema =
|
|
1526
|
+
var ReflectionConfigSchema = z7.object({
|
|
1518
1527
|
/**
|
|
1519
1528
|
* Maximum number of reflection iterations
|
|
1520
1529
|
*/
|
|
1521
|
-
maxIterations:
|
|
1530
|
+
maxIterations: z7.number().int().positive().default(3).describe("Maximum reflection iterations"),
|
|
1522
1531
|
/**
|
|
1523
1532
|
* Quality criteria for completion
|
|
1524
1533
|
*/
|
|
@@ -1526,7 +1535,7 @@ var ReflectionConfigSchema = z6.object({
|
|
|
1526
1535
|
/**
|
|
1527
1536
|
* Whether to include previous reflections in context
|
|
1528
1537
|
*/
|
|
1529
|
-
includeHistory:
|
|
1538
|
+
includeHistory: z7.boolean().default(true).describe("Include previous reflections in context")
|
|
1530
1539
|
});
|
|
1531
1540
|
|
|
1532
1541
|
// src/reflection/state.ts
|
|
@@ -1539,7 +1548,7 @@ var ReflectionStateConfig = {
|
|
|
1539
1548
|
* Current response/output
|
|
1540
1549
|
*/
|
|
1541
1550
|
currentResponse: {
|
|
1542
|
-
schema:
|
|
1551
|
+
schema: z8.string().optional(),
|
|
1543
1552
|
description: "Current response or output"
|
|
1544
1553
|
},
|
|
1545
1554
|
/**
|
|
@@ -1547,7 +1556,7 @@ var ReflectionStateConfig = {
|
|
|
1547
1556
|
* Accumulates all reflections
|
|
1548
1557
|
*/
|
|
1549
1558
|
reflections: {
|
|
1550
|
-
schema:
|
|
1559
|
+
schema: z8.array(ReflectionSchema),
|
|
1551
1560
|
reducer: (left, right) => [...left, ...right],
|
|
1552
1561
|
default: () => [],
|
|
1553
1562
|
description: "History of all reflections and critiques"
|
|
@@ -1557,7 +1566,7 @@ var ReflectionStateConfig = {
|
|
|
1557
1566
|
* Accumulates all revisions
|
|
1558
1567
|
*/
|
|
1559
1568
|
revisions: {
|
|
1560
|
-
schema:
|
|
1569
|
+
schema: z8.array(RevisionSchema),
|
|
1561
1570
|
reducer: (left, right) => [...left, ...right],
|
|
1562
1571
|
default: () => [],
|
|
1563
1572
|
description: "History of all revisions"
|
|
@@ -1997,13 +2006,13 @@ function createReflectionAgent(config) {
|
|
|
1997
2006
|
}
|
|
1998
2007
|
|
|
1999
2008
|
// src/multi-agent/state.ts
|
|
2000
|
-
import { z as
|
|
2009
|
+
import { z as z10 } from "zod";
|
|
2001
2010
|
import { createStateAnnotation as createStateAnnotation4 } from "@agentforge/core";
|
|
2002
2011
|
|
|
2003
2012
|
// src/multi-agent/schemas.ts
|
|
2004
|
-
import { z as
|
|
2005
|
-
var AgentRoleSchema =
|
|
2006
|
-
var MessageTypeSchema =
|
|
2013
|
+
import { z as z9 } from "zod";
|
|
2014
|
+
var AgentRoleSchema = z9.enum(["supervisor", "worker"]);
|
|
2015
|
+
var MessageTypeSchema = z9.enum([
|
|
2007
2016
|
"user_input",
|
|
2008
2017
|
// Initial user message
|
|
2009
2018
|
"task_assignment",
|
|
@@ -2017,11 +2026,11 @@ var MessageTypeSchema = z8.enum([
|
|
|
2017
2026
|
"completion"
|
|
2018
2027
|
// Final completion message
|
|
2019
2028
|
]);
|
|
2020
|
-
var AgentMessageSchema =
|
|
2029
|
+
var AgentMessageSchema = z9.object({
|
|
2021
2030
|
/**
|
|
2022
2031
|
* Unique identifier for the message
|
|
2023
2032
|
*/
|
|
2024
|
-
id:
|
|
2033
|
+
id: z9.string().describe("Unique message identifier"),
|
|
2025
2034
|
/**
|
|
2026
2035
|
* Type of message
|
|
2027
2036
|
*/
|
|
@@ -2029,25 +2038,25 @@ var AgentMessageSchema = z8.object({
|
|
|
2029
2038
|
/**
|
|
2030
2039
|
* Agent that sent the message
|
|
2031
2040
|
*/
|
|
2032
|
-
from:
|
|
2041
|
+
from: z9.string().describe("Agent identifier that sent the message"),
|
|
2033
2042
|
/**
|
|
2034
2043
|
* Agent(s) that should receive the message
|
|
2035
2044
|
*/
|
|
2036
|
-
to:
|
|
2045
|
+
to: z9.union([z9.string(), z9.array(z9.string())]).describe("Target agent(s)"),
|
|
2037
2046
|
/**
|
|
2038
2047
|
* Message content
|
|
2039
2048
|
*/
|
|
2040
|
-
content:
|
|
2049
|
+
content: z9.string().describe("Message content"),
|
|
2041
2050
|
/**
|
|
2042
2051
|
* Optional metadata
|
|
2043
2052
|
*/
|
|
2044
|
-
metadata:
|
|
2053
|
+
metadata: JsonObjectSchema.optional().describe("Additional message metadata"),
|
|
2045
2054
|
/**
|
|
2046
2055
|
* Timestamp when message was created
|
|
2047
2056
|
*/
|
|
2048
|
-
timestamp:
|
|
2057
|
+
timestamp: z9.number().describe("Timestamp when message was created")
|
|
2049
2058
|
});
|
|
2050
|
-
var RoutingStrategySchema =
|
|
2059
|
+
var RoutingStrategySchema = z9.enum([
|
|
2051
2060
|
"llm-based",
|
|
2052
2061
|
// LLM decides which agent to route to
|
|
2053
2062
|
"rule-based",
|
|
@@ -2059,25 +2068,25 @@ var RoutingStrategySchema = z8.enum([
|
|
|
2059
2068
|
"load-balanced"
|
|
2060
2069
|
// Route based on agent workload
|
|
2061
2070
|
]);
|
|
2062
|
-
var RoutingDecisionSchema =
|
|
2071
|
+
var RoutingDecisionSchema = z9.object({
|
|
2063
2072
|
/**
|
|
2064
2073
|
* Target agent to route to (single agent routing)
|
|
2065
2074
|
* @deprecated Use targetAgents for parallel routing support
|
|
2066
2075
|
*/
|
|
2067
|
-
targetAgent:
|
|
2076
|
+
targetAgent: z9.string().nullable().default(null).describe("Agent to route the task to (single routing)"),
|
|
2068
2077
|
/**
|
|
2069
2078
|
* Target agents to route to (parallel routing)
|
|
2070
2079
|
* When multiple agents are specified, they execute in parallel
|
|
2071
2080
|
*/
|
|
2072
|
-
targetAgents:
|
|
2081
|
+
targetAgents: z9.array(z9.string()).nullable().default(null).describe("Agents to route the task to (parallel routing)"),
|
|
2073
2082
|
/**
|
|
2074
2083
|
* Reasoning for the routing decision
|
|
2075
2084
|
*/
|
|
2076
|
-
reasoning:
|
|
2085
|
+
reasoning: z9.string().default("").describe("Explanation for routing decision"),
|
|
2077
2086
|
/**
|
|
2078
2087
|
* Confidence in the routing decision (0-1)
|
|
2079
2088
|
*/
|
|
2080
|
-
confidence:
|
|
2089
|
+
confidence: z9.number().min(0).max(1).default(0.8).describe("Confidence score"),
|
|
2081
2090
|
/**
|
|
2082
2091
|
* Strategy used for routing
|
|
2083
2092
|
*/
|
|
@@ -2085,86 +2094,86 @@ var RoutingDecisionSchema = z8.object({
|
|
|
2085
2094
|
/**
|
|
2086
2095
|
* Timestamp of the routing decision
|
|
2087
2096
|
*/
|
|
2088
|
-
timestamp:
|
|
2097
|
+
timestamp: z9.number().default(() => Date.now()).describe("Timestamp of the decision")
|
|
2089
2098
|
}).refine(
|
|
2090
2099
|
(data) => data.targetAgent || data.targetAgents && data.targetAgents.length > 0,
|
|
2091
2100
|
{ message: "Either targetAgent or targetAgents must be provided" }
|
|
2092
2101
|
);
|
|
2093
|
-
var WorkerCapabilitiesSchema =
|
|
2102
|
+
var WorkerCapabilitiesSchema = z9.object({
|
|
2094
2103
|
/**
|
|
2095
2104
|
* Skills/capabilities the agent has
|
|
2096
2105
|
*/
|
|
2097
|
-
skills:
|
|
2106
|
+
skills: z9.array(z9.string()).describe("List of agent skills"),
|
|
2098
2107
|
/**
|
|
2099
2108
|
* Tools available to the agent
|
|
2100
2109
|
*/
|
|
2101
|
-
tools:
|
|
2110
|
+
tools: z9.array(z9.string()).describe("List of tool names available to agent"),
|
|
2102
2111
|
/**
|
|
2103
2112
|
* Whether the agent is currently available
|
|
2104
2113
|
*/
|
|
2105
|
-
available:
|
|
2114
|
+
available: z9.boolean().default(true).describe("Whether agent is available"),
|
|
2106
2115
|
/**
|
|
2107
2116
|
* Current workload (number of active tasks)
|
|
2108
2117
|
*/
|
|
2109
|
-
currentWorkload:
|
|
2118
|
+
currentWorkload: z9.number().int().nonnegative().default(0).describe("Current number of active tasks")
|
|
2110
2119
|
});
|
|
2111
|
-
var TaskAssignmentSchema =
|
|
2120
|
+
var TaskAssignmentSchema = z9.object({
|
|
2112
2121
|
/**
|
|
2113
2122
|
* Unique assignment identifier
|
|
2114
2123
|
*/
|
|
2115
|
-
id:
|
|
2124
|
+
id: z9.string().describe("Unique assignment identifier"),
|
|
2116
2125
|
/**
|
|
2117
2126
|
* Worker ID assigned to the task
|
|
2118
2127
|
*/
|
|
2119
|
-
workerId:
|
|
2128
|
+
workerId: z9.string().describe("Worker identifier assigned to task"),
|
|
2120
2129
|
/**
|
|
2121
2130
|
* Task description
|
|
2122
2131
|
*/
|
|
2123
|
-
task:
|
|
2132
|
+
task: z9.string().describe("Description of the task"),
|
|
2124
2133
|
/**
|
|
2125
2134
|
* Task priority (1-10, higher is more urgent)
|
|
2126
2135
|
*/
|
|
2127
|
-
priority:
|
|
2136
|
+
priority: z9.number().int().min(1).max(10).default(5).describe("Task priority"),
|
|
2128
2137
|
/**
|
|
2129
2138
|
* Timestamp when task was assigned
|
|
2130
2139
|
*/
|
|
2131
|
-
assignedAt:
|
|
2140
|
+
assignedAt: z9.number().describe("Timestamp when task was assigned"),
|
|
2132
2141
|
/**
|
|
2133
2142
|
* Optional deadline for task completion
|
|
2134
2143
|
*/
|
|
2135
|
-
deadline:
|
|
2144
|
+
deadline: z9.number().optional().describe("Optional task deadline timestamp")
|
|
2136
2145
|
});
|
|
2137
|
-
var TaskResultSchema =
|
|
2146
|
+
var TaskResultSchema = z9.object({
|
|
2138
2147
|
/**
|
|
2139
2148
|
* Assignment identifier
|
|
2140
2149
|
*/
|
|
2141
|
-
assignmentId:
|
|
2150
|
+
assignmentId: z9.string().describe("Assignment identifier"),
|
|
2142
2151
|
/**
|
|
2143
2152
|
* Worker that completed the task
|
|
2144
2153
|
*/
|
|
2145
|
-
workerId:
|
|
2154
|
+
workerId: z9.string().describe("Worker that completed the task"),
|
|
2146
2155
|
/**
|
|
2147
2156
|
* Whether the task succeeded
|
|
2148
2157
|
*/
|
|
2149
|
-
success:
|
|
2158
|
+
success: z9.boolean().describe("Whether the task succeeded"),
|
|
2150
2159
|
/**
|
|
2151
2160
|
* Task result/output
|
|
2152
2161
|
*/
|
|
2153
|
-
result:
|
|
2162
|
+
result: z9.string().describe("Task result or output"),
|
|
2154
2163
|
/**
|
|
2155
2164
|
* Optional error message if task failed
|
|
2156
2165
|
*/
|
|
2157
|
-
error:
|
|
2166
|
+
error: z9.string().optional().describe("Error message if task failed"),
|
|
2158
2167
|
/**
|
|
2159
2168
|
* Timestamp when task was completed
|
|
2160
2169
|
*/
|
|
2161
|
-
completedAt:
|
|
2170
|
+
completedAt: z9.number().describe("Timestamp when task was completed"),
|
|
2162
2171
|
/**
|
|
2163
2172
|
* Optional metadata about execution
|
|
2164
2173
|
*/
|
|
2165
|
-
metadata:
|
|
2174
|
+
metadata: JsonObjectSchema.optional().describe("Execution metadata")
|
|
2166
2175
|
});
|
|
2167
|
-
var MultiAgentStatusSchema =
|
|
2176
|
+
var MultiAgentStatusSchema = z9.enum([
|
|
2168
2177
|
"initializing",
|
|
2169
2178
|
// System is initializing
|
|
2170
2179
|
"routing",
|
|
@@ -2180,27 +2189,27 @@ var MultiAgentStatusSchema = z8.enum([
|
|
|
2180
2189
|
"failed"
|
|
2181
2190
|
// Task failed
|
|
2182
2191
|
]);
|
|
2183
|
-
var HandoffRequestSchema =
|
|
2192
|
+
var HandoffRequestSchema = z9.object({
|
|
2184
2193
|
/**
|
|
2185
2194
|
* Agent requesting the handoff
|
|
2186
2195
|
*/
|
|
2187
|
-
from:
|
|
2196
|
+
from: z9.string().describe("Agent requesting handoff"),
|
|
2188
2197
|
/**
|
|
2189
2198
|
* Target agent for handoff
|
|
2190
2199
|
*/
|
|
2191
|
-
to:
|
|
2200
|
+
to: z9.string().describe("Target agent for handoff"),
|
|
2192
2201
|
/**
|
|
2193
2202
|
* Reason for handoff
|
|
2194
2203
|
*/
|
|
2195
|
-
reason:
|
|
2204
|
+
reason: z9.string().describe("Reason for requesting handoff"),
|
|
2196
2205
|
/**
|
|
2197
2206
|
* Context to pass to next agent
|
|
2198
2207
|
*/
|
|
2199
|
-
context:
|
|
2208
|
+
context: z9.unknown().describe("Context to pass to next agent"),
|
|
2200
2209
|
/**
|
|
2201
2210
|
* Timestamp of handoff request
|
|
2202
2211
|
*/
|
|
2203
|
-
timestamp:
|
|
2212
|
+
timestamp: z9.string().datetime().describe("ISO timestamp of handoff request")
|
|
2204
2213
|
});
|
|
2205
2214
|
|
|
2206
2215
|
// src/multi-agent/state.ts
|
|
@@ -2214,7 +2223,7 @@ var MultiAgentStateConfig = {
|
|
|
2214
2223
|
* Accumulates all messages between agents
|
|
2215
2224
|
*/
|
|
2216
2225
|
messages: {
|
|
2217
|
-
schema:
|
|
2226
|
+
schema: z10.array(AgentMessageSchema),
|
|
2218
2227
|
reducer: (left, right) => [...left, ...right],
|
|
2219
2228
|
default: () => [],
|
|
2220
2229
|
description: "All messages in the multi-agent conversation"
|
|
@@ -2223,7 +2232,7 @@ var MultiAgentStateConfig = {
|
|
|
2223
2232
|
* Available worker agents and their capabilities
|
|
2224
2233
|
*/
|
|
2225
2234
|
workers: {
|
|
2226
|
-
schema:
|
|
2235
|
+
schema: z10.record(z10.string(), WorkerCapabilitiesSchema),
|
|
2227
2236
|
reducer: (left, right) => ({
|
|
2228
2237
|
...left,
|
|
2229
2238
|
...right
|
|
@@ -2235,7 +2244,7 @@ var MultiAgentStateConfig = {
|
|
|
2235
2244
|
* Current active agent
|
|
2236
2245
|
*/
|
|
2237
2246
|
currentAgent: {
|
|
2238
|
-
schema:
|
|
2247
|
+
schema: z10.string().optional(),
|
|
2239
2248
|
description: "Identifier of the currently active agent"
|
|
2240
2249
|
},
|
|
2241
2250
|
/**
|
|
@@ -2243,7 +2252,7 @@ var MultiAgentStateConfig = {
|
|
|
2243
2252
|
* Accumulates all routing decisions
|
|
2244
2253
|
*/
|
|
2245
2254
|
routingHistory: {
|
|
2246
|
-
schema:
|
|
2255
|
+
schema: z10.array(RoutingDecisionSchema),
|
|
2247
2256
|
reducer: (left, right) => [...left, ...right],
|
|
2248
2257
|
default: () => [],
|
|
2249
2258
|
description: "History of routing decisions"
|
|
@@ -2252,7 +2261,7 @@ var MultiAgentStateConfig = {
|
|
|
2252
2261
|
* Active task assignments
|
|
2253
2262
|
*/
|
|
2254
2263
|
activeAssignments: {
|
|
2255
|
-
schema:
|
|
2264
|
+
schema: z10.array(TaskAssignmentSchema),
|
|
2256
2265
|
reducer: (left, right) => [...left, ...right],
|
|
2257
2266
|
default: () => [],
|
|
2258
2267
|
description: "Currently active task assignments"
|
|
@@ -2262,7 +2271,7 @@ var MultiAgentStateConfig = {
|
|
|
2262
2271
|
* Accumulates all completed tasks
|
|
2263
2272
|
*/
|
|
2264
2273
|
completedTasks: {
|
|
2265
|
-
schema:
|
|
2274
|
+
schema: z10.array(TaskResultSchema),
|
|
2266
2275
|
reducer: (left, right) => [...left, ...right],
|
|
2267
2276
|
default: () => [],
|
|
2268
2277
|
description: "Completed task results"
|
|
@@ -2272,7 +2281,7 @@ var MultiAgentStateConfig = {
|
|
|
2272
2281
|
* Accumulates all handoff requests
|
|
2273
2282
|
*/
|
|
2274
2283
|
handoffs: {
|
|
2275
|
-
schema:
|
|
2284
|
+
schema: z10.array(HandoffRequestSchema),
|
|
2276
2285
|
reducer: (left, right) => [...left, ...right],
|
|
2277
2286
|
default: () => [],
|
|
2278
2287
|
description: "Handoff requests between agents"
|