@axiom-lattice/core 2.0.1 → 2.0.3
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.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +511 -237
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +493 -203
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ __export(index_exports, {
|
|
|
44
44
|
ThreadStatus: () => ThreadStatus,
|
|
45
45
|
ToolLatticeManager: () => ToolLatticeManager,
|
|
46
46
|
agentLatticeManager: () => agentLatticeManager,
|
|
47
|
-
getAgentClient: () =>
|
|
47
|
+
getAgentClient: () => getAgentClient2,
|
|
48
48
|
getAgentConfig: () => getAgentConfig,
|
|
49
49
|
getAgentLattice: () => getAgentLattice,
|
|
50
50
|
getAllAgentConfigs: () => getAllAgentConfigs,
|
|
@@ -627,7 +627,7 @@ registerToolLattice(
|
|
|
627
627
|
{
|
|
628
628
|
name: "internet_search",
|
|
629
629
|
description: "Run a web search",
|
|
630
|
-
needUserApprove:
|
|
630
|
+
needUserApprove: false,
|
|
631
631
|
schema: import_zod2.default.object({
|
|
632
632
|
query: import_zod2.default.string().describe("The search query"),
|
|
633
633
|
maxResults: import_zod2.default.number().optional().default(5).describe("Maximum number of results to return"),
|
|
@@ -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,20 +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_prebuilt2 = require("@langchain/langgraph/prebuilt");
|
|
787
|
-
var import_zod6 = require("zod");
|
|
788
|
-
|
|
789
|
-
// src/deep_agent/tools.ts
|
|
790
1036
|
var import_tools2 = require("@langchain/core/tools");
|
|
791
|
-
var
|
|
792
|
-
var
|
|
793
|
-
var
|
|
1037
|
+
var import_messages4 = require("@langchain/core/messages");
|
|
1038
|
+
var import_langgraph9 = require("@langchain/langgraph");
|
|
1039
|
+
var import_zod10 = require("zod");
|
|
794
1040
|
|
|
795
1041
|
// src/deep_agent/prompts.ts
|
|
796
|
-
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.
|
|
797
1043
|
|
|
798
1044
|
When to Use This Tool
|
|
799
1045
|
Use this tool proactively in these scenarios:
|
|
@@ -1047,14 +1293,140 @@ Results are returned using cat -n format, with line numbers starting at 1
|
|
|
1047
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.
|
|
1048
1294
|
If you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.`;
|
|
1049
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
|
+
|
|
1050
1418
|
// src/deep_agent/tools.ts
|
|
1051
|
-
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)(
|
|
1052
1424
|
(input, config) => {
|
|
1053
|
-
return new
|
|
1425
|
+
return new import_langgraph10.Command({
|
|
1054
1426
|
update: {
|
|
1055
1427
|
todos: input.todos,
|
|
1056
1428
|
messages: [
|
|
1057
|
-
new
|
|
1429
|
+
new import_messages5.ToolMessage({
|
|
1058
1430
|
content: genUIMarkdown("todo_list", input.todos),
|
|
1059
1431
|
tool_call_id: config.toolCall?.id
|
|
1060
1432
|
})
|
|
@@ -1064,32 +1436,32 @@ var writeTodos = (0, import_tools2.tool)(
|
|
|
1064
1436
|
},
|
|
1065
1437
|
{
|
|
1066
1438
|
name: "write_todos",
|
|
1067
|
-
description:
|
|
1068
|
-
schema:
|
|
1069
|
-
todos:
|
|
1070
|
-
|
|
1071
|
-
content:
|
|
1072
|
-
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")
|
|
1073
1445
|
})
|
|
1074
1446
|
).describe("List of todo items to update")
|
|
1075
1447
|
})
|
|
1076
1448
|
}
|
|
1077
1449
|
);
|
|
1078
|
-
var ls = (0,
|
|
1450
|
+
var ls = (0, import_tools3.tool)(
|
|
1079
1451
|
() => {
|
|
1080
|
-
const state = (0,
|
|
1452
|
+
const state = (0, import_langgraph10.getCurrentTaskInput)();
|
|
1081
1453
|
const files = state.files || {};
|
|
1082
1454
|
return Object.keys(files);
|
|
1083
1455
|
},
|
|
1084
1456
|
{
|
|
1085
1457
|
name: "ls",
|
|
1086
1458
|
description: "List all files in the mock filesystem",
|
|
1087
|
-
schema:
|
|
1459
|
+
schema: import_zod11.z.object({})
|
|
1088
1460
|
}
|
|
1089
1461
|
);
|
|
1090
|
-
var readFile = (0,
|
|
1462
|
+
var readFile = (0, import_tools3.tool)(
|
|
1091
1463
|
(input) => {
|
|
1092
|
-
const state = (0,
|
|
1464
|
+
const state = (0, import_langgraph10.getCurrentTaskInput)();
|
|
1093
1465
|
const mockFilesystem = state.files || {};
|
|
1094
1466
|
const { file_path, offset = 0, limit = 2e3 } = input;
|
|
1095
1467
|
if (!(file_path in mockFilesystem)) {
|
|
@@ -1119,23 +1491,23 @@ var readFile = (0, import_tools2.tool)(
|
|
|
1119
1491
|
{
|
|
1120
1492
|
name: "read_file",
|
|
1121
1493
|
description: TOOL_DESCRIPTION,
|
|
1122
|
-
schema:
|
|
1123
|
-
file_path:
|
|
1124
|
-
offset:
|
|
1125
|
-
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")
|
|
1126
1498
|
})
|
|
1127
1499
|
}
|
|
1128
1500
|
);
|
|
1129
|
-
var writeFile = (0,
|
|
1501
|
+
var writeFile = (0, import_tools3.tool)(
|
|
1130
1502
|
(input, config) => {
|
|
1131
|
-
const state = (0,
|
|
1503
|
+
const state = (0, import_langgraph10.getCurrentTaskInput)();
|
|
1132
1504
|
const files = { ...state.files || {} };
|
|
1133
1505
|
files[input.file_path] = input.content;
|
|
1134
|
-
return new
|
|
1506
|
+
return new import_langgraph10.Command({
|
|
1135
1507
|
update: {
|
|
1136
1508
|
files,
|
|
1137
1509
|
messages: [
|
|
1138
|
-
new
|
|
1510
|
+
new import_messages5.ToolMessage({
|
|
1139
1511
|
content: `Updated file ${input.file_path}`,
|
|
1140
1512
|
tool_call_id: config.toolCall?.id
|
|
1141
1513
|
})
|
|
@@ -1146,15 +1518,15 @@ var writeFile = (0, import_tools2.tool)(
|
|
|
1146
1518
|
{
|
|
1147
1519
|
name: "write_file",
|
|
1148
1520
|
description: "Write content to a file in the mock filesystem",
|
|
1149
|
-
schema:
|
|
1150
|
-
file_path:
|
|
1151
|
-
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")
|
|
1152
1524
|
})
|
|
1153
1525
|
}
|
|
1154
1526
|
);
|
|
1155
|
-
var editFile = (0,
|
|
1527
|
+
var editFile = (0, import_tools3.tool)(
|
|
1156
1528
|
(input, config) => {
|
|
1157
|
-
const state = (0,
|
|
1529
|
+
const state = (0, import_langgraph10.getCurrentTaskInput)();
|
|
1158
1530
|
const mockFilesystem = { ...state.files || {} };
|
|
1159
1531
|
const { file_path, old_string, new_string, replace_all = false } = input;
|
|
1160
1532
|
if (!(file_path in mockFilesystem)) {
|
|
@@ -1190,11 +1562,11 @@ var editFile = (0, import_tools2.tool)(
|
|
|
1190
1562
|
newContent = content.replace(old_string, new_string);
|
|
1191
1563
|
}
|
|
1192
1564
|
mockFilesystem[file_path] = newContent;
|
|
1193
|
-
return new
|
|
1565
|
+
return new import_langgraph10.Command({
|
|
1194
1566
|
update: {
|
|
1195
1567
|
files: mockFilesystem,
|
|
1196
1568
|
messages: [
|
|
1197
|
-
new
|
|
1569
|
+
new import_messages5.ToolMessage({
|
|
1198
1570
|
content: `Updated file ${file_path}`,
|
|
1199
1571
|
tool_call_id: config.toolCall?.id
|
|
1200
1572
|
})
|
|
@@ -1205,133 +1577,20 @@ var editFile = (0, import_tools2.tool)(
|
|
|
1205
1577
|
{
|
|
1206
1578
|
name: "edit_file",
|
|
1207
1579
|
description: EDIT_DESCRIPTION,
|
|
1208
|
-
schema:
|
|
1209
|
-
file_path:
|
|
1210
|
-
old_string:
|
|
1211
|
-
new_string:
|
|
1212
|
-
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")
|
|
1213
1585
|
})
|
|
1214
1586
|
}
|
|
1215
1587
|
);
|
|
1216
1588
|
|
|
1217
|
-
// src/deep_agent/subAgent.ts
|
|
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
|
-
const subagentTools = [];
|
|
1240
|
-
if (subagent.tools) {
|
|
1241
|
-
for (const toolName of subagent.tools) {
|
|
1242
|
-
const resolvedTool = allTools[toolName];
|
|
1243
|
-
if (resolvedTool) {
|
|
1244
|
-
subagentTools.push(resolvedTool);
|
|
1245
|
-
} else {
|
|
1246
|
-
console.warn(
|
|
1247
|
-
`Warning: Tool '${toolName}' not found for agent '${subagent.name}'`
|
|
1248
|
-
);
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
} else {
|
|
1252
|
-
subagentTools.push(...Object.values(allTools));
|
|
1253
|
-
}
|
|
1254
|
-
const reactAgent = (0, import_prebuilt2.createReactAgent)({
|
|
1255
|
-
llm: model,
|
|
1256
|
-
tools: subagentTools,
|
|
1257
|
-
stateSchema,
|
|
1258
|
-
messageModifier: subagent.prompt,
|
|
1259
|
-
// checkpointer: false,
|
|
1260
|
-
checkpointer: getCheckpointSaver("default"),
|
|
1261
|
-
postModelHook
|
|
1262
|
-
});
|
|
1263
|
-
agentsMap.set(subagent.name, reactAgent);
|
|
1264
|
-
}
|
|
1265
|
-
return (0, import_tools3.tool)(
|
|
1266
|
-
async (input, config) => {
|
|
1267
|
-
const { description, subagent_type } = input;
|
|
1268
|
-
const reactAgent = agentsMap.get(subagent_type);
|
|
1269
|
-
if (!reactAgent) {
|
|
1270
|
-
return `Error: Agent '${subagent_type}' not found. Available agents: ${Array.from(
|
|
1271
|
-
agentsMap.keys()
|
|
1272
|
-
).join(", ")}`;
|
|
1273
|
-
}
|
|
1274
|
-
try {
|
|
1275
|
-
const currentState = (0, import_langgraph5.getCurrentTaskInput)();
|
|
1276
|
-
const modifiedState = {
|
|
1277
|
-
...currentState,
|
|
1278
|
-
messages: [
|
|
1279
|
-
{
|
|
1280
|
-
role: "user",
|
|
1281
|
-
content: description
|
|
1282
|
-
}
|
|
1283
|
-
]
|
|
1284
|
-
};
|
|
1285
|
-
const result = await reactAgent.invoke(modifiedState, config);
|
|
1286
|
-
return new import_langgraph5.Command({
|
|
1287
|
-
update: {
|
|
1288
|
-
files: result.files || {},
|
|
1289
|
-
messages: [
|
|
1290
|
-
new import_messages2.ToolMessage({
|
|
1291
|
-
content: result.messages?.slice(-1)[0]?.content || "Task completed",
|
|
1292
|
-
tool_call_id: config.toolCall?.id
|
|
1293
|
-
})
|
|
1294
|
-
]
|
|
1295
|
-
}
|
|
1296
|
-
});
|
|
1297
|
-
} catch (error) {
|
|
1298
|
-
if (error instanceof import_langgraph5.GraphInterrupt) {
|
|
1299
|
-
throw error;
|
|
1300
|
-
}
|
|
1301
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1302
|
-
return new import_langgraph5.Command({
|
|
1303
|
-
update: {
|
|
1304
|
-
messages: [
|
|
1305
|
-
new import_messages2.ToolMessage({
|
|
1306
|
-
content: `Error executing task '${description}' with agent '${subagent_type}': ${errorMessage}`,
|
|
1307
|
-
tool_call_id: config.toolCall?.id
|
|
1308
|
-
})
|
|
1309
|
-
]
|
|
1310
|
-
}
|
|
1311
|
-
});
|
|
1312
|
-
}
|
|
1313
|
-
},
|
|
1314
|
-
{
|
|
1315
|
-
name: "task",
|
|
1316
|
-
description: TASK_DESCRIPTION_PREFIX.replace(
|
|
1317
|
-
"{other_agents}",
|
|
1318
|
-
subagents.map((a) => `- ${a.name}: ${a.description}`).join("\n")
|
|
1319
|
-
) + TASK_DESCRIPTION_SUFFIX,
|
|
1320
|
-
schema: import_zod6.z.object({
|
|
1321
|
-
description: import_zod6.z.string().describe("The task to execute with the selected agent"),
|
|
1322
|
-
subagent_type: import_zod6.z.string().describe(
|
|
1323
|
-
`Name of the agent to use. Available: ${subagents.map((a) => a.name).join(", ")}`
|
|
1324
|
-
)
|
|
1325
|
-
})
|
|
1326
|
-
}
|
|
1327
|
-
);
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
1589
|
// src/deep_agent/state.ts
|
|
1331
|
-
var
|
|
1332
|
-
var
|
|
1333
|
-
var
|
|
1334
|
-
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");
|
|
1335
1594
|
function fileReducer(left, right) {
|
|
1336
1595
|
if (left == null) {
|
|
1337
1596
|
return right || {};
|
|
@@ -1347,23 +1606,23 @@ function todoReducer(left, right) {
|
|
|
1347
1606
|
}
|
|
1348
1607
|
return left || [];
|
|
1349
1608
|
}
|
|
1350
|
-
var DeepAgentState =
|
|
1351
|
-
todos: (0,
|
|
1609
|
+
var DeepAgentState = import_langgraph11.MessagesZodState.extend({
|
|
1610
|
+
todos: (0, import_zod13.withLangGraph)(import_zod14.z.custom(), {
|
|
1352
1611
|
reducer: {
|
|
1353
|
-
schema:
|
|
1612
|
+
schema: import_zod14.z.custom(),
|
|
1354
1613
|
fn: todoReducer
|
|
1355
1614
|
}
|
|
1356
1615
|
}),
|
|
1357
|
-
files: (0,
|
|
1616
|
+
files: (0, import_zod13.withLangGraph)(import_zod14.z.custom(), {
|
|
1358
1617
|
reducer: {
|
|
1359
|
-
schema:
|
|
1618
|
+
schema: import_zod14.z.custom(),
|
|
1360
1619
|
fn: fileReducer
|
|
1361
1620
|
}
|
|
1362
1621
|
})
|
|
1363
1622
|
});
|
|
1364
1623
|
|
|
1365
1624
|
// src/deep_agent/graph.ts
|
|
1366
|
-
var
|
|
1625
|
+
var import_prebuilt2 = require("@langchain/langgraph/prebuilt");
|
|
1367
1626
|
var BASE_PROMPT = `You have access to a number of standard tools
|
|
1368
1627
|
|
|
1369
1628
|
## \`write_todos\`
|
|
@@ -1375,7 +1634,7 @@ It is critical that you mark todos as completed as soon as you are done with a t
|
|
|
1375
1634
|
## \`task\`
|
|
1376
1635
|
|
|
1377
1636
|
- When doing web search, prefer to use the \`task\` tool in order to reduce context usage.`;
|
|
1378
|
-
var
|
|
1637
|
+
var BUILTIN_TOOLS = [
|
|
1379
1638
|
writeTodos,
|
|
1380
1639
|
readFile,
|
|
1381
1640
|
writeFile,
|
|
@@ -1393,7 +1652,7 @@ function createDeepAgent(params = {}) {
|
|
|
1393
1652
|
throw new Error("Model not found");
|
|
1394
1653
|
}
|
|
1395
1654
|
const stateSchema = params.stateSchema ? DeepAgentState.extend(params.stateSchema.shape) : DeepAgentState;
|
|
1396
|
-
const allTools = [...
|
|
1655
|
+
const allTools = [...BUILTIN_TOOLS, ...tools];
|
|
1397
1656
|
if (subagents.length > 0) {
|
|
1398
1657
|
const toolsMap = {};
|
|
1399
1658
|
for (const tool5 of allTools) {
|
|
@@ -1410,7 +1669,7 @@ function createDeepAgent(params = {}) {
|
|
|
1410
1669
|
allTools.push(taskTool);
|
|
1411
1670
|
}
|
|
1412
1671
|
const finalInstructions = instructions ? instructions + BASE_PROMPT : BASE_PROMPT;
|
|
1413
|
-
return (0,
|
|
1672
|
+
return (0, import_prebuilt2.createReactAgent)({
|
|
1414
1673
|
llm: model,
|
|
1415
1674
|
tools: allTools,
|
|
1416
1675
|
stateSchema,
|
|
@@ -1438,20 +1697,15 @@ var DeepAgentGraphBuilder = class {
|
|
|
1438
1697
|
model: params.model,
|
|
1439
1698
|
stateSchema: params.stateSchema,
|
|
1440
1699
|
instructions: params.prompt,
|
|
1441
|
-
subagents: params.subAgents.map((sa) =>
|
|
1442
|
-
name: sa.key,
|
|
1443
|
-
description: sa.config.description,
|
|
1444
|
-
prompt: sa.config.prompt,
|
|
1445
|
-
tools: sa.config.tools
|
|
1446
|
-
}))
|
|
1700
|
+
subagents: params.subAgents.map((sa) => sa.config)
|
|
1447
1701
|
});
|
|
1448
1702
|
}
|
|
1449
1703
|
};
|
|
1450
1704
|
|
|
1451
1705
|
// src/createPlanExecuteAgent.ts
|
|
1452
|
-
var
|
|
1453
|
-
var
|
|
1454
|
-
var
|
|
1706
|
+
var import_langgraph13 = require("@langchain/langgraph");
|
|
1707
|
+
var import_messages9 = require("@langchain/core/messages");
|
|
1708
|
+
var import_zod15 = require("zod");
|
|
1455
1709
|
|
|
1456
1710
|
// src/logger/Logger.ts
|
|
1457
1711
|
var import_pino = __toESM(require("pino"));
|
|
@@ -1592,14 +1846,14 @@ var Logger = class _Logger {
|
|
|
1592
1846
|
};
|
|
1593
1847
|
|
|
1594
1848
|
// src/util/returnToolResponse.ts
|
|
1595
|
-
var
|
|
1849
|
+
var import_messages6 = require("@langchain/core/messages");
|
|
1596
1850
|
var import_uuid = require("uuid");
|
|
1597
1851
|
var returnToolResponse = (config, think) => {
|
|
1598
1852
|
const { think_id = (0, import_uuid.v4)(), content, title, status, type, data } = think;
|
|
1599
1853
|
const contents = type ? [title, content, genUIMarkdown(type, data)] : [title, content];
|
|
1600
1854
|
const message = {
|
|
1601
1855
|
messages: [
|
|
1602
|
-
new
|
|
1856
|
+
new import_messages6.ToolMessage({
|
|
1603
1857
|
content: contents.filter((item) => item).join("\n\n"),
|
|
1604
1858
|
tool_call_id: config.configurable?.run_id + "_tool_" + think_id,
|
|
1605
1859
|
status: status || "success"
|
|
@@ -1610,12 +1864,12 @@ var returnToolResponse = (config, think) => {
|
|
|
1610
1864
|
};
|
|
1611
1865
|
|
|
1612
1866
|
// src/util/returnAIResponse.ts
|
|
1613
|
-
var
|
|
1867
|
+
var import_messages7 = require("@langchain/core/messages");
|
|
1614
1868
|
var returnAIResponse = (config, content, type, data) => {
|
|
1615
1869
|
const contents = type ? [content, genUIMarkdown(type, data)].join("\n") : content;
|
|
1616
1870
|
const message = {
|
|
1617
1871
|
messages: [
|
|
1618
|
-
new
|
|
1872
|
+
new import_messages7.AIMessage({
|
|
1619
1873
|
content: contents
|
|
1620
1874
|
})
|
|
1621
1875
|
// {
|
|
@@ -1630,11 +1884,11 @@ var returnAIResponse = (config, content, type, data) => {
|
|
|
1630
1884
|
};
|
|
1631
1885
|
|
|
1632
1886
|
// src/util/getLastHumanMessageData.ts
|
|
1633
|
-
var
|
|
1887
|
+
var import_messages8 = require("@langchain/core/messages");
|
|
1634
1888
|
var getLastHumanMessageData = (messages) => {
|
|
1635
1889
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1636
1890
|
const message = messages[i];
|
|
1637
|
-
if ((0,
|
|
1891
|
+
if ((0, import_messages8.isHumanMessage)(message)) {
|
|
1638
1892
|
const files = message?.additional_kwargs?.files;
|
|
1639
1893
|
return {
|
|
1640
1894
|
files,
|
|
@@ -1646,13 +1900,13 @@ var getLastHumanMessageData = (messages) => {
|
|
|
1646
1900
|
};
|
|
1647
1901
|
|
|
1648
1902
|
// src/createPlanExecuteAgent.ts
|
|
1649
|
-
var
|
|
1903
|
+
var import_tools6 = require("@langchain/core/tools");
|
|
1650
1904
|
|
|
1651
1905
|
// src/util/PGMemory.ts
|
|
1652
|
-
var
|
|
1906
|
+
var import_langgraph12 = require("@langchain/langgraph");
|
|
1653
1907
|
var import_langgraph_checkpoint_postgres = require("@langchain/langgraph-checkpoint-postgres");
|
|
1654
1908
|
var globalMemory = import_langgraph_checkpoint_postgres.PostgresSaver.fromConnString(process.env.DATABASE_URL);
|
|
1655
|
-
var memory2 = new
|
|
1909
|
+
var memory2 = new import_langgraph12.MemorySaver();
|
|
1656
1910
|
var _MemoryManager = class _MemoryManager {
|
|
1657
1911
|
static getInstance() {
|
|
1658
1912
|
return _MemoryManager.instance;
|
|
@@ -1662,41 +1916,41 @@ _MemoryManager.instance = memory2;
|
|
|
1662
1916
|
var MemoryManager = _MemoryManager;
|
|
1663
1917
|
|
|
1664
1918
|
// src/createPlanExecuteAgent.ts
|
|
1665
|
-
var
|
|
1666
|
-
var PlanExecuteState =
|
|
1919
|
+
var import_prebuilt3 = require("@langchain/langgraph/prebuilt");
|
|
1920
|
+
var PlanExecuteState = import_langgraph13.Annotation.Root({
|
|
1667
1921
|
// 输入
|
|
1668
|
-
input: (0,
|
|
1922
|
+
input: (0, import_langgraph13.Annotation)({
|
|
1669
1923
|
reducer: (x, y) => y ?? x ?? ""
|
|
1670
1924
|
}),
|
|
1671
1925
|
// 计划步骤列表
|
|
1672
|
-
plan: (0,
|
|
1926
|
+
plan: (0, import_langgraph13.Annotation)({
|
|
1673
1927
|
reducer: (x, y) => y ?? x ?? []
|
|
1674
1928
|
}),
|
|
1675
1929
|
// 已执行的步骤 [步骤名称, 执行结果]
|
|
1676
|
-
pastSteps: (0,
|
|
1930
|
+
pastSteps: (0, import_langgraph13.Annotation)({
|
|
1677
1931
|
reducer: (x, y) => x.concat(y),
|
|
1678
1932
|
default: () => []
|
|
1679
1933
|
}),
|
|
1680
1934
|
// 最终响应
|
|
1681
|
-
response: (0,
|
|
1935
|
+
response: (0, import_langgraph13.Annotation)({
|
|
1682
1936
|
reducer: (x, y) => y ?? x
|
|
1683
1937
|
}),
|
|
1684
1938
|
// 错误信息
|
|
1685
|
-
error: (0,
|
|
1939
|
+
error: (0, import_langgraph13.Annotation)({
|
|
1686
1940
|
reducer: (x, y) => y ?? x
|
|
1687
1941
|
}),
|
|
1688
1942
|
// 继承基础状态
|
|
1689
|
-
"x-tenant-id": (0,
|
|
1690
|
-
messages: (0,
|
|
1691
|
-
reducer:
|
|
1943
|
+
"x-tenant-id": (0, import_langgraph13.Annotation)(),
|
|
1944
|
+
messages: (0, import_langgraph13.Annotation)({
|
|
1945
|
+
reducer: import_langgraph13.messagesStateReducer,
|
|
1692
1946
|
default: () => []
|
|
1693
1947
|
})
|
|
1694
1948
|
});
|
|
1695
|
-
var planSchema =
|
|
1696
|
-
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")
|
|
1697
1951
|
});
|
|
1698
|
-
var responseSchema =
|
|
1699
|
-
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")
|
|
1700
1954
|
});
|
|
1701
1955
|
function createPlanExecuteAgent(config) {
|
|
1702
1956
|
const {
|
|
@@ -1719,7 +1973,7 @@ function createPlanExecuteAgent(config) {
|
|
|
1719
1973
|
maxSteps,
|
|
1720
1974
|
toolsCount: executorTools.length
|
|
1721
1975
|
});
|
|
1722
|
-
const agentExecutor = (0,
|
|
1976
|
+
const agentExecutor = (0, import_prebuilt3.createReactAgent)({
|
|
1723
1977
|
tools: executorTools,
|
|
1724
1978
|
llm
|
|
1725
1979
|
});
|
|
@@ -1736,7 +1990,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1736
1990
|
\u76EE\u6807: ${input}`;
|
|
1737
1991
|
try {
|
|
1738
1992
|
const planResult = await llm.invokeWithStructuredOutput(
|
|
1739
|
-
[new
|
|
1993
|
+
[new import_messages9.HumanMessage(plannerPrompt)],
|
|
1740
1994
|
planSchema
|
|
1741
1995
|
);
|
|
1742
1996
|
const { messages } = await returnToolResponse(config2, {
|
|
@@ -1777,7 +2031,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1777
2031
|
|
|
1778
2032
|
\u8BF7\u63D0\u4F9B\u6267\u884C\u6B64\u4EFB\u52A1\u7684\u8BE6\u7EC6\u7ED3\u679C\u3002`;
|
|
1779
2033
|
const executionResult = await agentExecutor.invoke({
|
|
1780
|
-
messages: [new
|
|
2034
|
+
messages: [new import_messages9.HumanMessage(executorPrompt)]
|
|
1781
2035
|
});
|
|
1782
2036
|
const resultContent = executionResult.messages[executionResult.messages.length - 1].content;
|
|
1783
2037
|
return {
|
|
@@ -1788,7 +2042,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1788
2042
|
error: void 0
|
|
1789
2043
|
};
|
|
1790
2044
|
} catch (error) {
|
|
1791
|
-
if (error instanceof
|
|
2045
|
+
if (error instanceof import_langgraph13.GraphInterrupt) {
|
|
1792
2046
|
throw error;
|
|
1793
2047
|
}
|
|
1794
2048
|
const errorMsg = `\u4EFB\u52A1\u6267\u884C\u5931\u8D25: ${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`;
|
|
@@ -1799,7 +2053,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1799
2053
|
};
|
|
1800
2054
|
}
|
|
1801
2055
|
}
|
|
1802
|
-
const responseTool = (0,
|
|
2056
|
+
const responseTool = (0, import_tools6.tool)(
|
|
1803
2057
|
({ response }) => {
|
|
1804
2058
|
return response;
|
|
1805
2059
|
},
|
|
@@ -1810,7 +2064,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1810
2064
|
returnDirect: true
|
|
1811
2065
|
}
|
|
1812
2066
|
);
|
|
1813
|
-
const planTool = (0,
|
|
2067
|
+
const planTool = (0, import_tools6.tool)(
|
|
1814
2068
|
({ steps }) => {
|
|
1815
2069
|
return steps.join("\n\n");
|
|
1816
2070
|
},
|
|
@@ -1821,7 +2075,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1821
2075
|
returnDirect: true
|
|
1822
2076
|
}
|
|
1823
2077
|
);
|
|
1824
|
-
const replanAgent = (0,
|
|
2078
|
+
const replanAgent = (0, import_prebuilt3.createReactAgent)({
|
|
1825
2079
|
tools: [responseTool, planTool],
|
|
1826
2080
|
llm
|
|
1827
2081
|
});
|
|
@@ -1846,7 +2100,7 @@ Otherwise, fill out the plan.
|
|
|
1846
2100
|
Only add steps to the plan that still NEED to be done. Do not return previously done steps as part of the plan.`;
|
|
1847
2101
|
try {
|
|
1848
2102
|
const responseResult = await replanAgent.invoke({
|
|
1849
|
-
messages: [new
|
|
2103
|
+
messages: [new import_messages9.HumanMessage(replannerPrompt)]
|
|
1850
2104
|
});
|
|
1851
2105
|
const toolCall = responseResult.messages[responseResult.messages.length - 1];
|
|
1852
2106
|
if (toolCall?.name == "response") {
|
|
@@ -1881,7 +2135,7 @@ Only add steps to the plan that still NEED to be done. Do not return previously
|
|
|
1881
2135
|
};
|
|
1882
2136
|
}
|
|
1883
2137
|
} catch (error) {
|
|
1884
|
-
if (error instanceof
|
|
2138
|
+
if (error instanceof import_langgraph13.GraphInterrupt) {
|
|
1885
2139
|
throw error;
|
|
1886
2140
|
}
|
|
1887
2141
|
const errorMsg = `\u91CD\u65B0\u89C4\u5212\u5931\u8D25: ${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`;
|
|
@@ -1913,8 +2167,8 @@ Only add steps to the plan that still NEED to be done. Do not return previously
|
|
|
1913
2167
|
}
|
|
1914
2168
|
return "continue";
|
|
1915
2169
|
}
|
|
1916
|
-
const workflow = new
|
|
1917
|
-
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,
|
|
1918
2172
|
continue: "executor"
|
|
1919
2173
|
});
|
|
1920
2174
|
const compiledGraph = workflow.compile({
|
|
@@ -2044,6 +2298,7 @@ var AgentGraphBuilderFactory = class _AgentGraphBuilderFactory {
|
|
|
2044
2298
|
};
|
|
2045
2299
|
|
|
2046
2300
|
// src/agent_lattice/builders/AgentParamsBuilder.ts
|
|
2301
|
+
var import_protocols4 = require("@axiom-lattice/protocols");
|
|
2047
2302
|
var AgentParamsBuilder = class {
|
|
2048
2303
|
/**
|
|
2049
2304
|
* constructor
|
|
@@ -2061,7 +2316,7 @@ var AgentParamsBuilder = class {
|
|
|
2061
2316
|
* @returns Agent build parameters
|
|
2062
2317
|
*/
|
|
2063
2318
|
buildParams(agentLattice, options) {
|
|
2064
|
-
const toolKeys = options?.overrideTools || agentLattice.config
|
|
2319
|
+
const toolKeys = options?.overrideTools || (0, import_protocols4.getToolsFromConfig)(agentLattice.config);
|
|
2065
2320
|
const tools = toolKeys.map((toolKey) => {
|
|
2066
2321
|
const toolLattice = toolLatticeManager.getToolLattice(toolKey);
|
|
2067
2322
|
if (!toolLattice) {
|
|
@@ -2078,7 +2333,7 @@ var AgentParamsBuilder = class {
|
|
|
2078
2333
|
if (!model) {
|
|
2079
2334
|
throw new Error(`Model "${modelKey}" does not exist`);
|
|
2080
2335
|
}
|
|
2081
|
-
const subAgentKeys = agentLattice.config
|
|
2336
|
+
const subAgentKeys = (0, import_protocols4.getSubAgentsFromConfig)(agentLattice.config);
|
|
2082
2337
|
const subAgents = subAgentKeys.map((agentKey) => {
|
|
2083
2338
|
const subAgentLattice = this.getAgentLatticeFunc(agentKey);
|
|
2084
2339
|
if (!subAgentLattice) {
|
|
@@ -2090,10 +2345,17 @@ var AgentParamsBuilder = class {
|
|
|
2090
2345
|
client: subAgentLattice.client
|
|
2091
2346
|
};
|
|
2092
2347
|
});
|
|
2348
|
+
let internalSubAgents = [];
|
|
2349
|
+
if ((0, import_protocols4.isDeepAgentConfig)(agentLattice.config)) {
|
|
2350
|
+
internalSubAgents = agentLattice.config.internalSubAgents?.map((i) => ({
|
|
2351
|
+
key: i.key,
|
|
2352
|
+
config: i
|
|
2353
|
+
})) || [];
|
|
2354
|
+
}
|
|
2093
2355
|
return {
|
|
2094
2356
|
tools,
|
|
2095
2357
|
model,
|
|
2096
|
-
subAgents,
|
|
2358
|
+
subAgents: [...subAgents, ...internalSubAgents],
|
|
2097
2359
|
prompt: agentLattice.config.prompt,
|
|
2098
2360
|
stateSchema: agentLattice.config.schema
|
|
2099
2361
|
};
|
|
@@ -2196,11 +2458,25 @@ var AgentLatticeManager = class _AgentLatticeManager extends BaseLatticeManager
|
|
|
2196
2458
|
* @returns 返回Agent构建参数
|
|
2197
2459
|
*/
|
|
2198
2460
|
buildAgentParams(agentLattice, options) {
|
|
2199
|
-
const paramsBuilder = new AgentParamsBuilder(
|
|
2200
|
-
|
|
2201
|
-
|
|
2461
|
+
const paramsBuilder = new AgentParamsBuilder((key) => {
|
|
2462
|
+
this.initializeClient(key);
|
|
2463
|
+
return this.getAgentLattice(key);
|
|
2464
|
+
});
|
|
2202
2465
|
return paramsBuilder.buildParams(agentLattice, options);
|
|
2203
2466
|
}
|
|
2467
|
+
/**
|
|
2468
|
+
* Create an AgentClient from AgentLattice config
|
|
2469
|
+
*
|
|
2470
|
+
* @param agentLattice Agent Lattice object
|
|
2471
|
+
* @param options Build options
|
|
2472
|
+
* @returns AgentClient instance
|
|
2473
|
+
*/
|
|
2474
|
+
createAgentClientFromConfig(agentLattice, options) {
|
|
2475
|
+
const factory = AgentGraphBuilderFactory.getInstance();
|
|
2476
|
+
const builder = factory.getBuilder(agentLattice.config.type);
|
|
2477
|
+
const params = this.buildAgentParams(agentLattice, options);
|
|
2478
|
+
return builder.build(agentLattice, params);
|
|
2479
|
+
}
|
|
2204
2480
|
/**
|
|
2205
2481
|
* 初始化Agent客户端
|
|
2206
2482
|
*
|
|
@@ -2218,10 +2494,7 @@ var AgentLatticeManager = class _AgentLatticeManager extends BaseLatticeManager
|
|
|
2218
2494
|
if (agentLattice.client) {
|
|
2219
2495
|
return agentLattice.client;
|
|
2220
2496
|
}
|
|
2221
|
-
const
|
|
2222
|
-
const builder = factory.getBuilder(agentLattice.config.type);
|
|
2223
|
-
const params = this.buildAgentParams(agentLattice, options);
|
|
2224
|
-
const graph = builder.build(agentLattice, params);
|
|
2497
|
+
const graph = this.createAgentClientFromConfig(agentLattice, options);
|
|
2225
2498
|
agentLattice.client = graph;
|
|
2226
2499
|
return graph;
|
|
2227
2500
|
}
|
|
@@ -2239,7 +2512,8 @@ var getAgentLattice = (key) => agentLatticeManager.getAgentLattice(key);
|
|
|
2239
2512
|
var getAgentConfig = (key) => agentLatticeManager.getAgentConfig(key);
|
|
2240
2513
|
var getAllAgentConfigs = () => agentLatticeManager.getAllAgentConfigs();
|
|
2241
2514
|
var validateAgentInput = (key, input) => agentLatticeManager.validateAgentInput(key, input);
|
|
2242
|
-
var
|
|
2515
|
+
var getAgentClient2 = (key, options) => agentLatticeManager.initializeClient(key, options);
|
|
2516
|
+
var createAgentClientFromAgentLattice = (agentLattice, options) => agentLatticeManager.createAgentClientFromConfig(agentLattice, options);
|
|
2243
2517
|
|
|
2244
2518
|
// src/chunk_buffer_lattice/ChunkBuffer.ts
|
|
2245
2519
|
var ChunkBuffer = class {
|