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