@agentforge/patterns 0.15.15 → 0.16.1
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 +34 -11
- package/dist/index.d.cts +76 -69
- package/dist/index.d.ts +76 -69
- package/dist/index.js +34 -11
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -888,7 +888,7 @@ var PlanStepSchema = import_zod4.z.object({
|
|
|
888
888
|
/**
|
|
889
889
|
* Optional arguments for the tool
|
|
890
890
|
*/
|
|
891
|
-
args: import_zod4.z.record(import_zod4.z.
|
|
891
|
+
args: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()).optional().describe("Arguments to pass to the tool")
|
|
892
892
|
});
|
|
893
893
|
var CompletedStepSchema = import_zod4.z.object({
|
|
894
894
|
/**
|
|
@@ -898,7 +898,7 @@ var CompletedStepSchema = import_zod4.z.object({
|
|
|
898
898
|
/**
|
|
899
899
|
* The result of executing the step
|
|
900
900
|
*/
|
|
901
|
-
result: import_zod4.z.
|
|
901
|
+
result: import_zod4.z.unknown().describe("The result of executing the step"),
|
|
902
902
|
/**
|
|
903
903
|
* Whether the step succeeded
|
|
904
904
|
*/
|
|
@@ -1075,6 +1075,9 @@ var REMAINING_STEP_TEMPLATE = `Step {stepNumber}: {description}
|
|
|
1075
1075
|
var plannerLogger = createPatternLogger("agentforge:patterns:plan-execute:planner");
|
|
1076
1076
|
var executorLogger = createPatternLogger("agentforge:patterns:plan-execute:executor");
|
|
1077
1077
|
var replannerLogger = createPatternLogger("agentforge:patterns:plan-execute:replanner");
|
|
1078
|
+
function invokePlanExecuteTool(tool, args) {
|
|
1079
|
+
return tool.invoke.call(tool, args);
|
|
1080
|
+
}
|
|
1078
1081
|
function createPlannerNode(config) {
|
|
1079
1082
|
const {
|
|
1080
1083
|
model,
|
|
@@ -1142,10 +1145,18 @@ function createExecutorNode(config) {
|
|
|
1142
1145
|
const {
|
|
1143
1146
|
tools,
|
|
1144
1147
|
model,
|
|
1145
|
-
parallel
|
|
1148
|
+
parallel,
|
|
1146
1149
|
stepTimeout = 3e4,
|
|
1147
1150
|
enableDeduplication = true
|
|
1148
1151
|
} = config;
|
|
1152
|
+
if (typeof model !== "undefined") {
|
|
1153
|
+
executorLogger.warn("ExecutorConfig.model is currently unsupported and will be ignored");
|
|
1154
|
+
}
|
|
1155
|
+
if (typeof parallel !== "undefined") {
|
|
1156
|
+
executorLogger.warn("ExecutorConfig.parallel is currently unsupported and will be ignored", {
|
|
1157
|
+
parallel
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1149
1160
|
return async (state) => {
|
|
1150
1161
|
const { plan, currentStepIndex = 0, pastSteps = [], iteration = 0 } = state;
|
|
1151
1162
|
try {
|
|
@@ -1222,13 +1233,20 @@ function createExecutorNode(config) {
|
|
|
1222
1233
|
throw new Error(`Tool not found: ${currentStep.tool}`);
|
|
1223
1234
|
}
|
|
1224
1235
|
const startTime = Date.now();
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1236
|
+
let timeoutId;
|
|
1237
|
+
try {
|
|
1238
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
1239
|
+
timeoutId = setTimeout(() => reject(new Error("Step execution timeout")), stepTimeout);
|
|
1240
|
+
});
|
|
1241
|
+
result = await Promise.race([
|
|
1242
|
+
invokePlanExecuteTool(tool, currentStep.args || {}),
|
|
1243
|
+
timeoutPromise
|
|
1244
|
+
]);
|
|
1245
|
+
} finally {
|
|
1246
|
+
if (timeoutId !== void 0) {
|
|
1247
|
+
clearTimeout(timeoutId);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1232
1250
|
const executionTime = Date.now() - startTime;
|
|
1233
1251
|
executorLogger.debug("Step executed successfully", {
|
|
1234
1252
|
stepId: currentStep.id,
|
|
@@ -1285,9 +1303,14 @@ function createExecutorNode(config) {
|
|
|
1285
1303
|
function createReplannerNode(config) {
|
|
1286
1304
|
const {
|
|
1287
1305
|
model,
|
|
1288
|
-
replanThreshold
|
|
1306
|
+
replanThreshold,
|
|
1289
1307
|
systemPrompt = DEFAULT_REPLANNER_SYSTEM_PROMPT
|
|
1290
1308
|
} = config;
|
|
1309
|
+
if (typeof replanThreshold !== "undefined") {
|
|
1310
|
+
replannerLogger.warn("ReplannerConfig.replanThreshold is currently unsupported and will be ignored", {
|
|
1311
|
+
replanThreshold
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1291
1314
|
return async (state) => {
|
|
1292
1315
|
const startTime = Date.now();
|
|
1293
1316
|
try {
|
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import * as _langchain_langgraph from '@langchain/langgraph';
|
|
|
3
3
|
import { BaseCheckpointSaver, CompiledStateGraph } from '@langchain/langgraph';
|
|
4
4
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
5
5
|
import * as _agentforge_core from '@agentforge/core';
|
|
6
|
-
import { ToolRegistry, Tool, LogLevel } from '@agentforge/core';
|
|
6
|
+
import { ToolRegistry, Tool, ToolMetadata, LogLevel } from '@agentforge/core';
|
|
7
7
|
import { RunnableConfig } from '@langchain/core/runnables';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -549,6 +549,8 @@ declare function createReActAgentBuilder(): ReActAgentBuilder;
|
|
|
549
549
|
* @module patterns/plan-execute/schemas
|
|
550
550
|
*/
|
|
551
551
|
|
|
552
|
+
type PlanStepArguments = Record<string, unknown>;
|
|
553
|
+
type PlanStepResult = unknown;
|
|
552
554
|
/**
|
|
553
555
|
* Schema for a single step in the plan
|
|
554
556
|
*/
|
|
@@ -572,18 +574,18 @@ declare const PlanStepSchema: z.ZodObject<{
|
|
|
572
574
|
/**
|
|
573
575
|
* Optional arguments for the tool
|
|
574
576
|
*/
|
|
575
|
-
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
577
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
576
578
|
}, "strip", z.ZodTypeAny, {
|
|
577
579
|
id: string;
|
|
578
580
|
description: string;
|
|
579
581
|
tool?: string | undefined;
|
|
580
|
-
args?: Record<string,
|
|
582
|
+
args?: Record<string, unknown> | undefined;
|
|
581
583
|
dependencies?: string[] | undefined;
|
|
582
584
|
}, {
|
|
583
585
|
id: string;
|
|
584
586
|
description: string;
|
|
585
587
|
tool?: string | undefined;
|
|
586
|
-
args?: Record<string,
|
|
588
|
+
args?: Record<string, unknown> | undefined;
|
|
587
589
|
dependencies?: string[] | undefined;
|
|
588
590
|
}>;
|
|
589
591
|
type PlanStep = z.infer<typeof PlanStepSchema>;
|
|
@@ -614,24 +616,24 @@ declare const CompletedStepSchema: z.ZodObject<{
|
|
|
614
616
|
/**
|
|
615
617
|
* Optional arguments for the tool
|
|
616
618
|
*/
|
|
617
|
-
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
619
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
618
620
|
}, "strip", z.ZodTypeAny, {
|
|
619
621
|
id: string;
|
|
620
622
|
description: string;
|
|
621
623
|
tool?: string | undefined;
|
|
622
|
-
args?: Record<string,
|
|
624
|
+
args?: Record<string, unknown> | undefined;
|
|
623
625
|
dependencies?: string[] | undefined;
|
|
624
626
|
}, {
|
|
625
627
|
id: string;
|
|
626
628
|
description: string;
|
|
627
629
|
tool?: string | undefined;
|
|
628
|
-
args?: Record<string,
|
|
630
|
+
args?: Record<string, unknown> | undefined;
|
|
629
631
|
dependencies?: string[] | undefined;
|
|
630
632
|
}>;
|
|
631
633
|
/**
|
|
632
634
|
* The result of executing the step
|
|
633
635
|
*/
|
|
634
|
-
result: z.
|
|
636
|
+
result: z.ZodUnknown;
|
|
635
637
|
/**
|
|
636
638
|
* Whether the step succeeded
|
|
637
639
|
*/
|
|
@@ -650,11 +652,11 @@ declare const CompletedStepSchema: z.ZodObject<{
|
|
|
650
652
|
id: string;
|
|
651
653
|
description: string;
|
|
652
654
|
tool?: string | undefined;
|
|
653
|
-
args?: Record<string,
|
|
655
|
+
args?: Record<string, unknown> | undefined;
|
|
654
656
|
dependencies?: string[] | undefined;
|
|
655
657
|
};
|
|
656
658
|
success: boolean;
|
|
657
|
-
result?:
|
|
659
|
+
result?: unknown;
|
|
658
660
|
error?: string | undefined;
|
|
659
661
|
}, {
|
|
660
662
|
timestamp: string;
|
|
@@ -662,11 +664,11 @@ declare const CompletedStepSchema: z.ZodObject<{
|
|
|
662
664
|
id: string;
|
|
663
665
|
description: string;
|
|
664
666
|
tool?: string | undefined;
|
|
665
|
-
args?: Record<string,
|
|
667
|
+
args?: Record<string, unknown> | undefined;
|
|
666
668
|
dependencies?: string[] | undefined;
|
|
667
669
|
};
|
|
668
670
|
success: boolean;
|
|
669
|
-
result?:
|
|
671
|
+
result?: unknown;
|
|
670
672
|
error?: string | undefined;
|
|
671
673
|
}>;
|
|
672
674
|
type CompletedStep = z.infer<typeof CompletedStepSchema>;
|
|
@@ -697,18 +699,18 @@ declare const PlanSchema: z.ZodObject<{
|
|
|
697
699
|
/**
|
|
698
700
|
* Optional arguments for the tool
|
|
699
701
|
*/
|
|
700
|
-
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
702
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
701
703
|
}, "strip", z.ZodTypeAny, {
|
|
702
704
|
id: string;
|
|
703
705
|
description: string;
|
|
704
706
|
tool?: string | undefined;
|
|
705
|
-
args?: Record<string,
|
|
707
|
+
args?: Record<string, unknown> | undefined;
|
|
706
708
|
dependencies?: string[] | undefined;
|
|
707
709
|
}, {
|
|
708
710
|
id: string;
|
|
709
711
|
description: string;
|
|
710
712
|
tool?: string | undefined;
|
|
711
|
-
args?: Record<string,
|
|
713
|
+
args?: Record<string, unknown> | undefined;
|
|
712
714
|
dependencies?: string[] | undefined;
|
|
713
715
|
}>, "many">;
|
|
714
716
|
/**
|
|
@@ -728,7 +730,7 @@ declare const PlanSchema: z.ZodObject<{
|
|
|
728
730
|
id: string;
|
|
729
731
|
description: string;
|
|
730
732
|
tool?: string | undefined;
|
|
731
|
-
args?: Record<string,
|
|
733
|
+
args?: Record<string, unknown> | undefined;
|
|
732
734
|
dependencies?: string[] | undefined;
|
|
733
735
|
}[];
|
|
734
736
|
goal: string;
|
|
@@ -739,7 +741,7 @@ declare const PlanSchema: z.ZodObject<{
|
|
|
739
741
|
id: string;
|
|
740
742
|
description: string;
|
|
741
743
|
tool?: string | undefined;
|
|
742
|
-
args?: Record<string,
|
|
744
|
+
args?: Record<string, unknown> | undefined;
|
|
743
745
|
dependencies?: string[] | undefined;
|
|
744
746
|
}[];
|
|
745
747
|
goal: string;
|
|
@@ -804,18 +806,18 @@ declare const PlanExecuteStateConfig: {
|
|
|
804
806
|
description: z.ZodString;
|
|
805
807
|
dependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
806
808
|
tool: z.ZodOptional<z.ZodString>;
|
|
807
|
-
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
809
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
808
810
|
}, "strip", z.ZodTypeAny, {
|
|
809
811
|
id: string;
|
|
810
812
|
description: string;
|
|
811
813
|
tool?: string | undefined;
|
|
812
|
-
args?: Record<string,
|
|
814
|
+
args?: Record<string, unknown> | undefined;
|
|
813
815
|
dependencies?: string[] | undefined;
|
|
814
816
|
}, {
|
|
815
817
|
id: string;
|
|
816
818
|
description: string;
|
|
817
819
|
tool?: string | undefined;
|
|
818
|
-
args?: Record<string,
|
|
820
|
+
args?: Record<string, unknown> | undefined;
|
|
819
821
|
dependencies?: string[] | undefined;
|
|
820
822
|
}>, "many">;
|
|
821
823
|
goal: z.ZodString;
|
|
@@ -826,7 +828,7 @@ declare const PlanExecuteStateConfig: {
|
|
|
826
828
|
id: string;
|
|
827
829
|
description: string;
|
|
828
830
|
tool?: string | undefined;
|
|
829
|
-
args?: Record<string,
|
|
831
|
+
args?: Record<string, unknown> | undefined;
|
|
830
832
|
dependencies?: string[] | undefined;
|
|
831
833
|
}[];
|
|
832
834
|
goal: string;
|
|
@@ -837,7 +839,7 @@ declare const PlanExecuteStateConfig: {
|
|
|
837
839
|
id: string;
|
|
838
840
|
description: string;
|
|
839
841
|
tool?: string | undefined;
|
|
840
|
-
args?: Record<string,
|
|
842
|
+
args?: Record<string, unknown> | undefined;
|
|
841
843
|
dependencies?: string[] | undefined;
|
|
842
844
|
}[];
|
|
843
845
|
goal: string;
|
|
@@ -857,21 +859,21 @@ declare const PlanExecuteStateConfig: {
|
|
|
857
859
|
description: z.ZodString;
|
|
858
860
|
dependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
859
861
|
tool: z.ZodOptional<z.ZodString>;
|
|
860
|
-
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
862
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
861
863
|
}, "strip", z.ZodTypeAny, {
|
|
862
864
|
id: string;
|
|
863
865
|
description: string;
|
|
864
866
|
tool?: string | undefined;
|
|
865
|
-
args?: Record<string,
|
|
867
|
+
args?: Record<string, unknown> | undefined;
|
|
866
868
|
dependencies?: string[] | undefined;
|
|
867
869
|
}, {
|
|
868
870
|
id: string;
|
|
869
871
|
description: string;
|
|
870
872
|
tool?: string | undefined;
|
|
871
|
-
args?: Record<string,
|
|
873
|
+
args?: Record<string, unknown> | undefined;
|
|
872
874
|
dependencies?: string[] | undefined;
|
|
873
875
|
}>;
|
|
874
|
-
result: z.
|
|
876
|
+
result: z.ZodUnknown;
|
|
875
877
|
success: z.ZodBoolean;
|
|
876
878
|
error: z.ZodOptional<z.ZodString>;
|
|
877
879
|
timestamp: z.ZodString;
|
|
@@ -881,11 +883,11 @@ declare const PlanExecuteStateConfig: {
|
|
|
881
883
|
id: string;
|
|
882
884
|
description: string;
|
|
883
885
|
tool?: string | undefined;
|
|
884
|
-
args?: Record<string,
|
|
886
|
+
args?: Record<string, unknown> | undefined;
|
|
885
887
|
dependencies?: string[] | undefined;
|
|
886
888
|
};
|
|
887
889
|
success: boolean;
|
|
888
|
-
result?:
|
|
890
|
+
result?: unknown;
|
|
889
891
|
error?: string | undefined;
|
|
890
892
|
}, {
|
|
891
893
|
timestamp: string;
|
|
@@ -893,11 +895,11 @@ declare const PlanExecuteStateConfig: {
|
|
|
893
895
|
id: string;
|
|
894
896
|
description: string;
|
|
895
897
|
tool?: string | undefined;
|
|
896
|
-
args?: Record<string,
|
|
898
|
+
args?: Record<string, unknown> | undefined;
|
|
897
899
|
dependencies?: string[] | undefined;
|
|
898
900
|
};
|
|
899
901
|
success: boolean;
|
|
900
|
-
result?:
|
|
902
|
+
result?: unknown;
|
|
901
903
|
error?: string | undefined;
|
|
902
904
|
}>, "many">;
|
|
903
905
|
reducer: (left: CompletedStep[], right: CompletedStep[]) => {
|
|
@@ -906,11 +908,11 @@ declare const PlanExecuteStateConfig: {
|
|
|
906
908
|
id: string;
|
|
907
909
|
description: string;
|
|
908
910
|
tool?: string | undefined;
|
|
909
|
-
args?: Record<string,
|
|
911
|
+
args?: Record<string, unknown> | undefined;
|
|
910
912
|
dependencies?: string[] | undefined;
|
|
911
913
|
};
|
|
912
914
|
success: boolean;
|
|
913
|
-
result?:
|
|
915
|
+
result?: unknown;
|
|
914
916
|
error?: string | undefined;
|
|
915
917
|
}[];
|
|
916
918
|
default: () => never[];
|
|
@@ -975,7 +977,7 @@ declare const PlanExecuteState: _langchain_langgraph.AnnotationRoot<{
|
|
|
975
977
|
id: string;
|
|
976
978
|
description: string;
|
|
977
979
|
tool?: string | undefined;
|
|
978
|
-
args?: Record<string,
|
|
980
|
+
args?: Record<string, unknown> | undefined;
|
|
979
981
|
dependencies?: string[] | undefined;
|
|
980
982
|
}[];
|
|
981
983
|
goal: string;
|
|
@@ -986,7 +988,7 @@ declare const PlanExecuteState: _langchain_langgraph.AnnotationRoot<{
|
|
|
986
988
|
id: string;
|
|
987
989
|
description: string;
|
|
988
990
|
tool?: string | undefined;
|
|
989
|
-
args?: Record<string,
|
|
991
|
+
args?: Record<string, unknown> | undefined;
|
|
990
992
|
dependencies?: string[] | undefined;
|
|
991
993
|
}[];
|
|
992
994
|
goal: string;
|
|
@@ -999,11 +1001,11 @@ declare const PlanExecuteState: _langchain_langgraph.AnnotationRoot<{
|
|
|
999
1001
|
id: string;
|
|
1000
1002
|
description: string;
|
|
1001
1003
|
tool?: string | undefined;
|
|
1002
|
-
args?: Record<string,
|
|
1004
|
+
args?: Record<string, unknown> | undefined;
|
|
1003
1005
|
dependencies?: string[] | undefined;
|
|
1004
1006
|
};
|
|
1005
1007
|
success: boolean;
|
|
1006
|
-
result?:
|
|
1008
|
+
result?: unknown;
|
|
1007
1009
|
error?: string | undefined;
|
|
1008
1010
|
}[], {
|
|
1009
1011
|
timestamp: string;
|
|
@@ -1011,11 +1013,11 @@ declare const PlanExecuteState: _langchain_langgraph.AnnotationRoot<{
|
|
|
1011
1013
|
id: string;
|
|
1012
1014
|
description: string;
|
|
1013
1015
|
tool?: string | undefined;
|
|
1014
|
-
args?: Record<string,
|
|
1016
|
+
args?: Record<string, unknown> | undefined;
|
|
1015
1017
|
dependencies?: string[] | undefined;
|
|
1016
1018
|
};
|
|
1017
1019
|
success: boolean;
|
|
1018
|
-
result?:
|
|
1020
|
+
result?: unknown;
|
|
1019
1021
|
error?: string | undefined;
|
|
1020
1022
|
}[], unknown>;
|
|
1021
1023
|
currentStepIndex: _langchain_langgraph.BaseChannel<number | undefined, number | undefined, unknown>;
|
|
@@ -1050,6 +1052,10 @@ type PlanExecuteStateType = {
|
|
|
1050
1052
|
* @module patterns/plan-execute/types
|
|
1051
1053
|
*/
|
|
1052
1054
|
|
|
1055
|
+
interface PlanExecuteTool {
|
|
1056
|
+
metadata: ToolMetadata;
|
|
1057
|
+
invoke(input: PlanStepArguments): Promise<PlanStepResult>;
|
|
1058
|
+
}
|
|
1053
1059
|
/**
|
|
1054
1060
|
* Configuration for the planner node
|
|
1055
1061
|
*/
|
|
@@ -1074,17 +1080,19 @@ interface PlannerConfig {
|
|
|
1074
1080
|
/**
|
|
1075
1081
|
* Configuration for the executor node
|
|
1076
1082
|
*/
|
|
1077
|
-
interface ExecutorConfig {
|
|
1083
|
+
interface ExecutorConfig<TTool extends PlanExecuteTool = PlanExecuteTool> {
|
|
1078
1084
|
/**
|
|
1079
1085
|
* Available tools for execution
|
|
1080
1086
|
*/
|
|
1081
|
-
tools:
|
|
1087
|
+
tools: readonly TTool[];
|
|
1082
1088
|
/**
|
|
1083
|
-
* Optional language model for sub-tasks
|
|
1089
|
+
* Optional language model for sub-tasks.
|
|
1090
|
+
* Currently unsupported and ignored by the runtime executor node.
|
|
1084
1091
|
*/
|
|
1085
1092
|
model?: BaseChatModel;
|
|
1086
1093
|
/**
|
|
1087
|
-
* Enable parallel execution of independent steps
|
|
1094
|
+
* Enable parallel execution of independent steps.
|
|
1095
|
+
* Currently unsupported and ignored by the runtime executor node.
|
|
1088
1096
|
*/
|
|
1089
1097
|
parallel?: boolean;
|
|
1090
1098
|
/**
|
|
@@ -1106,8 +1114,9 @@ interface ReplannerConfig {
|
|
|
1106
1114
|
*/
|
|
1107
1115
|
model: BaseChatModel;
|
|
1108
1116
|
/**
|
|
1109
|
-
*
|
|
1110
|
-
*
|
|
1117
|
+
* Intended confidence threshold for replanning (0-1).
|
|
1118
|
+
* This is a forward-compatibility option and is currently ignored by the runtime replanner node.
|
|
1119
|
+
* Future versions may use this to decide when to trigger replanning.
|
|
1111
1120
|
*/
|
|
1112
1121
|
replanThreshold?: number;
|
|
1113
1122
|
/**
|
|
@@ -1118,7 +1127,7 @@ interface ReplannerConfig {
|
|
|
1118
1127
|
/**
|
|
1119
1128
|
* Configuration for creating a Plan-Execute agent
|
|
1120
1129
|
*/
|
|
1121
|
-
interface PlanExecuteAgentConfig {
|
|
1130
|
+
interface PlanExecuteAgentConfig<TTool extends PlanExecuteTool = PlanExecuteTool> {
|
|
1122
1131
|
/**
|
|
1123
1132
|
* Planner configuration
|
|
1124
1133
|
*/
|
|
@@ -1126,7 +1135,7 @@ interface PlanExecuteAgentConfig {
|
|
|
1126
1135
|
/**
|
|
1127
1136
|
* Executor configuration
|
|
1128
1137
|
*/
|
|
1129
|
-
executor: ExecutorConfig
|
|
1138
|
+
executor: ExecutorConfig<TTool>;
|
|
1130
1139
|
/**
|
|
1131
1140
|
* Optional replanner configuration
|
|
1132
1141
|
* If not provided, no replanning will occur
|
|
@@ -1196,12 +1205,10 @@ type PlanExecuteRouter = (state: PlanExecuteStateType) => PlanExecuteRoute;
|
|
|
1196
1205
|
* maxSteps: 5
|
|
1197
1206
|
* },
|
|
1198
1207
|
* executor: {
|
|
1199
|
-
* tools: [searchTool, calculatorTool]
|
|
1200
|
-
* parallel: false
|
|
1208
|
+
* tools: [searchTool, calculatorTool]
|
|
1201
1209
|
* },
|
|
1202
1210
|
* replanner: {
|
|
1203
|
-
* model: new ChatOpenAI({ model: 'gpt-4' })
|
|
1204
|
-
* replanThreshold: 0.7
|
|
1211
|
+
* model: new ChatOpenAI({ model: 'gpt-4' })
|
|
1205
1212
|
* }
|
|
1206
1213
|
* });
|
|
1207
1214
|
*
|
|
@@ -1234,14 +1241,14 @@ type PlanExecuteRouter = (state: PlanExecuteStateType) => PlanExecuteRoute;
|
|
|
1234
1241
|
* );
|
|
1235
1242
|
* ```
|
|
1236
1243
|
*/
|
|
1237
|
-
declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langchain_langgraph.CompiledStateGraph<{
|
|
1244
|
+
declare function createPlanExecuteAgent<TTool extends PlanExecuteTool = PlanExecuteTool>(config: PlanExecuteAgentConfig<TTool>): _langchain_langgraph.CompiledStateGraph<{
|
|
1238
1245
|
input: string;
|
|
1239
1246
|
plan: {
|
|
1240
1247
|
steps: {
|
|
1241
1248
|
id: string;
|
|
1242
1249
|
description: string;
|
|
1243
1250
|
tool?: string | undefined;
|
|
1244
|
-
args?: Record<string,
|
|
1251
|
+
args?: Record<string, unknown> | undefined;
|
|
1245
1252
|
dependencies?: string[] | undefined;
|
|
1246
1253
|
}[];
|
|
1247
1254
|
goal: string;
|
|
@@ -1254,11 +1261,11 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1254
1261
|
id: string;
|
|
1255
1262
|
description: string;
|
|
1256
1263
|
tool?: string | undefined;
|
|
1257
|
-
args?: Record<string,
|
|
1264
|
+
args?: Record<string, unknown> | undefined;
|
|
1258
1265
|
dependencies?: string[] | undefined;
|
|
1259
1266
|
};
|
|
1260
1267
|
success: boolean;
|
|
1261
|
-
result?:
|
|
1268
|
+
result?: unknown;
|
|
1262
1269
|
error?: string | undefined;
|
|
1263
1270
|
}[];
|
|
1264
1271
|
currentStepIndex: number | undefined;
|
|
@@ -1274,7 +1281,7 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1274
1281
|
id: string;
|
|
1275
1282
|
description: string;
|
|
1276
1283
|
tool?: string | undefined;
|
|
1277
|
-
args?: Record<string,
|
|
1284
|
+
args?: Record<string, unknown> | undefined;
|
|
1278
1285
|
dependencies?: string[] | undefined;
|
|
1279
1286
|
}[];
|
|
1280
1287
|
goal: string;
|
|
@@ -1287,11 +1294,11 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1287
1294
|
id: string;
|
|
1288
1295
|
description: string;
|
|
1289
1296
|
tool?: string | undefined;
|
|
1290
|
-
args?: Record<string,
|
|
1297
|
+
args?: Record<string, unknown> | undefined;
|
|
1291
1298
|
dependencies?: string[] | undefined;
|
|
1292
1299
|
};
|
|
1293
1300
|
success: boolean;
|
|
1294
|
-
result?:
|
|
1301
|
+
result?: unknown;
|
|
1295
1302
|
error?: string | undefined;
|
|
1296
1303
|
}[] | undefined;
|
|
1297
1304
|
currentStepIndex?: number | undefined;
|
|
@@ -1307,7 +1314,7 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1307
1314
|
id: string;
|
|
1308
1315
|
description: string;
|
|
1309
1316
|
tool?: string | undefined;
|
|
1310
|
-
args?: Record<string,
|
|
1317
|
+
args?: Record<string, unknown> | undefined;
|
|
1311
1318
|
dependencies?: string[] | undefined;
|
|
1312
1319
|
}[];
|
|
1313
1320
|
goal: string;
|
|
@@ -1318,7 +1325,7 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1318
1325
|
id: string;
|
|
1319
1326
|
description: string;
|
|
1320
1327
|
tool?: string | undefined;
|
|
1321
|
-
args?: Record<string,
|
|
1328
|
+
args?: Record<string, unknown> | undefined;
|
|
1322
1329
|
dependencies?: string[] | undefined;
|
|
1323
1330
|
}[];
|
|
1324
1331
|
goal: string;
|
|
@@ -1331,11 +1338,11 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1331
1338
|
id: string;
|
|
1332
1339
|
description: string;
|
|
1333
1340
|
tool?: string | undefined;
|
|
1334
|
-
args?: Record<string,
|
|
1341
|
+
args?: Record<string, unknown> | undefined;
|
|
1335
1342
|
dependencies?: string[] | undefined;
|
|
1336
1343
|
};
|
|
1337
1344
|
success: boolean;
|
|
1338
|
-
result?:
|
|
1345
|
+
result?: unknown;
|
|
1339
1346
|
error?: string | undefined;
|
|
1340
1347
|
}[], {
|
|
1341
1348
|
timestamp: string;
|
|
@@ -1343,11 +1350,11 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1343
1350
|
id: string;
|
|
1344
1351
|
description: string;
|
|
1345
1352
|
tool?: string | undefined;
|
|
1346
|
-
args?: Record<string,
|
|
1353
|
+
args?: Record<string, unknown> | undefined;
|
|
1347
1354
|
dependencies?: string[] | undefined;
|
|
1348
1355
|
};
|
|
1349
1356
|
success: boolean;
|
|
1350
|
-
result?:
|
|
1357
|
+
result?: unknown;
|
|
1351
1358
|
error?: string | undefined;
|
|
1352
1359
|
}[], unknown>;
|
|
1353
1360
|
currentStepIndex: _langchain_langgraph.BaseChannel<number | undefined, number | undefined, unknown>;
|
|
@@ -1363,7 +1370,7 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1363
1370
|
id: string;
|
|
1364
1371
|
description: string;
|
|
1365
1372
|
tool?: string | undefined;
|
|
1366
|
-
args?: Record<string,
|
|
1373
|
+
args?: Record<string, unknown> | undefined;
|
|
1367
1374
|
dependencies?: string[] | undefined;
|
|
1368
1375
|
}[];
|
|
1369
1376
|
goal: string;
|
|
@@ -1374,7 +1381,7 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1374
1381
|
id: string;
|
|
1375
1382
|
description: string;
|
|
1376
1383
|
tool?: string | undefined;
|
|
1377
|
-
args?: Record<string,
|
|
1384
|
+
args?: Record<string, unknown> | undefined;
|
|
1378
1385
|
dependencies?: string[] | undefined;
|
|
1379
1386
|
}[];
|
|
1380
1387
|
goal: string;
|
|
@@ -1387,11 +1394,11 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1387
1394
|
id: string;
|
|
1388
1395
|
description: string;
|
|
1389
1396
|
tool?: string | undefined;
|
|
1390
|
-
args?: Record<string,
|
|
1397
|
+
args?: Record<string, unknown> | undefined;
|
|
1391
1398
|
dependencies?: string[] | undefined;
|
|
1392
1399
|
};
|
|
1393
1400
|
success: boolean;
|
|
1394
|
-
result?:
|
|
1401
|
+
result?: unknown;
|
|
1395
1402
|
error?: string | undefined;
|
|
1396
1403
|
}[], {
|
|
1397
1404
|
timestamp: string;
|
|
@@ -1399,11 +1406,11 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1399
1406
|
id: string;
|
|
1400
1407
|
description: string;
|
|
1401
1408
|
tool?: string | undefined;
|
|
1402
|
-
args?: Record<string,
|
|
1409
|
+
args?: Record<string, unknown> | undefined;
|
|
1403
1410
|
dependencies?: string[] | undefined;
|
|
1404
1411
|
};
|
|
1405
1412
|
success: boolean;
|
|
1406
|
-
result?:
|
|
1413
|
+
result?: unknown;
|
|
1407
1414
|
error?: string | undefined;
|
|
1408
1415
|
}[], unknown>;
|
|
1409
1416
|
currentStepIndex: _langchain_langgraph.BaseChannel<number | undefined, number | undefined, unknown>;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as _langchain_langgraph from '@langchain/langgraph';
|
|
|
3
3
|
import { BaseCheckpointSaver, CompiledStateGraph } from '@langchain/langgraph';
|
|
4
4
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
5
5
|
import * as _agentforge_core from '@agentforge/core';
|
|
6
|
-
import { ToolRegistry, Tool, LogLevel } from '@agentforge/core';
|
|
6
|
+
import { ToolRegistry, Tool, ToolMetadata, LogLevel } from '@agentforge/core';
|
|
7
7
|
import { RunnableConfig } from '@langchain/core/runnables';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -549,6 +549,8 @@ declare function createReActAgentBuilder(): ReActAgentBuilder;
|
|
|
549
549
|
* @module patterns/plan-execute/schemas
|
|
550
550
|
*/
|
|
551
551
|
|
|
552
|
+
type PlanStepArguments = Record<string, unknown>;
|
|
553
|
+
type PlanStepResult = unknown;
|
|
552
554
|
/**
|
|
553
555
|
* Schema for a single step in the plan
|
|
554
556
|
*/
|
|
@@ -572,18 +574,18 @@ declare const PlanStepSchema: z.ZodObject<{
|
|
|
572
574
|
/**
|
|
573
575
|
* Optional arguments for the tool
|
|
574
576
|
*/
|
|
575
|
-
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
577
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
576
578
|
}, "strip", z.ZodTypeAny, {
|
|
577
579
|
id: string;
|
|
578
580
|
description: string;
|
|
579
581
|
tool?: string | undefined;
|
|
580
|
-
args?: Record<string,
|
|
582
|
+
args?: Record<string, unknown> | undefined;
|
|
581
583
|
dependencies?: string[] | undefined;
|
|
582
584
|
}, {
|
|
583
585
|
id: string;
|
|
584
586
|
description: string;
|
|
585
587
|
tool?: string | undefined;
|
|
586
|
-
args?: Record<string,
|
|
588
|
+
args?: Record<string, unknown> | undefined;
|
|
587
589
|
dependencies?: string[] | undefined;
|
|
588
590
|
}>;
|
|
589
591
|
type PlanStep = z.infer<typeof PlanStepSchema>;
|
|
@@ -614,24 +616,24 @@ declare const CompletedStepSchema: z.ZodObject<{
|
|
|
614
616
|
/**
|
|
615
617
|
* Optional arguments for the tool
|
|
616
618
|
*/
|
|
617
|
-
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
619
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
618
620
|
}, "strip", z.ZodTypeAny, {
|
|
619
621
|
id: string;
|
|
620
622
|
description: string;
|
|
621
623
|
tool?: string | undefined;
|
|
622
|
-
args?: Record<string,
|
|
624
|
+
args?: Record<string, unknown> | undefined;
|
|
623
625
|
dependencies?: string[] | undefined;
|
|
624
626
|
}, {
|
|
625
627
|
id: string;
|
|
626
628
|
description: string;
|
|
627
629
|
tool?: string | undefined;
|
|
628
|
-
args?: Record<string,
|
|
630
|
+
args?: Record<string, unknown> | undefined;
|
|
629
631
|
dependencies?: string[] | undefined;
|
|
630
632
|
}>;
|
|
631
633
|
/**
|
|
632
634
|
* The result of executing the step
|
|
633
635
|
*/
|
|
634
|
-
result: z.
|
|
636
|
+
result: z.ZodUnknown;
|
|
635
637
|
/**
|
|
636
638
|
* Whether the step succeeded
|
|
637
639
|
*/
|
|
@@ -650,11 +652,11 @@ declare const CompletedStepSchema: z.ZodObject<{
|
|
|
650
652
|
id: string;
|
|
651
653
|
description: string;
|
|
652
654
|
tool?: string | undefined;
|
|
653
|
-
args?: Record<string,
|
|
655
|
+
args?: Record<string, unknown> | undefined;
|
|
654
656
|
dependencies?: string[] | undefined;
|
|
655
657
|
};
|
|
656
658
|
success: boolean;
|
|
657
|
-
result?:
|
|
659
|
+
result?: unknown;
|
|
658
660
|
error?: string | undefined;
|
|
659
661
|
}, {
|
|
660
662
|
timestamp: string;
|
|
@@ -662,11 +664,11 @@ declare const CompletedStepSchema: z.ZodObject<{
|
|
|
662
664
|
id: string;
|
|
663
665
|
description: string;
|
|
664
666
|
tool?: string | undefined;
|
|
665
|
-
args?: Record<string,
|
|
667
|
+
args?: Record<string, unknown> | undefined;
|
|
666
668
|
dependencies?: string[] | undefined;
|
|
667
669
|
};
|
|
668
670
|
success: boolean;
|
|
669
|
-
result?:
|
|
671
|
+
result?: unknown;
|
|
670
672
|
error?: string | undefined;
|
|
671
673
|
}>;
|
|
672
674
|
type CompletedStep = z.infer<typeof CompletedStepSchema>;
|
|
@@ -697,18 +699,18 @@ declare const PlanSchema: z.ZodObject<{
|
|
|
697
699
|
/**
|
|
698
700
|
* Optional arguments for the tool
|
|
699
701
|
*/
|
|
700
|
-
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
702
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
701
703
|
}, "strip", z.ZodTypeAny, {
|
|
702
704
|
id: string;
|
|
703
705
|
description: string;
|
|
704
706
|
tool?: string | undefined;
|
|
705
|
-
args?: Record<string,
|
|
707
|
+
args?: Record<string, unknown> | undefined;
|
|
706
708
|
dependencies?: string[] | undefined;
|
|
707
709
|
}, {
|
|
708
710
|
id: string;
|
|
709
711
|
description: string;
|
|
710
712
|
tool?: string | undefined;
|
|
711
|
-
args?: Record<string,
|
|
713
|
+
args?: Record<string, unknown> | undefined;
|
|
712
714
|
dependencies?: string[] | undefined;
|
|
713
715
|
}>, "many">;
|
|
714
716
|
/**
|
|
@@ -728,7 +730,7 @@ declare const PlanSchema: z.ZodObject<{
|
|
|
728
730
|
id: string;
|
|
729
731
|
description: string;
|
|
730
732
|
tool?: string | undefined;
|
|
731
|
-
args?: Record<string,
|
|
733
|
+
args?: Record<string, unknown> | undefined;
|
|
732
734
|
dependencies?: string[] | undefined;
|
|
733
735
|
}[];
|
|
734
736
|
goal: string;
|
|
@@ -739,7 +741,7 @@ declare const PlanSchema: z.ZodObject<{
|
|
|
739
741
|
id: string;
|
|
740
742
|
description: string;
|
|
741
743
|
tool?: string | undefined;
|
|
742
|
-
args?: Record<string,
|
|
744
|
+
args?: Record<string, unknown> | undefined;
|
|
743
745
|
dependencies?: string[] | undefined;
|
|
744
746
|
}[];
|
|
745
747
|
goal: string;
|
|
@@ -804,18 +806,18 @@ declare const PlanExecuteStateConfig: {
|
|
|
804
806
|
description: z.ZodString;
|
|
805
807
|
dependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
806
808
|
tool: z.ZodOptional<z.ZodString>;
|
|
807
|
-
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
809
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
808
810
|
}, "strip", z.ZodTypeAny, {
|
|
809
811
|
id: string;
|
|
810
812
|
description: string;
|
|
811
813
|
tool?: string | undefined;
|
|
812
|
-
args?: Record<string,
|
|
814
|
+
args?: Record<string, unknown> | undefined;
|
|
813
815
|
dependencies?: string[] | undefined;
|
|
814
816
|
}, {
|
|
815
817
|
id: string;
|
|
816
818
|
description: string;
|
|
817
819
|
tool?: string | undefined;
|
|
818
|
-
args?: Record<string,
|
|
820
|
+
args?: Record<string, unknown> | undefined;
|
|
819
821
|
dependencies?: string[] | undefined;
|
|
820
822
|
}>, "many">;
|
|
821
823
|
goal: z.ZodString;
|
|
@@ -826,7 +828,7 @@ declare const PlanExecuteStateConfig: {
|
|
|
826
828
|
id: string;
|
|
827
829
|
description: string;
|
|
828
830
|
tool?: string | undefined;
|
|
829
|
-
args?: Record<string,
|
|
831
|
+
args?: Record<string, unknown> | undefined;
|
|
830
832
|
dependencies?: string[] | undefined;
|
|
831
833
|
}[];
|
|
832
834
|
goal: string;
|
|
@@ -837,7 +839,7 @@ declare const PlanExecuteStateConfig: {
|
|
|
837
839
|
id: string;
|
|
838
840
|
description: string;
|
|
839
841
|
tool?: string | undefined;
|
|
840
|
-
args?: Record<string,
|
|
842
|
+
args?: Record<string, unknown> | undefined;
|
|
841
843
|
dependencies?: string[] | undefined;
|
|
842
844
|
}[];
|
|
843
845
|
goal: string;
|
|
@@ -857,21 +859,21 @@ declare const PlanExecuteStateConfig: {
|
|
|
857
859
|
description: z.ZodString;
|
|
858
860
|
dependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
859
861
|
tool: z.ZodOptional<z.ZodString>;
|
|
860
|
-
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
862
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
861
863
|
}, "strip", z.ZodTypeAny, {
|
|
862
864
|
id: string;
|
|
863
865
|
description: string;
|
|
864
866
|
tool?: string | undefined;
|
|
865
|
-
args?: Record<string,
|
|
867
|
+
args?: Record<string, unknown> | undefined;
|
|
866
868
|
dependencies?: string[] | undefined;
|
|
867
869
|
}, {
|
|
868
870
|
id: string;
|
|
869
871
|
description: string;
|
|
870
872
|
tool?: string | undefined;
|
|
871
|
-
args?: Record<string,
|
|
873
|
+
args?: Record<string, unknown> | undefined;
|
|
872
874
|
dependencies?: string[] | undefined;
|
|
873
875
|
}>;
|
|
874
|
-
result: z.
|
|
876
|
+
result: z.ZodUnknown;
|
|
875
877
|
success: z.ZodBoolean;
|
|
876
878
|
error: z.ZodOptional<z.ZodString>;
|
|
877
879
|
timestamp: z.ZodString;
|
|
@@ -881,11 +883,11 @@ declare const PlanExecuteStateConfig: {
|
|
|
881
883
|
id: string;
|
|
882
884
|
description: string;
|
|
883
885
|
tool?: string | undefined;
|
|
884
|
-
args?: Record<string,
|
|
886
|
+
args?: Record<string, unknown> | undefined;
|
|
885
887
|
dependencies?: string[] | undefined;
|
|
886
888
|
};
|
|
887
889
|
success: boolean;
|
|
888
|
-
result?:
|
|
890
|
+
result?: unknown;
|
|
889
891
|
error?: string | undefined;
|
|
890
892
|
}, {
|
|
891
893
|
timestamp: string;
|
|
@@ -893,11 +895,11 @@ declare const PlanExecuteStateConfig: {
|
|
|
893
895
|
id: string;
|
|
894
896
|
description: string;
|
|
895
897
|
tool?: string | undefined;
|
|
896
|
-
args?: Record<string,
|
|
898
|
+
args?: Record<string, unknown> | undefined;
|
|
897
899
|
dependencies?: string[] | undefined;
|
|
898
900
|
};
|
|
899
901
|
success: boolean;
|
|
900
|
-
result?:
|
|
902
|
+
result?: unknown;
|
|
901
903
|
error?: string | undefined;
|
|
902
904
|
}>, "many">;
|
|
903
905
|
reducer: (left: CompletedStep[], right: CompletedStep[]) => {
|
|
@@ -906,11 +908,11 @@ declare const PlanExecuteStateConfig: {
|
|
|
906
908
|
id: string;
|
|
907
909
|
description: string;
|
|
908
910
|
tool?: string | undefined;
|
|
909
|
-
args?: Record<string,
|
|
911
|
+
args?: Record<string, unknown> | undefined;
|
|
910
912
|
dependencies?: string[] | undefined;
|
|
911
913
|
};
|
|
912
914
|
success: boolean;
|
|
913
|
-
result?:
|
|
915
|
+
result?: unknown;
|
|
914
916
|
error?: string | undefined;
|
|
915
917
|
}[];
|
|
916
918
|
default: () => never[];
|
|
@@ -975,7 +977,7 @@ declare const PlanExecuteState: _langchain_langgraph.AnnotationRoot<{
|
|
|
975
977
|
id: string;
|
|
976
978
|
description: string;
|
|
977
979
|
tool?: string | undefined;
|
|
978
|
-
args?: Record<string,
|
|
980
|
+
args?: Record<string, unknown> | undefined;
|
|
979
981
|
dependencies?: string[] | undefined;
|
|
980
982
|
}[];
|
|
981
983
|
goal: string;
|
|
@@ -986,7 +988,7 @@ declare const PlanExecuteState: _langchain_langgraph.AnnotationRoot<{
|
|
|
986
988
|
id: string;
|
|
987
989
|
description: string;
|
|
988
990
|
tool?: string | undefined;
|
|
989
|
-
args?: Record<string,
|
|
991
|
+
args?: Record<string, unknown> | undefined;
|
|
990
992
|
dependencies?: string[] | undefined;
|
|
991
993
|
}[];
|
|
992
994
|
goal: string;
|
|
@@ -999,11 +1001,11 @@ declare const PlanExecuteState: _langchain_langgraph.AnnotationRoot<{
|
|
|
999
1001
|
id: string;
|
|
1000
1002
|
description: string;
|
|
1001
1003
|
tool?: string | undefined;
|
|
1002
|
-
args?: Record<string,
|
|
1004
|
+
args?: Record<string, unknown> | undefined;
|
|
1003
1005
|
dependencies?: string[] | undefined;
|
|
1004
1006
|
};
|
|
1005
1007
|
success: boolean;
|
|
1006
|
-
result?:
|
|
1008
|
+
result?: unknown;
|
|
1007
1009
|
error?: string | undefined;
|
|
1008
1010
|
}[], {
|
|
1009
1011
|
timestamp: string;
|
|
@@ -1011,11 +1013,11 @@ declare const PlanExecuteState: _langchain_langgraph.AnnotationRoot<{
|
|
|
1011
1013
|
id: string;
|
|
1012
1014
|
description: string;
|
|
1013
1015
|
tool?: string | undefined;
|
|
1014
|
-
args?: Record<string,
|
|
1016
|
+
args?: Record<string, unknown> | undefined;
|
|
1015
1017
|
dependencies?: string[] | undefined;
|
|
1016
1018
|
};
|
|
1017
1019
|
success: boolean;
|
|
1018
|
-
result?:
|
|
1020
|
+
result?: unknown;
|
|
1019
1021
|
error?: string | undefined;
|
|
1020
1022
|
}[], unknown>;
|
|
1021
1023
|
currentStepIndex: _langchain_langgraph.BaseChannel<number | undefined, number | undefined, unknown>;
|
|
@@ -1050,6 +1052,10 @@ type PlanExecuteStateType = {
|
|
|
1050
1052
|
* @module patterns/plan-execute/types
|
|
1051
1053
|
*/
|
|
1052
1054
|
|
|
1055
|
+
interface PlanExecuteTool {
|
|
1056
|
+
metadata: ToolMetadata;
|
|
1057
|
+
invoke(input: PlanStepArguments): Promise<PlanStepResult>;
|
|
1058
|
+
}
|
|
1053
1059
|
/**
|
|
1054
1060
|
* Configuration for the planner node
|
|
1055
1061
|
*/
|
|
@@ -1074,17 +1080,19 @@ interface PlannerConfig {
|
|
|
1074
1080
|
/**
|
|
1075
1081
|
* Configuration for the executor node
|
|
1076
1082
|
*/
|
|
1077
|
-
interface ExecutorConfig {
|
|
1083
|
+
interface ExecutorConfig<TTool extends PlanExecuteTool = PlanExecuteTool> {
|
|
1078
1084
|
/**
|
|
1079
1085
|
* Available tools for execution
|
|
1080
1086
|
*/
|
|
1081
|
-
tools:
|
|
1087
|
+
tools: readonly TTool[];
|
|
1082
1088
|
/**
|
|
1083
|
-
* Optional language model for sub-tasks
|
|
1089
|
+
* Optional language model for sub-tasks.
|
|
1090
|
+
* Currently unsupported and ignored by the runtime executor node.
|
|
1084
1091
|
*/
|
|
1085
1092
|
model?: BaseChatModel;
|
|
1086
1093
|
/**
|
|
1087
|
-
* Enable parallel execution of independent steps
|
|
1094
|
+
* Enable parallel execution of independent steps.
|
|
1095
|
+
* Currently unsupported and ignored by the runtime executor node.
|
|
1088
1096
|
*/
|
|
1089
1097
|
parallel?: boolean;
|
|
1090
1098
|
/**
|
|
@@ -1106,8 +1114,9 @@ interface ReplannerConfig {
|
|
|
1106
1114
|
*/
|
|
1107
1115
|
model: BaseChatModel;
|
|
1108
1116
|
/**
|
|
1109
|
-
*
|
|
1110
|
-
*
|
|
1117
|
+
* Intended confidence threshold for replanning (0-1).
|
|
1118
|
+
* This is a forward-compatibility option and is currently ignored by the runtime replanner node.
|
|
1119
|
+
* Future versions may use this to decide when to trigger replanning.
|
|
1111
1120
|
*/
|
|
1112
1121
|
replanThreshold?: number;
|
|
1113
1122
|
/**
|
|
@@ -1118,7 +1127,7 @@ interface ReplannerConfig {
|
|
|
1118
1127
|
/**
|
|
1119
1128
|
* Configuration for creating a Plan-Execute agent
|
|
1120
1129
|
*/
|
|
1121
|
-
interface PlanExecuteAgentConfig {
|
|
1130
|
+
interface PlanExecuteAgentConfig<TTool extends PlanExecuteTool = PlanExecuteTool> {
|
|
1122
1131
|
/**
|
|
1123
1132
|
* Planner configuration
|
|
1124
1133
|
*/
|
|
@@ -1126,7 +1135,7 @@ interface PlanExecuteAgentConfig {
|
|
|
1126
1135
|
/**
|
|
1127
1136
|
* Executor configuration
|
|
1128
1137
|
*/
|
|
1129
|
-
executor: ExecutorConfig
|
|
1138
|
+
executor: ExecutorConfig<TTool>;
|
|
1130
1139
|
/**
|
|
1131
1140
|
* Optional replanner configuration
|
|
1132
1141
|
* If not provided, no replanning will occur
|
|
@@ -1196,12 +1205,10 @@ type PlanExecuteRouter = (state: PlanExecuteStateType) => PlanExecuteRoute;
|
|
|
1196
1205
|
* maxSteps: 5
|
|
1197
1206
|
* },
|
|
1198
1207
|
* executor: {
|
|
1199
|
-
* tools: [searchTool, calculatorTool]
|
|
1200
|
-
* parallel: false
|
|
1208
|
+
* tools: [searchTool, calculatorTool]
|
|
1201
1209
|
* },
|
|
1202
1210
|
* replanner: {
|
|
1203
|
-
* model: new ChatOpenAI({ model: 'gpt-4' })
|
|
1204
|
-
* replanThreshold: 0.7
|
|
1211
|
+
* model: new ChatOpenAI({ model: 'gpt-4' })
|
|
1205
1212
|
* }
|
|
1206
1213
|
* });
|
|
1207
1214
|
*
|
|
@@ -1234,14 +1241,14 @@ type PlanExecuteRouter = (state: PlanExecuteStateType) => PlanExecuteRoute;
|
|
|
1234
1241
|
* );
|
|
1235
1242
|
* ```
|
|
1236
1243
|
*/
|
|
1237
|
-
declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langchain_langgraph.CompiledStateGraph<{
|
|
1244
|
+
declare function createPlanExecuteAgent<TTool extends PlanExecuteTool = PlanExecuteTool>(config: PlanExecuteAgentConfig<TTool>): _langchain_langgraph.CompiledStateGraph<{
|
|
1238
1245
|
input: string;
|
|
1239
1246
|
plan: {
|
|
1240
1247
|
steps: {
|
|
1241
1248
|
id: string;
|
|
1242
1249
|
description: string;
|
|
1243
1250
|
tool?: string | undefined;
|
|
1244
|
-
args?: Record<string,
|
|
1251
|
+
args?: Record<string, unknown> | undefined;
|
|
1245
1252
|
dependencies?: string[] | undefined;
|
|
1246
1253
|
}[];
|
|
1247
1254
|
goal: string;
|
|
@@ -1254,11 +1261,11 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1254
1261
|
id: string;
|
|
1255
1262
|
description: string;
|
|
1256
1263
|
tool?: string | undefined;
|
|
1257
|
-
args?: Record<string,
|
|
1264
|
+
args?: Record<string, unknown> | undefined;
|
|
1258
1265
|
dependencies?: string[] | undefined;
|
|
1259
1266
|
};
|
|
1260
1267
|
success: boolean;
|
|
1261
|
-
result?:
|
|
1268
|
+
result?: unknown;
|
|
1262
1269
|
error?: string | undefined;
|
|
1263
1270
|
}[];
|
|
1264
1271
|
currentStepIndex: number | undefined;
|
|
@@ -1274,7 +1281,7 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1274
1281
|
id: string;
|
|
1275
1282
|
description: string;
|
|
1276
1283
|
tool?: string | undefined;
|
|
1277
|
-
args?: Record<string,
|
|
1284
|
+
args?: Record<string, unknown> | undefined;
|
|
1278
1285
|
dependencies?: string[] | undefined;
|
|
1279
1286
|
}[];
|
|
1280
1287
|
goal: string;
|
|
@@ -1287,11 +1294,11 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1287
1294
|
id: string;
|
|
1288
1295
|
description: string;
|
|
1289
1296
|
tool?: string | undefined;
|
|
1290
|
-
args?: Record<string,
|
|
1297
|
+
args?: Record<string, unknown> | undefined;
|
|
1291
1298
|
dependencies?: string[] | undefined;
|
|
1292
1299
|
};
|
|
1293
1300
|
success: boolean;
|
|
1294
|
-
result?:
|
|
1301
|
+
result?: unknown;
|
|
1295
1302
|
error?: string | undefined;
|
|
1296
1303
|
}[] | undefined;
|
|
1297
1304
|
currentStepIndex?: number | undefined;
|
|
@@ -1307,7 +1314,7 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1307
1314
|
id: string;
|
|
1308
1315
|
description: string;
|
|
1309
1316
|
tool?: string | undefined;
|
|
1310
|
-
args?: Record<string,
|
|
1317
|
+
args?: Record<string, unknown> | undefined;
|
|
1311
1318
|
dependencies?: string[] | undefined;
|
|
1312
1319
|
}[];
|
|
1313
1320
|
goal: string;
|
|
@@ -1318,7 +1325,7 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1318
1325
|
id: string;
|
|
1319
1326
|
description: string;
|
|
1320
1327
|
tool?: string | undefined;
|
|
1321
|
-
args?: Record<string,
|
|
1328
|
+
args?: Record<string, unknown> | undefined;
|
|
1322
1329
|
dependencies?: string[] | undefined;
|
|
1323
1330
|
}[];
|
|
1324
1331
|
goal: string;
|
|
@@ -1331,11 +1338,11 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1331
1338
|
id: string;
|
|
1332
1339
|
description: string;
|
|
1333
1340
|
tool?: string | undefined;
|
|
1334
|
-
args?: Record<string,
|
|
1341
|
+
args?: Record<string, unknown> | undefined;
|
|
1335
1342
|
dependencies?: string[] | undefined;
|
|
1336
1343
|
};
|
|
1337
1344
|
success: boolean;
|
|
1338
|
-
result?:
|
|
1345
|
+
result?: unknown;
|
|
1339
1346
|
error?: string | undefined;
|
|
1340
1347
|
}[], {
|
|
1341
1348
|
timestamp: string;
|
|
@@ -1343,11 +1350,11 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1343
1350
|
id: string;
|
|
1344
1351
|
description: string;
|
|
1345
1352
|
tool?: string | undefined;
|
|
1346
|
-
args?: Record<string,
|
|
1353
|
+
args?: Record<string, unknown> | undefined;
|
|
1347
1354
|
dependencies?: string[] | undefined;
|
|
1348
1355
|
};
|
|
1349
1356
|
success: boolean;
|
|
1350
|
-
result?:
|
|
1357
|
+
result?: unknown;
|
|
1351
1358
|
error?: string | undefined;
|
|
1352
1359
|
}[], unknown>;
|
|
1353
1360
|
currentStepIndex: _langchain_langgraph.BaseChannel<number | undefined, number | undefined, unknown>;
|
|
@@ -1363,7 +1370,7 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1363
1370
|
id: string;
|
|
1364
1371
|
description: string;
|
|
1365
1372
|
tool?: string | undefined;
|
|
1366
|
-
args?: Record<string,
|
|
1373
|
+
args?: Record<string, unknown> | undefined;
|
|
1367
1374
|
dependencies?: string[] | undefined;
|
|
1368
1375
|
}[];
|
|
1369
1376
|
goal: string;
|
|
@@ -1374,7 +1381,7 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1374
1381
|
id: string;
|
|
1375
1382
|
description: string;
|
|
1376
1383
|
tool?: string | undefined;
|
|
1377
|
-
args?: Record<string,
|
|
1384
|
+
args?: Record<string, unknown> | undefined;
|
|
1378
1385
|
dependencies?: string[] | undefined;
|
|
1379
1386
|
}[];
|
|
1380
1387
|
goal: string;
|
|
@@ -1387,11 +1394,11 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1387
1394
|
id: string;
|
|
1388
1395
|
description: string;
|
|
1389
1396
|
tool?: string | undefined;
|
|
1390
|
-
args?: Record<string,
|
|
1397
|
+
args?: Record<string, unknown> | undefined;
|
|
1391
1398
|
dependencies?: string[] | undefined;
|
|
1392
1399
|
};
|
|
1393
1400
|
success: boolean;
|
|
1394
|
-
result?:
|
|
1401
|
+
result?: unknown;
|
|
1395
1402
|
error?: string | undefined;
|
|
1396
1403
|
}[], {
|
|
1397
1404
|
timestamp: string;
|
|
@@ -1399,11 +1406,11 @@ declare function createPlanExecuteAgent(config: PlanExecuteAgentConfig): _langch
|
|
|
1399
1406
|
id: string;
|
|
1400
1407
|
description: string;
|
|
1401
1408
|
tool?: string | undefined;
|
|
1402
|
-
args?: Record<string,
|
|
1409
|
+
args?: Record<string, unknown> | undefined;
|
|
1403
1410
|
dependencies?: string[] | undefined;
|
|
1404
1411
|
};
|
|
1405
1412
|
success: boolean;
|
|
1406
|
-
result?:
|
|
1413
|
+
result?: unknown;
|
|
1407
1414
|
error?: string | undefined;
|
|
1408
1415
|
}[], unknown>;
|
|
1409
1416
|
currentStepIndex: _langchain_langgraph.BaseChannel<number | undefined, number | undefined, unknown>;
|
package/dist/index.js
CHANGED
|
@@ -790,7 +790,7 @@ var PlanStepSchema = z4.object({
|
|
|
790
790
|
/**
|
|
791
791
|
* Optional arguments for the tool
|
|
792
792
|
*/
|
|
793
|
-
args: z4.record(z4.
|
|
793
|
+
args: z4.record(z4.string(), z4.unknown()).optional().describe("Arguments to pass to the tool")
|
|
794
794
|
});
|
|
795
795
|
var CompletedStepSchema = z4.object({
|
|
796
796
|
/**
|
|
@@ -800,7 +800,7 @@ var CompletedStepSchema = z4.object({
|
|
|
800
800
|
/**
|
|
801
801
|
* The result of executing the step
|
|
802
802
|
*/
|
|
803
|
-
result: z4.
|
|
803
|
+
result: z4.unknown().describe("The result of executing the step"),
|
|
804
804
|
/**
|
|
805
805
|
* Whether the step succeeded
|
|
806
806
|
*/
|
|
@@ -977,6 +977,9 @@ var REMAINING_STEP_TEMPLATE = `Step {stepNumber}: {description}
|
|
|
977
977
|
var plannerLogger = createPatternLogger("agentforge:patterns:plan-execute:planner");
|
|
978
978
|
var executorLogger = createPatternLogger("agentforge:patterns:plan-execute:executor");
|
|
979
979
|
var replannerLogger = createPatternLogger("agentforge:patterns:plan-execute:replanner");
|
|
980
|
+
function invokePlanExecuteTool(tool, args) {
|
|
981
|
+
return tool.invoke.call(tool, args);
|
|
982
|
+
}
|
|
980
983
|
function createPlannerNode(config) {
|
|
981
984
|
const {
|
|
982
985
|
model,
|
|
@@ -1044,10 +1047,18 @@ function createExecutorNode(config) {
|
|
|
1044
1047
|
const {
|
|
1045
1048
|
tools,
|
|
1046
1049
|
model,
|
|
1047
|
-
parallel
|
|
1050
|
+
parallel,
|
|
1048
1051
|
stepTimeout = 3e4,
|
|
1049
1052
|
enableDeduplication = true
|
|
1050
1053
|
} = config;
|
|
1054
|
+
if (typeof model !== "undefined") {
|
|
1055
|
+
executorLogger.warn("ExecutorConfig.model is currently unsupported and will be ignored");
|
|
1056
|
+
}
|
|
1057
|
+
if (typeof parallel !== "undefined") {
|
|
1058
|
+
executorLogger.warn("ExecutorConfig.parallel is currently unsupported and will be ignored", {
|
|
1059
|
+
parallel
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1051
1062
|
return async (state) => {
|
|
1052
1063
|
const { plan, currentStepIndex = 0, pastSteps = [], iteration = 0 } = state;
|
|
1053
1064
|
try {
|
|
@@ -1124,13 +1135,20 @@ function createExecutorNode(config) {
|
|
|
1124
1135
|
throw new Error(`Tool not found: ${currentStep.tool}`);
|
|
1125
1136
|
}
|
|
1126
1137
|
const startTime = Date.now();
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1138
|
+
let timeoutId;
|
|
1139
|
+
try {
|
|
1140
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
1141
|
+
timeoutId = setTimeout(() => reject(new Error("Step execution timeout")), stepTimeout);
|
|
1142
|
+
});
|
|
1143
|
+
result = await Promise.race([
|
|
1144
|
+
invokePlanExecuteTool(tool, currentStep.args || {}),
|
|
1145
|
+
timeoutPromise
|
|
1146
|
+
]);
|
|
1147
|
+
} finally {
|
|
1148
|
+
if (timeoutId !== void 0) {
|
|
1149
|
+
clearTimeout(timeoutId);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1134
1152
|
const executionTime = Date.now() - startTime;
|
|
1135
1153
|
executorLogger.debug("Step executed successfully", {
|
|
1136
1154
|
stepId: currentStep.id,
|
|
@@ -1187,9 +1205,14 @@ function createExecutorNode(config) {
|
|
|
1187
1205
|
function createReplannerNode(config) {
|
|
1188
1206
|
const {
|
|
1189
1207
|
model,
|
|
1190
|
-
replanThreshold
|
|
1208
|
+
replanThreshold,
|
|
1191
1209
|
systemPrompt = DEFAULT_REPLANNER_SYSTEM_PROMPT
|
|
1192
1210
|
} = config;
|
|
1211
|
+
if (typeof replanThreshold !== "undefined") {
|
|
1212
|
+
replannerLogger.warn("ReplannerConfig.replanThreshold is currently unsupported and will be ignored", {
|
|
1213
|
+
replanThreshold
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1193
1216
|
return async (state) => {
|
|
1194
1217
|
const startTime = Date.now();
|
|
1195
1218
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentforge/patterns",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Production-ready agent workflow patterns for TypeScript including ReAct and Planner-Executor, built on LangGraph.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
"url": "https://github.com/TVScoundrel/agentforge/issues"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@agentforge/core": "0.
|
|
44
|
+
"@agentforge/core": "0.16.1",
|
|
45
45
|
"@langchain/core": "^1.1.17",
|
|
46
46
|
"@langchain/langgraph": "^1.1.2",
|
|
47
47
|
"zod": "^3.23.8"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@agentforge/testing": "0.
|
|
50
|
+
"@agentforge/testing": "0.16.1",
|
|
51
51
|
"@eslint/js": "^9.17.0",
|
|
52
52
|
"@types/node": "^22.10.2",
|
|
53
53
|
"eslint": "^9.17.0",
|