@axiom-lattice/core 2.0.2 → 2.0.4
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.js +472 -211
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +440 -179
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -641,19 +641,272 @@ registerToolLattice(
|
|
|
641
641
|
topic = "general",
|
|
642
642
|
includeRawContent = false
|
|
643
643
|
}, config) => {
|
|
644
|
+
console.log("[DEBUG][internet_search] Starting search with params:", {
|
|
645
|
+
query,
|
|
646
|
+
maxResults,
|
|
647
|
+
topic,
|
|
648
|
+
includeRawContent
|
|
649
|
+
});
|
|
650
|
+
console.log("[DEBUG][internet_search] Creating TavilySearch instance...");
|
|
644
651
|
const tavilySearch = new import_tavily.TavilySearch({
|
|
645
652
|
maxResults,
|
|
646
653
|
tavilyApiKey: process.env.TAVILY_API_KEY,
|
|
647
654
|
includeRawContent,
|
|
648
655
|
topic
|
|
649
656
|
});
|
|
657
|
+
console.log("[DEBUG][internet_search] Invoking search for query:", query);
|
|
650
658
|
const tavilyResponse = await tavilySearch.invoke({ query });
|
|
651
|
-
|
|
659
|
+
console.log(
|
|
660
|
+
"[DEBUG][internet_search] Search completed. Results count:",
|
|
661
|
+
tavilyResponse.results?.length ?? 0
|
|
662
|
+
);
|
|
663
|
+
const result = genUICard("Internet Search:" + query, "generic_data_table", {
|
|
652
664
|
dataSource: tavilyResponse.results
|
|
653
665
|
});
|
|
666
|
+
console.log("[DEBUG][internet_search] Returning UI card result");
|
|
667
|
+
return result;
|
|
654
668
|
}
|
|
655
669
|
);
|
|
656
670
|
|
|
671
|
+
// src/tool_lattice/write_todos/index.ts
|
|
672
|
+
var import_zod3 = __toESM(require("zod"));
|
|
673
|
+
var import_messages = require("@langchain/core/messages");
|
|
674
|
+
var import_langgraph2 = require("@langchain/langgraph");
|
|
675
|
+
var WRITE_TODOS_DESCRIPTION = `Use this tool to create and manage a structured task list for your current work session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user. It also helps the user understand the progress of the task and overall progress of their requests.
|
|
676
|
+
|
|
677
|
+
When to Use This Tool
|
|
678
|
+
Use this tool proactively in these scenarios:
|
|
679
|
+
|
|
680
|
+
Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
|
|
681
|
+
Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
|
|
682
|
+
User explicitly requests todo list - When the user directly asks you to use the todo list
|
|
683
|
+
User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
|
|
684
|
+
After receiving new instructions - Immediately capture user requirements as todos
|
|
685
|
+
When you start working on a task - Mark it as in_progress BEFORE beginning work. Ideally you should only have one todo as in_progress at a time
|
|
686
|
+
After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation
|
|
687
|
+
|
|
688
|
+
When NOT to Use This Tool
|
|
689
|
+
Skip using this tool when:
|
|
690
|
+
|
|
691
|
+
There is only a single, straightforward task
|
|
692
|
+
The task is trivial and tracking it provides no organizational benefit
|
|
693
|
+
The task can be completed in less than 3 trivial steps
|
|
694
|
+
The task is purely conversational or informational
|
|
695
|
+
|
|
696
|
+
NOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.`;
|
|
697
|
+
registerToolLattice(
|
|
698
|
+
"write_todos",
|
|
699
|
+
{
|
|
700
|
+
name: "write_todos",
|
|
701
|
+
description: WRITE_TODOS_DESCRIPTION,
|
|
702
|
+
needUserApprove: false,
|
|
703
|
+
schema: import_zod3.default.object({
|
|
704
|
+
todos: import_zod3.default.array(
|
|
705
|
+
import_zod3.default.object({
|
|
706
|
+
content: import_zod3.default.string().describe("Content of the todo item"),
|
|
707
|
+
status: import_zod3.default.enum(["pending", "in_progress", "completed"]).describe("Status of the todo")
|
|
708
|
+
})
|
|
709
|
+
).describe("List of todo items to update")
|
|
710
|
+
})
|
|
711
|
+
},
|
|
712
|
+
((input, config) => {
|
|
713
|
+
return new import_langgraph2.Command({
|
|
714
|
+
update: {
|
|
715
|
+
todos: input.todos,
|
|
716
|
+
messages: [
|
|
717
|
+
new import_messages.ToolMessage({
|
|
718
|
+
content: genUIMarkdown("todo_list", input.todos),
|
|
719
|
+
tool_call_id: config.toolCall?.id
|
|
720
|
+
})
|
|
721
|
+
]
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
})
|
|
725
|
+
);
|
|
726
|
+
|
|
727
|
+
// src/tool_lattice/read_file/index.ts
|
|
728
|
+
var import_zod4 = __toESM(require("zod"));
|
|
729
|
+
var import_langgraph3 = require("@langchain/langgraph");
|
|
730
|
+
var READ_FILE_DESCRIPTION = `Reads a file from the local filesystem. You can access any file directly by using this tool. Assume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.
|
|
731
|
+
Usage:
|
|
732
|
+
|
|
733
|
+
The file_path parameter must be an absolute path, not a relative path
|
|
734
|
+
By default, it reads up to 2000 lines starting from the beginning of the file
|
|
735
|
+
You can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters
|
|
736
|
+
Any lines longer than 2000 characters will be truncated
|
|
737
|
+
Results are returned using cat -n format, with line numbers starting at 1
|
|
738
|
+
You have the capability to call multiple tools in a single response. It is always better to speculatively read multiple files as a batch that are potentially useful.
|
|
739
|
+
If you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.`;
|
|
740
|
+
registerToolLattice(
|
|
741
|
+
"read_file",
|
|
742
|
+
{
|
|
743
|
+
name: "read_file",
|
|
744
|
+
description: READ_FILE_DESCRIPTION,
|
|
745
|
+
needUserApprove: false,
|
|
746
|
+
schema: import_zod4.default.object({
|
|
747
|
+
file_path: import_zod4.default.string().describe("Absolute path to the file to read"),
|
|
748
|
+
offset: import_zod4.default.number().optional().default(0).describe("Line offset to start reading from"),
|
|
749
|
+
limit: import_zod4.default.number().optional().default(2e3).describe("Maximum number of lines to read")
|
|
750
|
+
})
|
|
751
|
+
},
|
|
752
|
+
((input) => {
|
|
753
|
+
const state = (0, import_langgraph3.getCurrentTaskInput)();
|
|
754
|
+
const mockFilesystem = state.files || {};
|
|
755
|
+
const { file_path, offset = 0, limit = 2e3 } = input;
|
|
756
|
+
if (!(file_path in mockFilesystem)) {
|
|
757
|
+
return `Error: File '${file_path}' not found`;
|
|
758
|
+
}
|
|
759
|
+
const content = mockFilesystem[file_path];
|
|
760
|
+
if (!content || content.trim() === "") {
|
|
761
|
+
return "System reminder: File exists but has empty contents";
|
|
762
|
+
}
|
|
763
|
+
const lines = content.split("\n");
|
|
764
|
+
const startIdx = offset;
|
|
765
|
+
const endIdx = Math.min(startIdx + limit, lines.length);
|
|
766
|
+
if (startIdx >= lines.length) {
|
|
767
|
+
return `Error: Line offset ${offset} exceeds file length (${lines.length} lines)`;
|
|
768
|
+
}
|
|
769
|
+
const resultLines = [];
|
|
770
|
+
for (let i = startIdx; i < endIdx; i++) {
|
|
771
|
+
let lineContent = lines[i];
|
|
772
|
+
if (lineContent.length > 2e3) {
|
|
773
|
+
lineContent = lineContent.substring(0, 2e3);
|
|
774
|
+
}
|
|
775
|
+
const lineNumber = i + 1;
|
|
776
|
+
resultLines.push(`${lineNumber.toString().padStart(6)} ${lineContent}`);
|
|
777
|
+
}
|
|
778
|
+
return resultLines.join("\n");
|
|
779
|
+
})
|
|
780
|
+
);
|
|
781
|
+
|
|
782
|
+
// src/tool_lattice/write_file/index.ts
|
|
783
|
+
var import_zod5 = __toESM(require("zod"));
|
|
784
|
+
var import_messages2 = require("@langchain/core/messages");
|
|
785
|
+
var import_langgraph4 = require("@langchain/langgraph");
|
|
786
|
+
registerToolLattice(
|
|
787
|
+
"write_file",
|
|
788
|
+
{
|
|
789
|
+
name: "write_file",
|
|
790
|
+
description: "Write content to a file in the mock filesystem",
|
|
791
|
+
needUserApprove: false,
|
|
792
|
+
schema: import_zod5.default.object({
|
|
793
|
+
file_path: import_zod5.default.string().describe("Absolute path to the file to write"),
|
|
794
|
+
content: import_zod5.default.string().describe("Content to write to the file")
|
|
795
|
+
})
|
|
796
|
+
},
|
|
797
|
+
((input, config) => {
|
|
798
|
+
const state = (0, import_langgraph4.getCurrentTaskInput)();
|
|
799
|
+
const files = { ...state.files || {} };
|
|
800
|
+
files[input.file_path] = input.content;
|
|
801
|
+
return new import_langgraph4.Command({
|
|
802
|
+
update: {
|
|
803
|
+
files,
|
|
804
|
+
messages: [
|
|
805
|
+
new import_messages2.ToolMessage({
|
|
806
|
+
content: `Updated file ${input.file_path}`,
|
|
807
|
+
tool_call_id: config.toolCall?.id
|
|
808
|
+
})
|
|
809
|
+
]
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
})
|
|
813
|
+
);
|
|
814
|
+
|
|
815
|
+
// src/tool_lattice/edit_file/index.ts
|
|
816
|
+
var import_zod6 = __toESM(require("zod"));
|
|
817
|
+
var import_messages3 = require("@langchain/core/messages");
|
|
818
|
+
var import_langgraph5 = require("@langchain/langgraph");
|
|
819
|
+
var EDIT_FILE_DESCRIPTION = `Performs exact string replacements in files.
|
|
820
|
+
Usage:
|
|
821
|
+
|
|
822
|
+
You must use your Read tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file.
|
|
823
|
+
When editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: spaces + line number + tab. Everything after that tab is the actual file content to match. Never include any part of the line number prefix in the old_string or new_string.
|
|
824
|
+
ALWAYS prefer editing existing files. NEVER write new files unless explicitly required.
|
|
825
|
+
Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.
|
|
826
|
+
The edit will FAIL if old_string is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use replace_all to change every instance of old_string.
|
|
827
|
+
Use replace_all for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.`;
|
|
828
|
+
registerToolLattice(
|
|
829
|
+
"edit_file",
|
|
830
|
+
{
|
|
831
|
+
name: "edit_file",
|
|
832
|
+
description: EDIT_FILE_DESCRIPTION,
|
|
833
|
+
needUserApprove: false,
|
|
834
|
+
schema: import_zod6.default.object({
|
|
835
|
+
file_path: import_zod6.default.string().describe("Absolute path to the file to edit"),
|
|
836
|
+
old_string: import_zod6.default.string().describe("String to be replaced (must match exactly)"),
|
|
837
|
+
new_string: import_zod6.default.string().describe("String to replace with"),
|
|
838
|
+
replace_all: import_zod6.default.boolean().optional().default(false).describe("Whether to replace all occurrences")
|
|
839
|
+
})
|
|
840
|
+
},
|
|
841
|
+
((input, config) => {
|
|
842
|
+
const state = (0, import_langgraph5.getCurrentTaskInput)();
|
|
843
|
+
const mockFilesystem = { ...state.files || {} };
|
|
844
|
+
const { file_path, old_string, new_string, replace_all = false } = input;
|
|
845
|
+
if (!(file_path in mockFilesystem)) {
|
|
846
|
+
return `Error: File '${file_path}' not found`;
|
|
847
|
+
}
|
|
848
|
+
const content = mockFilesystem[file_path];
|
|
849
|
+
if (!content.includes(old_string)) {
|
|
850
|
+
return `Error: String not found in file: '${old_string}'`;
|
|
851
|
+
}
|
|
852
|
+
if (!replace_all) {
|
|
853
|
+
const escapedOldString = old_string.replace(
|
|
854
|
+
/[.*+?^${}()|[\]\\]/g,
|
|
855
|
+
"\\$&"
|
|
856
|
+
);
|
|
857
|
+
const occurrences = (content.match(new RegExp(escapedOldString, "g")) || []).length;
|
|
858
|
+
if (occurrences > 1) {
|
|
859
|
+
return `Error: String '${old_string}' appears ${occurrences} times in file. Use replace_all=True to replace all instances, or provide a more specific string with surrounding context.`;
|
|
860
|
+
} else if (occurrences === 0) {
|
|
861
|
+
return `Error: String not found in file: '${old_string}'`;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
let newContent;
|
|
865
|
+
if (replace_all) {
|
|
866
|
+
const escapedOldString = old_string.replace(
|
|
867
|
+
/[.*+?^${}()|[\]\\]/g,
|
|
868
|
+
"\\$&"
|
|
869
|
+
);
|
|
870
|
+
newContent = content.replace(
|
|
871
|
+
new RegExp(escapedOldString, "g"),
|
|
872
|
+
new_string
|
|
873
|
+
);
|
|
874
|
+
} else {
|
|
875
|
+
newContent = content.replace(old_string, new_string);
|
|
876
|
+
}
|
|
877
|
+
mockFilesystem[file_path] = newContent;
|
|
878
|
+
return new import_langgraph5.Command({
|
|
879
|
+
update: {
|
|
880
|
+
files: mockFilesystem,
|
|
881
|
+
messages: [
|
|
882
|
+
new import_messages3.ToolMessage({
|
|
883
|
+
content: `Updated file ${file_path}`,
|
|
884
|
+
tool_call_id: config.toolCall?.id
|
|
885
|
+
})
|
|
886
|
+
]
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
})
|
|
890
|
+
);
|
|
891
|
+
|
|
892
|
+
// src/tool_lattice/ls/index.ts
|
|
893
|
+
var import_zod7 = __toESM(require("zod"));
|
|
894
|
+
var import_langgraph6 = require("@langchain/langgraph");
|
|
895
|
+
registerToolLattice(
|
|
896
|
+
"ls",
|
|
897
|
+
{
|
|
898
|
+
name: "ls",
|
|
899
|
+
description: "List all files in the mock filesystem",
|
|
900
|
+
needUserApprove: false,
|
|
901
|
+
schema: import_zod7.default.object({})
|
|
902
|
+
},
|
|
903
|
+
(() => {
|
|
904
|
+
const state = (0, import_langgraph6.getCurrentTaskInput)();
|
|
905
|
+
const files = state.files || {};
|
|
906
|
+
return Object.keys(files);
|
|
907
|
+
})
|
|
908
|
+
);
|
|
909
|
+
|
|
657
910
|
// src/agent_lattice/types.ts
|
|
658
911
|
var import_protocols = require("@axiom-lattice/protocols");
|
|
659
912
|
|
|
@@ -661,7 +914,7 @@ var import_protocols = require("@axiom-lattice/protocols");
|
|
|
661
914
|
var import_prebuilt = require("@langchain/langgraph/prebuilt");
|
|
662
915
|
|
|
663
916
|
// src/memory_lattice/DefaultMemorySaver.ts
|
|
664
|
-
var
|
|
917
|
+
var import_langgraph7 = require("@langchain/langgraph");
|
|
665
918
|
|
|
666
919
|
// src/memory_lattice/MemoryLatticeManager.ts
|
|
667
920
|
var import_protocols2 = require("@axiom-lattice/protocols");
|
|
@@ -737,20 +990,20 @@ var getCheckpointSaver = (key) => MemoryLatticeManager.getInstance().getCheckpoi
|
|
|
737
990
|
var registerCheckpointSaver = (key, saver) => MemoryLatticeManager.getInstance().registerCheckpointSaver(key, saver);
|
|
738
991
|
|
|
739
992
|
// src/memory_lattice/DefaultMemorySaver.ts
|
|
740
|
-
var memory = new
|
|
993
|
+
var memory = new import_langgraph7.MemorySaver();
|
|
741
994
|
registerCheckpointSaver("default", memory);
|
|
742
995
|
|
|
743
996
|
// src/agent_lattice/builders/state.ts
|
|
744
|
-
var
|
|
745
|
-
var
|
|
746
|
-
var
|
|
747
|
-
var ReActAgentState =
|
|
748
|
-
files:
|
|
749
|
-
final_output:
|
|
997
|
+
var import_zod8 = require("@langchain/langgraph/zod");
|
|
998
|
+
var import_langgraph8 = require("@langchain/langgraph");
|
|
999
|
+
var import_zod9 = require("zod");
|
|
1000
|
+
var ReActAgentState = import_langgraph8.MessagesZodState.extend({
|
|
1001
|
+
files: import_zod9.z.object({
|
|
1002
|
+
final_output: import_zod9.z.record(import_zod9.z.any())
|
|
750
1003
|
})
|
|
751
1004
|
});
|
|
752
1005
|
var createReactAgentSchema = (schema) => {
|
|
753
|
-
return schema ?
|
|
1006
|
+
return schema ? import_langgraph8.MessagesZodState.extend(schema.shape) : void 0;
|
|
754
1007
|
};
|
|
755
1008
|
|
|
756
1009
|
// src/agent_lattice/builders/ReActAgentGraphBuilder.ts
|
|
@@ -780,19 +1033,13 @@ var ReActAgentGraphBuilder = class {
|
|
|
780
1033
|
};
|
|
781
1034
|
|
|
782
1035
|
// src/deep_agent/subAgent.ts
|
|
783
|
-
var import_tools3 = require("@langchain/core/tools");
|
|
784
|
-
var import_messages2 = require("@langchain/core/messages");
|
|
785
|
-
var import_langgraph5 = require("@langchain/langgraph");
|
|
786
|
-
var import_zod6 = require("zod");
|
|
787
|
-
|
|
788
|
-
// src/deep_agent/tools.ts
|
|
789
1036
|
var import_tools2 = require("@langchain/core/tools");
|
|
790
|
-
var
|
|
791
|
-
var
|
|
792
|
-
var
|
|
1037
|
+
var import_messages4 = require("@langchain/core/messages");
|
|
1038
|
+
var import_langgraph9 = require("@langchain/langgraph");
|
|
1039
|
+
var import_zod10 = require("zod");
|
|
793
1040
|
|
|
794
1041
|
// src/deep_agent/prompts.ts
|
|
795
|
-
var
|
|
1042
|
+
var WRITE_TODOS_DESCRIPTION2 = `Use this tool to create and manage a structured task list for your current work session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user. It also helps the user understand the progress of the task and overall progress of their requests.
|
|
796
1043
|
|
|
797
1044
|
When to Use This Tool
|
|
798
1045
|
Use this tool proactively in these scenarios:
|
|
@@ -1046,14 +1293,140 @@ Results are returned using cat -n format, with line numbers starting at 1
|
|
|
1046
1293
|
You have the capability to call multiple tools in a single response. It is always better to speculatively read multiple files as a batch that are potentially useful.
|
|
1047
1294
|
If you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.`;
|
|
1048
1295
|
|
|
1296
|
+
// src/deep_agent/subAgent.ts
|
|
1297
|
+
var import_protocols3 = require("@axiom-lattice/protocols");
|
|
1298
|
+
var BUILTIN_TOOL_NAMES = [
|
|
1299
|
+
"write_todos",
|
|
1300
|
+
"read_file",
|
|
1301
|
+
"write_file",
|
|
1302
|
+
"edit_file",
|
|
1303
|
+
"ls"
|
|
1304
|
+
];
|
|
1305
|
+
function getBuiltinTools() {
|
|
1306
|
+
const tools = {};
|
|
1307
|
+
for (const name of BUILTIN_TOOL_NAMES) {
|
|
1308
|
+
try {
|
|
1309
|
+
tools[name] = getToolClient(name);
|
|
1310
|
+
} catch {
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
return tools;
|
|
1314
|
+
}
|
|
1315
|
+
function createTaskTool(inputs) {
|
|
1316
|
+
const {
|
|
1317
|
+
subagents,
|
|
1318
|
+
tools = {},
|
|
1319
|
+
model = getModelLattice("default")?.client,
|
|
1320
|
+
stateSchema,
|
|
1321
|
+
postModelHook
|
|
1322
|
+
} = inputs;
|
|
1323
|
+
if (!model) {
|
|
1324
|
+
throw new Error("Model not found");
|
|
1325
|
+
}
|
|
1326
|
+
const allTools = { ...getBuiltinTools(), ...tools };
|
|
1327
|
+
const agentsMap = /* @__PURE__ */ new Map();
|
|
1328
|
+
for (const subagent of subagents) {
|
|
1329
|
+
let reactAgent;
|
|
1330
|
+
const agentLattice = getAgentLattice(subagent.key);
|
|
1331
|
+
if (agentLattice) {
|
|
1332
|
+
reactAgent = agentLattice.client;
|
|
1333
|
+
} else {
|
|
1334
|
+
const subagentTools = [];
|
|
1335
|
+
if ((0, import_protocols3.hasTools)(subagent)) {
|
|
1336
|
+
for (const toolName of (0, import_protocols3.getToolsFromConfig)(subagent)) {
|
|
1337
|
+
const resolvedTool = allTools[toolName];
|
|
1338
|
+
if (resolvedTool) {
|
|
1339
|
+
subagentTools.push(resolvedTool);
|
|
1340
|
+
} else {
|
|
1341
|
+
console.warn(
|
|
1342
|
+
`Warning: Tool '${toolName}' not found for agent '${subagent.name}'`
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
} else {
|
|
1347
|
+
subagentTools.push(...Object.values(allTools));
|
|
1348
|
+
}
|
|
1349
|
+
reactAgent = createAgentClientFromAgentLattice({ config: subagent });
|
|
1350
|
+
}
|
|
1351
|
+
agentsMap.set(subagent.name, reactAgent);
|
|
1352
|
+
}
|
|
1353
|
+
return (0, import_tools2.tool)(
|
|
1354
|
+
async (input, config) => {
|
|
1355
|
+
const { description, subagent_type } = input;
|
|
1356
|
+
const reactAgent = agentsMap.get(subagent_type);
|
|
1357
|
+
if (!reactAgent) {
|
|
1358
|
+
return `Error: Agent '${subagent_type}' not found. Available agents: ${Array.from(
|
|
1359
|
+
agentsMap.keys()
|
|
1360
|
+
).join(", ")}`;
|
|
1361
|
+
}
|
|
1362
|
+
try {
|
|
1363
|
+
const currentState = (0, import_langgraph9.getCurrentTaskInput)();
|
|
1364
|
+
const modifiedState = {
|
|
1365
|
+
...currentState,
|
|
1366
|
+
messages: [
|
|
1367
|
+
{
|
|
1368
|
+
role: "user",
|
|
1369
|
+
content: description
|
|
1370
|
+
}
|
|
1371
|
+
]
|
|
1372
|
+
};
|
|
1373
|
+
const result = await reactAgent.invoke(modifiedState, config);
|
|
1374
|
+
return new import_langgraph9.Command({
|
|
1375
|
+
update: {
|
|
1376
|
+
files: result.files || {},
|
|
1377
|
+
messages: [
|
|
1378
|
+
new import_messages4.ToolMessage({
|
|
1379
|
+
content: result.messages?.slice(-1)[0]?.content || "Task completed",
|
|
1380
|
+
tool_call_id: config.toolCall?.id
|
|
1381
|
+
})
|
|
1382
|
+
]
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
} catch (error) {
|
|
1386
|
+
if (error instanceof import_langgraph9.GraphInterrupt) {
|
|
1387
|
+
throw error;
|
|
1388
|
+
}
|
|
1389
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1390
|
+
return new import_langgraph9.Command({
|
|
1391
|
+
update: {
|
|
1392
|
+
messages: [
|
|
1393
|
+
new import_messages4.ToolMessage({
|
|
1394
|
+
content: `Error executing task '${description}' with agent '${subagent_type}': ${errorMessage}`,
|
|
1395
|
+
tool_call_id: config.toolCall?.id
|
|
1396
|
+
})
|
|
1397
|
+
]
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
},
|
|
1402
|
+
{
|
|
1403
|
+
name: "task",
|
|
1404
|
+
description: TASK_DESCRIPTION_PREFIX.replace(
|
|
1405
|
+
"{other_agents}",
|
|
1406
|
+
subagents.map((a) => `- ${a.name}: ${a.description}`).join("\n")
|
|
1407
|
+
) + TASK_DESCRIPTION_SUFFIX,
|
|
1408
|
+
schema: import_zod10.z.object({
|
|
1409
|
+
description: import_zod10.z.string().describe("The task to execute with the selected agent"),
|
|
1410
|
+
subagent_type: import_zod10.z.string().describe(
|
|
1411
|
+
`Name of the agent to use. Available: ${subagents.map((a) => a.name).join(", ")}`
|
|
1412
|
+
)
|
|
1413
|
+
})
|
|
1414
|
+
}
|
|
1415
|
+
);
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1049
1418
|
// src/deep_agent/tools.ts
|
|
1050
|
-
var
|
|
1419
|
+
var import_tools3 = require("@langchain/core/tools");
|
|
1420
|
+
var import_messages5 = require("@langchain/core/messages");
|
|
1421
|
+
var import_langgraph10 = require("@langchain/langgraph");
|
|
1422
|
+
var import_zod11 = require("zod");
|
|
1423
|
+
var writeTodos = (0, import_tools3.tool)(
|
|
1051
1424
|
(input, config) => {
|
|
1052
|
-
return new
|
|
1425
|
+
return new import_langgraph10.Command({
|
|
1053
1426
|
update: {
|
|
1054
1427
|
todos: input.todos,
|
|
1055
1428
|
messages: [
|
|
1056
|
-
new
|
|
1429
|
+
new import_messages5.ToolMessage({
|
|
1057
1430
|
content: genUIMarkdown("todo_list", input.todos),
|
|
1058
1431
|
tool_call_id: config.toolCall?.id
|
|
1059
1432
|
})
|
|
@@ -1063,32 +1436,32 @@ var writeTodos = (0, import_tools2.tool)(
|
|
|
1063
1436
|
},
|
|
1064
1437
|
{
|
|
1065
1438
|
name: "write_todos",
|
|
1066
|
-
description:
|
|
1067
|
-
schema:
|
|
1068
|
-
todos:
|
|
1069
|
-
|
|
1070
|
-
content:
|
|
1071
|
-
status:
|
|
1439
|
+
description: WRITE_TODOS_DESCRIPTION2,
|
|
1440
|
+
schema: import_zod11.z.object({
|
|
1441
|
+
todos: import_zod11.z.array(
|
|
1442
|
+
import_zod11.z.object({
|
|
1443
|
+
content: import_zod11.z.string().describe("Content of the todo item"),
|
|
1444
|
+
status: import_zod11.z.enum(["pending", "in_progress", "completed"]).describe("Status of the todo")
|
|
1072
1445
|
})
|
|
1073
1446
|
).describe("List of todo items to update")
|
|
1074
1447
|
})
|
|
1075
1448
|
}
|
|
1076
1449
|
);
|
|
1077
|
-
var ls = (0,
|
|
1450
|
+
var ls = (0, import_tools3.tool)(
|
|
1078
1451
|
() => {
|
|
1079
|
-
const state = (0,
|
|
1452
|
+
const state = (0, import_langgraph10.getCurrentTaskInput)();
|
|
1080
1453
|
const files = state.files || {};
|
|
1081
1454
|
return Object.keys(files);
|
|
1082
1455
|
},
|
|
1083
1456
|
{
|
|
1084
1457
|
name: "ls",
|
|
1085
1458
|
description: "List all files in the mock filesystem",
|
|
1086
|
-
schema:
|
|
1459
|
+
schema: import_zod11.z.object({})
|
|
1087
1460
|
}
|
|
1088
1461
|
);
|
|
1089
|
-
var readFile = (0,
|
|
1462
|
+
var readFile = (0, import_tools3.tool)(
|
|
1090
1463
|
(input) => {
|
|
1091
|
-
const state = (0,
|
|
1464
|
+
const state = (0, import_langgraph10.getCurrentTaskInput)();
|
|
1092
1465
|
const mockFilesystem = state.files || {};
|
|
1093
1466
|
const { file_path, offset = 0, limit = 2e3 } = input;
|
|
1094
1467
|
if (!(file_path in mockFilesystem)) {
|
|
@@ -1118,23 +1491,23 @@ var readFile = (0, import_tools2.tool)(
|
|
|
1118
1491
|
{
|
|
1119
1492
|
name: "read_file",
|
|
1120
1493
|
description: TOOL_DESCRIPTION,
|
|
1121
|
-
schema:
|
|
1122
|
-
file_path:
|
|
1123
|
-
offset:
|
|
1124
|
-
limit:
|
|
1494
|
+
schema: import_zod11.z.object({
|
|
1495
|
+
file_path: import_zod11.z.string().describe("Absolute path to the file to read"),
|
|
1496
|
+
offset: import_zod11.z.number().optional().default(0).describe("Line offset to start reading from"),
|
|
1497
|
+
limit: import_zod11.z.number().optional().default(2e3).describe("Maximum number of lines to read")
|
|
1125
1498
|
})
|
|
1126
1499
|
}
|
|
1127
1500
|
);
|
|
1128
|
-
var writeFile = (0,
|
|
1501
|
+
var writeFile = (0, import_tools3.tool)(
|
|
1129
1502
|
(input, config) => {
|
|
1130
|
-
const state = (0,
|
|
1503
|
+
const state = (0, import_langgraph10.getCurrentTaskInput)();
|
|
1131
1504
|
const files = { ...state.files || {} };
|
|
1132
1505
|
files[input.file_path] = input.content;
|
|
1133
|
-
return new
|
|
1506
|
+
return new import_langgraph10.Command({
|
|
1134
1507
|
update: {
|
|
1135
1508
|
files,
|
|
1136
1509
|
messages: [
|
|
1137
|
-
new
|
|
1510
|
+
new import_messages5.ToolMessage({
|
|
1138
1511
|
content: `Updated file ${input.file_path}`,
|
|
1139
1512
|
tool_call_id: config.toolCall?.id
|
|
1140
1513
|
})
|
|
@@ -1145,15 +1518,15 @@ var writeFile = (0, import_tools2.tool)(
|
|
|
1145
1518
|
{
|
|
1146
1519
|
name: "write_file",
|
|
1147
1520
|
description: "Write content to a file in the mock filesystem",
|
|
1148
|
-
schema:
|
|
1149
|
-
file_path:
|
|
1150
|
-
content:
|
|
1521
|
+
schema: import_zod11.z.object({
|
|
1522
|
+
file_path: import_zod11.z.string().describe("Absolute path to the file to write"),
|
|
1523
|
+
content: import_zod11.z.string().describe("Content to write to the file")
|
|
1151
1524
|
})
|
|
1152
1525
|
}
|
|
1153
1526
|
);
|
|
1154
|
-
var editFile = (0,
|
|
1527
|
+
var editFile = (0, import_tools3.tool)(
|
|
1155
1528
|
(input, config) => {
|
|
1156
|
-
const state = (0,
|
|
1529
|
+
const state = (0, import_langgraph10.getCurrentTaskInput)();
|
|
1157
1530
|
const mockFilesystem = { ...state.files || {} };
|
|
1158
1531
|
const { file_path, old_string, new_string, replace_all = false } = input;
|
|
1159
1532
|
if (!(file_path in mockFilesystem)) {
|
|
@@ -1189,11 +1562,11 @@ var editFile = (0, import_tools2.tool)(
|
|
|
1189
1562
|
newContent = content.replace(old_string, new_string);
|
|
1190
1563
|
}
|
|
1191
1564
|
mockFilesystem[file_path] = newContent;
|
|
1192
|
-
return new
|
|
1565
|
+
return new import_langgraph10.Command({
|
|
1193
1566
|
update: {
|
|
1194
1567
|
files: mockFilesystem,
|
|
1195
1568
|
messages: [
|
|
1196
|
-
new
|
|
1569
|
+
new import_messages5.ToolMessage({
|
|
1197
1570
|
content: `Updated file ${file_path}`,
|
|
1198
1571
|
tool_call_id: config.toolCall?.id
|
|
1199
1572
|
})
|
|
@@ -1204,132 +1577,20 @@ var editFile = (0, import_tools2.tool)(
|
|
|
1204
1577
|
{
|
|
1205
1578
|
name: "edit_file",
|
|
1206
1579
|
description: EDIT_DESCRIPTION,
|
|
1207
|
-
schema:
|
|
1208
|
-
file_path:
|
|
1209
|
-
old_string:
|
|
1210
|
-
new_string:
|
|
1211
|
-
replace_all:
|
|
1580
|
+
schema: import_zod11.z.object({
|
|
1581
|
+
file_path: import_zod11.z.string().describe("Absolute path to the file to edit"),
|
|
1582
|
+
old_string: import_zod11.z.string().describe("String to be replaced (must match exactly)"),
|
|
1583
|
+
new_string: import_zod11.z.string().describe("String to replace with"),
|
|
1584
|
+
replace_all: import_zod11.z.boolean().optional().default(false).describe("Whether to replace all occurrences")
|
|
1212
1585
|
})
|
|
1213
1586
|
}
|
|
1214
1587
|
);
|
|
1215
1588
|
|
|
1216
|
-
// src/deep_agent/subAgent.ts
|
|
1217
|
-
var import_protocols3 = require("@axiom-lattice/protocols");
|
|
1218
|
-
var BUILTIN_TOOLS = {
|
|
1219
|
-
write_todos: writeTodos,
|
|
1220
|
-
read_file: readFile,
|
|
1221
|
-
write_file: writeFile,
|
|
1222
|
-
edit_file: editFile,
|
|
1223
|
-
ls
|
|
1224
|
-
};
|
|
1225
|
-
function createTaskTool(inputs) {
|
|
1226
|
-
const {
|
|
1227
|
-
subagents,
|
|
1228
|
-
tools = {},
|
|
1229
|
-
model = getModelLattice("default")?.client,
|
|
1230
|
-
stateSchema,
|
|
1231
|
-
postModelHook
|
|
1232
|
-
} = inputs;
|
|
1233
|
-
if (!model) {
|
|
1234
|
-
throw new Error("Model not found");
|
|
1235
|
-
}
|
|
1236
|
-
const allTools = { ...BUILTIN_TOOLS, ...tools };
|
|
1237
|
-
const agentsMap = /* @__PURE__ */ new Map();
|
|
1238
|
-
for (const subagent of subagents) {
|
|
1239
|
-
let reactAgent;
|
|
1240
|
-
const agentLattice = getAgentLattice(subagent.key);
|
|
1241
|
-
if (agentLattice) {
|
|
1242
|
-
reactAgent = agentLattice.client;
|
|
1243
|
-
} else {
|
|
1244
|
-
const subagentTools = [];
|
|
1245
|
-
if ((0, import_protocols3.hasTools)(subagent)) {
|
|
1246
|
-
for (const toolName of (0, import_protocols3.getToolsFromConfig)(subagent)) {
|
|
1247
|
-
const resolvedTool = allTools[toolName];
|
|
1248
|
-
if (resolvedTool) {
|
|
1249
|
-
subagentTools.push(resolvedTool);
|
|
1250
|
-
} else {
|
|
1251
|
-
console.warn(
|
|
1252
|
-
`Warning: Tool '${toolName}' not found for agent '${subagent.name}'`
|
|
1253
|
-
);
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
} else {
|
|
1257
|
-
subagentTools.push(...Object.values(allTools));
|
|
1258
|
-
}
|
|
1259
|
-
reactAgent = createAgentClientFromAgentLattice({ config: subagent });
|
|
1260
|
-
}
|
|
1261
|
-
agentsMap.set(subagent.name, reactAgent);
|
|
1262
|
-
}
|
|
1263
|
-
return (0, import_tools3.tool)(
|
|
1264
|
-
async (input, config) => {
|
|
1265
|
-
const { description, subagent_type } = input;
|
|
1266
|
-
const reactAgent = agentsMap.get(subagent_type);
|
|
1267
|
-
if (!reactAgent) {
|
|
1268
|
-
return `Error: Agent '${subagent_type}' not found. Available agents: ${Array.from(
|
|
1269
|
-
agentsMap.keys()
|
|
1270
|
-
).join(", ")}`;
|
|
1271
|
-
}
|
|
1272
|
-
try {
|
|
1273
|
-
const currentState = (0, import_langgraph5.getCurrentTaskInput)();
|
|
1274
|
-
const modifiedState = {
|
|
1275
|
-
...currentState,
|
|
1276
|
-
messages: [
|
|
1277
|
-
{
|
|
1278
|
-
role: "user",
|
|
1279
|
-
content: description
|
|
1280
|
-
}
|
|
1281
|
-
]
|
|
1282
|
-
};
|
|
1283
|
-
const result = await reactAgent.invoke(modifiedState, config);
|
|
1284
|
-
return new import_langgraph5.Command({
|
|
1285
|
-
update: {
|
|
1286
|
-
files: result.files || {},
|
|
1287
|
-
messages: [
|
|
1288
|
-
new import_messages2.ToolMessage({
|
|
1289
|
-
content: result.messages?.slice(-1)[0]?.content || "Task completed",
|
|
1290
|
-
tool_call_id: config.toolCall?.id
|
|
1291
|
-
})
|
|
1292
|
-
]
|
|
1293
|
-
}
|
|
1294
|
-
});
|
|
1295
|
-
} catch (error) {
|
|
1296
|
-
if (error instanceof import_langgraph5.GraphInterrupt) {
|
|
1297
|
-
throw error;
|
|
1298
|
-
}
|
|
1299
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1300
|
-
return new import_langgraph5.Command({
|
|
1301
|
-
update: {
|
|
1302
|
-
messages: [
|
|
1303
|
-
new import_messages2.ToolMessage({
|
|
1304
|
-
content: `Error executing task '${description}' with agent '${subagent_type}': ${errorMessage}`,
|
|
1305
|
-
tool_call_id: config.toolCall?.id
|
|
1306
|
-
})
|
|
1307
|
-
]
|
|
1308
|
-
}
|
|
1309
|
-
});
|
|
1310
|
-
}
|
|
1311
|
-
},
|
|
1312
|
-
{
|
|
1313
|
-
name: "task",
|
|
1314
|
-
description: TASK_DESCRIPTION_PREFIX.replace(
|
|
1315
|
-
"{other_agents}",
|
|
1316
|
-
subagents.map((a) => `- ${a.name}: ${a.description}`).join("\n")
|
|
1317
|
-
) + TASK_DESCRIPTION_SUFFIX,
|
|
1318
|
-
schema: import_zod6.z.object({
|
|
1319
|
-
description: import_zod6.z.string().describe("The task to execute with the selected agent"),
|
|
1320
|
-
subagent_type: import_zod6.z.string().describe(
|
|
1321
|
-
`Name of the agent to use. Available: ${subagents.map((a) => a.name).join(", ")}`
|
|
1322
|
-
)
|
|
1323
|
-
})
|
|
1324
|
-
}
|
|
1325
|
-
);
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
1589
|
// src/deep_agent/state.ts
|
|
1329
|
-
var
|
|
1330
|
-
var
|
|
1331
|
-
var
|
|
1332
|
-
var
|
|
1590
|
+
var import_zod12 = require("@langchain/langgraph/zod");
|
|
1591
|
+
var import_langgraph11 = require("@langchain/langgraph");
|
|
1592
|
+
var import_zod13 = require("@langchain/langgraph/zod");
|
|
1593
|
+
var import_zod14 = require("zod");
|
|
1333
1594
|
function fileReducer(left, right) {
|
|
1334
1595
|
if (left == null) {
|
|
1335
1596
|
return right || {};
|
|
@@ -1345,16 +1606,16 @@ function todoReducer(left, right) {
|
|
|
1345
1606
|
}
|
|
1346
1607
|
return left || [];
|
|
1347
1608
|
}
|
|
1348
|
-
var DeepAgentState =
|
|
1349
|
-
todos: (0,
|
|
1609
|
+
var DeepAgentState = import_langgraph11.MessagesZodState.extend({
|
|
1610
|
+
todos: (0, import_zod13.withLangGraph)(import_zod14.z.custom(), {
|
|
1350
1611
|
reducer: {
|
|
1351
|
-
schema:
|
|
1612
|
+
schema: import_zod14.z.custom(),
|
|
1352
1613
|
fn: todoReducer
|
|
1353
1614
|
}
|
|
1354
1615
|
}),
|
|
1355
|
-
files: (0,
|
|
1616
|
+
files: (0, import_zod13.withLangGraph)(import_zod14.z.custom(), {
|
|
1356
1617
|
reducer: {
|
|
1357
|
-
schema:
|
|
1618
|
+
schema: import_zod14.z.custom(),
|
|
1358
1619
|
fn: fileReducer
|
|
1359
1620
|
}
|
|
1360
1621
|
})
|
|
@@ -1373,7 +1634,7 @@ It is critical that you mark todos as completed as soon as you are done with a t
|
|
|
1373
1634
|
## \`task\`
|
|
1374
1635
|
|
|
1375
1636
|
- When doing web search, prefer to use the \`task\` tool in order to reduce context usage.`;
|
|
1376
|
-
var
|
|
1637
|
+
var BUILTIN_TOOLS = [
|
|
1377
1638
|
writeTodos,
|
|
1378
1639
|
readFile,
|
|
1379
1640
|
writeFile,
|
|
@@ -1391,7 +1652,7 @@ function createDeepAgent(params = {}) {
|
|
|
1391
1652
|
throw new Error("Model not found");
|
|
1392
1653
|
}
|
|
1393
1654
|
const stateSchema = params.stateSchema ? DeepAgentState.extend(params.stateSchema.shape) : DeepAgentState;
|
|
1394
|
-
const allTools = [...
|
|
1655
|
+
const allTools = [...BUILTIN_TOOLS, ...tools];
|
|
1395
1656
|
if (subagents.length > 0) {
|
|
1396
1657
|
const toolsMap = {};
|
|
1397
1658
|
for (const tool5 of allTools) {
|
|
@@ -1442,9 +1703,9 @@ var DeepAgentGraphBuilder = class {
|
|
|
1442
1703
|
};
|
|
1443
1704
|
|
|
1444
1705
|
// src/createPlanExecuteAgent.ts
|
|
1445
|
-
var
|
|
1446
|
-
var
|
|
1447
|
-
var
|
|
1706
|
+
var import_langgraph13 = require("@langchain/langgraph");
|
|
1707
|
+
var import_messages9 = require("@langchain/core/messages");
|
|
1708
|
+
var import_zod15 = require("zod");
|
|
1448
1709
|
|
|
1449
1710
|
// src/logger/Logger.ts
|
|
1450
1711
|
var import_pino = __toESM(require("pino"));
|
|
@@ -1585,14 +1846,14 @@ var Logger = class _Logger {
|
|
|
1585
1846
|
};
|
|
1586
1847
|
|
|
1587
1848
|
// src/util/returnToolResponse.ts
|
|
1588
|
-
var
|
|
1849
|
+
var import_messages6 = require("@langchain/core/messages");
|
|
1589
1850
|
var import_uuid = require("uuid");
|
|
1590
1851
|
var returnToolResponse = (config, think) => {
|
|
1591
1852
|
const { think_id = (0, import_uuid.v4)(), content, title, status, type, data } = think;
|
|
1592
1853
|
const contents = type ? [title, content, genUIMarkdown(type, data)] : [title, content];
|
|
1593
1854
|
const message = {
|
|
1594
1855
|
messages: [
|
|
1595
|
-
new
|
|
1856
|
+
new import_messages6.ToolMessage({
|
|
1596
1857
|
content: contents.filter((item) => item).join("\n\n"),
|
|
1597
1858
|
tool_call_id: config.configurable?.run_id + "_tool_" + think_id,
|
|
1598
1859
|
status: status || "success"
|
|
@@ -1603,12 +1864,12 @@ var returnToolResponse = (config, think) => {
|
|
|
1603
1864
|
};
|
|
1604
1865
|
|
|
1605
1866
|
// src/util/returnAIResponse.ts
|
|
1606
|
-
var
|
|
1867
|
+
var import_messages7 = require("@langchain/core/messages");
|
|
1607
1868
|
var returnAIResponse = (config, content, type, data) => {
|
|
1608
1869
|
const contents = type ? [content, genUIMarkdown(type, data)].join("\n") : content;
|
|
1609
1870
|
const message = {
|
|
1610
1871
|
messages: [
|
|
1611
|
-
new
|
|
1872
|
+
new import_messages7.AIMessage({
|
|
1612
1873
|
content: contents
|
|
1613
1874
|
})
|
|
1614
1875
|
// {
|
|
@@ -1623,11 +1884,11 @@ var returnAIResponse = (config, content, type, data) => {
|
|
|
1623
1884
|
};
|
|
1624
1885
|
|
|
1625
1886
|
// src/util/getLastHumanMessageData.ts
|
|
1626
|
-
var
|
|
1887
|
+
var import_messages8 = require("@langchain/core/messages");
|
|
1627
1888
|
var getLastHumanMessageData = (messages) => {
|
|
1628
1889
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1629
1890
|
const message = messages[i];
|
|
1630
|
-
if ((0,
|
|
1891
|
+
if ((0, import_messages8.isHumanMessage)(message)) {
|
|
1631
1892
|
const files = message?.additional_kwargs?.files;
|
|
1632
1893
|
return {
|
|
1633
1894
|
files,
|
|
@@ -1639,13 +1900,13 @@ var getLastHumanMessageData = (messages) => {
|
|
|
1639
1900
|
};
|
|
1640
1901
|
|
|
1641
1902
|
// src/createPlanExecuteAgent.ts
|
|
1642
|
-
var
|
|
1903
|
+
var import_tools6 = require("@langchain/core/tools");
|
|
1643
1904
|
|
|
1644
1905
|
// src/util/PGMemory.ts
|
|
1645
|
-
var
|
|
1906
|
+
var import_langgraph12 = require("@langchain/langgraph");
|
|
1646
1907
|
var import_langgraph_checkpoint_postgres = require("@langchain/langgraph-checkpoint-postgres");
|
|
1647
1908
|
var globalMemory = import_langgraph_checkpoint_postgres.PostgresSaver.fromConnString(process.env.DATABASE_URL);
|
|
1648
|
-
var memory2 = new
|
|
1909
|
+
var memory2 = new import_langgraph12.MemorySaver();
|
|
1649
1910
|
var _MemoryManager = class _MemoryManager {
|
|
1650
1911
|
static getInstance() {
|
|
1651
1912
|
return _MemoryManager.instance;
|
|
@@ -1656,40 +1917,40 @@ var MemoryManager = _MemoryManager;
|
|
|
1656
1917
|
|
|
1657
1918
|
// src/createPlanExecuteAgent.ts
|
|
1658
1919
|
var import_prebuilt3 = require("@langchain/langgraph/prebuilt");
|
|
1659
|
-
var PlanExecuteState =
|
|
1920
|
+
var PlanExecuteState = import_langgraph13.Annotation.Root({
|
|
1660
1921
|
// 输入
|
|
1661
|
-
input: (0,
|
|
1922
|
+
input: (0, import_langgraph13.Annotation)({
|
|
1662
1923
|
reducer: (x, y) => y ?? x ?? ""
|
|
1663
1924
|
}),
|
|
1664
1925
|
// 计划步骤列表
|
|
1665
|
-
plan: (0,
|
|
1926
|
+
plan: (0, import_langgraph13.Annotation)({
|
|
1666
1927
|
reducer: (x, y) => y ?? x ?? []
|
|
1667
1928
|
}),
|
|
1668
1929
|
// 已执行的步骤 [步骤名称, 执行结果]
|
|
1669
|
-
pastSteps: (0,
|
|
1930
|
+
pastSteps: (0, import_langgraph13.Annotation)({
|
|
1670
1931
|
reducer: (x, y) => x.concat(y),
|
|
1671
1932
|
default: () => []
|
|
1672
1933
|
}),
|
|
1673
1934
|
// 最终响应
|
|
1674
|
-
response: (0,
|
|
1935
|
+
response: (0, import_langgraph13.Annotation)({
|
|
1675
1936
|
reducer: (x, y) => y ?? x
|
|
1676
1937
|
}),
|
|
1677
1938
|
// 错误信息
|
|
1678
|
-
error: (0,
|
|
1939
|
+
error: (0, import_langgraph13.Annotation)({
|
|
1679
1940
|
reducer: (x, y) => y ?? x
|
|
1680
1941
|
}),
|
|
1681
1942
|
// 继承基础状态
|
|
1682
|
-
"x-tenant-id": (0,
|
|
1683
|
-
messages: (0,
|
|
1684
|
-
reducer:
|
|
1943
|
+
"x-tenant-id": (0, import_langgraph13.Annotation)(),
|
|
1944
|
+
messages: (0, import_langgraph13.Annotation)({
|
|
1945
|
+
reducer: import_langgraph13.messagesStateReducer,
|
|
1685
1946
|
default: () => []
|
|
1686
1947
|
})
|
|
1687
1948
|
});
|
|
1688
|
-
var planSchema =
|
|
1689
|
-
steps:
|
|
1949
|
+
var planSchema = import_zod15.z.object({
|
|
1950
|
+
steps: import_zod15.z.array(import_zod15.z.string()).describe("\u9700\u8981\u6267\u884C\u7684\u6B65\u9AA4\u5217\u8868\uFF0C\u5E94\u6309\u7167\u6267\u884C\u987A\u5E8F\u6392\u5E8F")
|
|
1690
1951
|
});
|
|
1691
|
-
var responseSchema =
|
|
1692
|
-
response:
|
|
1952
|
+
var responseSchema = import_zod15.z.object({
|
|
1953
|
+
response: import_zod15.z.string().describe("\u7ED9\u7528\u6237\u7684\u6700\u7EC8\u54CD\u5E94\uFF0C\u5982\u679C\u4E0D\u9700\u8981\u6267\u884C\u6B65\u9AA4\uFF0C\u5219\u8FD4\u56DE\u8FD9\u4E2A\u5B57\u6BB5")
|
|
1693
1954
|
});
|
|
1694
1955
|
function createPlanExecuteAgent(config) {
|
|
1695
1956
|
const {
|
|
@@ -1729,7 +1990,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1729
1990
|
\u76EE\u6807: ${input}`;
|
|
1730
1991
|
try {
|
|
1731
1992
|
const planResult = await llm.invokeWithStructuredOutput(
|
|
1732
|
-
[new
|
|
1993
|
+
[new import_messages9.HumanMessage(plannerPrompt)],
|
|
1733
1994
|
planSchema
|
|
1734
1995
|
);
|
|
1735
1996
|
const { messages } = await returnToolResponse(config2, {
|
|
@@ -1770,7 +2031,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1770
2031
|
|
|
1771
2032
|
\u8BF7\u63D0\u4F9B\u6267\u884C\u6B64\u4EFB\u52A1\u7684\u8BE6\u7EC6\u7ED3\u679C\u3002`;
|
|
1772
2033
|
const executionResult = await agentExecutor.invoke({
|
|
1773
|
-
messages: [new
|
|
2034
|
+
messages: [new import_messages9.HumanMessage(executorPrompt)]
|
|
1774
2035
|
});
|
|
1775
2036
|
const resultContent = executionResult.messages[executionResult.messages.length - 1].content;
|
|
1776
2037
|
return {
|
|
@@ -1781,7 +2042,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1781
2042
|
error: void 0
|
|
1782
2043
|
};
|
|
1783
2044
|
} catch (error) {
|
|
1784
|
-
if (error instanceof
|
|
2045
|
+
if (error instanceof import_langgraph13.GraphInterrupt) {
|
|
1785
2046
|
throw error;
|
|
1786
2047
|
}
|
|
1787
2048
|
const errorMsg = `\u4EFB\u52A1\u6267\u884C\u5931\u8D25: ${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`;
|
|
@@ -1792,7 +2053,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1792
2053
|
};
|
|
1793
2054
|
}
|
|
1794
2055
|
}
|
|
1795
|
-
const responseTool = (0,
|
|
2056
|
+
const responseTool = (0, import_tools6.tool)(
|
|
1796
2057
|
({ response }) => {
|
|
1797
2058
|
return response;
|
|
1798
2059
|
},
|
|
@@ -1803,7 +2064,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1803
2064
|
returnDirect: true
|
|
1804
2065
|
}
|
|
1805
2066
|
);
|
|
1806
|
-
const planTool = (0,
|
|
2067
|
+
const planTool = (0, import_tools6.tool)(
|
|
1807
2068
|
({ steps }) => {
|
|
1808
2069
|
return steps.join("\n\n");
|
|
1809
2070
|
},
|
|
@@ -1839,7 +2100,7 @@ Otherwise, fill out the plan.
|
|
|
1839
2100
|
Only add steps to the plan that still NEED to be done. Do not return previously done steps as part of the plan.`;
|
|
1840
2101
|
try {
|
|
1841
2102
|
const responseResult = await replanAgent.invoke({
|
|
1842
|
-
messages: [new
|
|
2103
|
+
messages: [new import_messages9.HumanMessage(replannerPrompt)]
|
|
1843
2104
|
});
|
|
1844
2105
|
const toolCall = responseResult.messages[responseResult.messages.length - 1];
|
|
1845
2106
|
if (toolCall?.name == "response") {
|
|
@@ -1874,7 +2135,7 @@ Only add steps to the plan that still NEED to be done. Do not return previously
|
|
|
1874
2135
|
};
|
|
1875
2136
|
}
|
|
1876
2137
|
} catch (error) {
|
|
1877
|
-
if (error instanceof
|
|
2138
|
+
if (error instanceof import_langgraph13.GraphInterrupt) {
|
|
1878
2139
|
throw error;
|
|
1879
2140
|
}
|
|
1880
2141
|
const errorMsg = `\u91CD\u65B0\u89C4\u5212\u5931\u8D25: ${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`;
|
|
@@ -1906,8 +2167,8 @@ Only add steps to the plan that still NEED to be done. Do not return previously
|
|
|
1906
2167
|
}
|
|
1907
2168
|
return "continue";
|
|
1908
2169
|
}
|
|
1909
|
-
const workflow = new
|
|
1910
|
-
end:
|
|
2170
|
+
const workflow = new import_langgraph13.StateGraph(PlanExecuteState).addNode("planner", planStep).addNode("executor", executeStep).addNode("replanner", replanStep).addEdge(import_langgraph13.START, "planner").addEdge("planner", "executor").addEdge("executor", "replanner").addConditionalEdges("replanner", shouldEnd, {
|
|
2171
|
+
end: import_langgraph13.END,
|
|
1911
2172
|
continue: "executor"
|
|
1912
2173
|
});
|
|
1913
2174
|
const compiledGraph = workflow.compile({
|