@axiom-lattice/core 1.0.27 → 1.0.30
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 +84 -68
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -689,6 +689,19 @@ var registerCheckpointSaver = (key, saver) => MemoryLatticeManager.getInstance()
|
|
|
689
689
|
var memory = new import_langgraph.MemorySaver();
|
|
690
690
|
registerCheckpointSaver("default", memory);
|
|
691
691
|
|
|
692
|
+
// src/agent_lattice/builders/state.ts
|
|
693
|
+
var import_zod3 = require("@langchain/langgraph/zod");
|
|
694
|
+
var import_langgraph2 = require("@langchain/langgraph");
|
|
695
|
+
var import_zod4 = require("zod");
|
|
696
|
+
var ReActAgentState = import_langgraph2.MessagesZodState.extend({
|
|
697
|
+
files: import_zod4.z.object({
|
|
698
|
+
final_output: import_zod4.z.record(import_zod4.z.any())
|
|
699
|
+
})
|
|
700
|
+
});
|
|
701
|
+
var createReactAgentSchema = (schema) => {
|
|
702
|
+
return schema ? import_langgraph2.MessagesZodState.extend(schema.shape) : void 0;
|
|
703
|
+
};
|
|
704
|
+
|
|
692
705
|
// src/agent_lattice/builders/ReActAgentGraphBuilder.ts
|
|
693
706
|
var ReActAgentGraphBuilder = class {
|
|
694
707
|
/**
|
|
@@ -703,12 +716,14 @@ var ReActAgentGraphBuilder = class {
|
|
|
703
716
|
const tool5 = getToolClient(t.key);
|
|
704
717
|
return tool5;
|
|
705
718
|
}).filter((tool5) => tool5 !== void 0);
|
|
719
|
+
const stateSchema = createReactAgentSchema(params.stateSchema);
|
|
706
720
|
return (0, import_prebuilt.createReactAgent)({
|
|
707
721
|
llm: params.model,
|
|
708
722
|
tools,
|
|
709
723
|
prompt: params.prompt,
|
|
710
724
|
name: agentLattice.config.name,
|
|
711
|
-
checkpointer: getCheckpointSaver("default")
|
|
725
|
+
checkpointer: getCheckpointSaver("default"),
|
|
726
|
+
stateSchema
|
|
712
727
|
});
|
|
713
728
|
}
|
|
714
729
|
};
|
|
@@ -716,15 +731,15 @@ var ReActAgentGraphBuilder = class {
|
|
|
716
731
|
// src/deep_agent/subAgent.ts
|
|
717
732
|
var import_tools3 = require("@langchain/core/tools");
|
|
718
733
|
var import_messages2 = require("@langchain/core/messages");
|
|
719
|
-
var
|
|
734
|
+
var import_langgraph4 = require("@langchain/langgraph");
|
|
720
735
|
var import_prebuilt2 = require("@langchain/langgraph/prebuilt");
|
|
721
|
-
var
|
|
736
|
+
var import_zod6 = require("zod");
|
|
722
737
|
|
|
723
738
|
// src/deep_agent/tools.ts
|
|
724
739
|
var import_tools2 = require("@langchain/core/tools");
|
|
725
740
|
var import_messages = require("@langchain/core/messages");
|
|
726
|
-
var
|
|
727
|
-
var
|
|
741
|
+
var import_langgraph3 = require("@langchain/langgraph");
|
|
742
|
+
var import_zod5 = require("zod");
|
|
728
743
|
|
|
729
744
|
// src/deep_agent/prompts.ts
|
|
730
745
|
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.
|
|
@@ -989,7 +1004,7 @@ var genUIMarkdown = (type, data) => {
|
|
|
989
1004
|
// src/deep_agent/tools.ts
|
|
990
1005
|
var writeTodos = (0, import_tools2.tool)(
|
|
991
1006
|
(input, config) => {
|
|
992
|
-
return new
|
|
1007
|
+
return new import_langgraph3.Command({
|
|
993
1008
|
update: {
|
|
994
1009
|
todos: input.todos,
|
|
995
1010
|
messages: [
|
|
@@ -1004,11 +1019,11 @@ var writeTodos = (0, import_tools2.tool)(
|
|
|
1004
1019
|
{
|
|
1005
1020
|
name: "write_todos",
|
|
1006
1021
|
description: WRITE_TODOS_DESCRIPTION,
|
|
1007
|
-
schema:
|
|
1008
|
-
todos:
|
|
1009
|
-
|
|
1010
|
-
content:
|
|
1011
|
-
status:
|
|
1022
|
+
schema: import_zod5.z.object({
|
|
1023
|
+
todos: import_zod5.z.array(
|
|
1024
|
+
import_zod5.z.object({
|
|
1025
|
+
content: import_zod5.z.string().describe("Content of the todo item"),
|
|
1026
|
+
status: import_zod5.z.enum(["pending", "in_progress", "completed"]).describe("Status of the todo")
|
|
1012
1027
|
})
|
|
1013
1028
|
).describe("List of todo items to update")
|
|
1014
1029
|
})
|
|
@@ -1016,19 +1031,19 @@ var writeTodos = (0, import_tools2.tool)(
|
|
|
1016
1031
|
);
|
|
1017
1032
|
var ls = (0, import_tools2.tool)(
|
|
1018
1033
|
() => {
|
|
1019
|
-
const state = (0,
|
|
1034
|
+
const state = (0, import_langgraph3.getCurrentTaskInput)();
|
|
1020
1035
|
const files = state.files || {};
|
|
1021
1036
|
return Object.keys(files);
|
|
1022
1037
|
},
|
|
1023
1038
|
{
|
|
1024
1039
|
name: "ls",
|
|
1025
1040
|
description: "List all files in the mock filesystem",
|
|
1026
|
-
schema:
|
|
1041
|
+
schema: import_zod5.z.object({})
|
|
1027
1042
|
}
|
|
1028
1043
|
);
|
|
1029
1044
|
var readFile = (0, import_tools2.tool)(
|
|
1030
1045
|
(input) => {
|
|
1031
|
-
const state = (0,
|
|
1046
|
+
const state = (0, import_langgraph3.getCurrentTaskInput)();
|
|
1032
1047
|
const mockFilesystem = state.files || {};
|
|
1033
1048
|
const { file_path, offset = 0, limit = 2e3 } = input;
|
|
1034
1049
|
if (!(file_path in mockFilesystem)) {
|
|
@@ -1058,19 +1073,19 @@ var readFile = (0, import_tools2.tool)(
|
|
|
1058
1073
|
{
|
|
1059
1074
|
name: "read_file",
|
|
1060
1075
|
description: TOOL_DESCRIPTION,
|
|
1061
|
-
schema:
|
|
1062
|
-
file_path:
|
|
1063
|
-
offset:
|
|
1064
|
-
limit:
|
|
1076
|
+
schema: import_zod5.z.object({
|
|
1077
|
+
file_path: import_zod5.z.string().describe("Absolute path to the file to read"),
|
|
1078
|
+
offset: import_zod5.z.number().optional().default(0).describe("Line offset to start reading from"),
|
|
1079
|
+
limit: import_zod5.z.number().optional().default(2e3).describe("Maximum number of lines to read")
|
|
1065
1080
|
})
|
|
1066
1081
|
}
|
|
1067
1082
|
);
|
|
1068
1083
|
var writeFile = (0, import_tools2.tool)(
|
|
1069
1084
|
(input, config) => {
|
|
1070
|
-
const state = (0,
|
|
1085
|
+
const state = (0, import_langgraph3.getCurrentTaskInput)();
|
|
1071
1086
|
const files = { ...state.files || {} };
|
|
1072
1087
|
files[input.file_path] = input.content;
|
|
1073
|
-
return new
|
|
1088
|
+
return new import_langgraph3.Command({
|
|
1074
1089
|
update: {
|
|
1075
1090
|
files,
|
|
1076
1091
|
messages: [
|
|
@@ -1085,15 +1100,15 @@ var writeFile = (0, import_tools2.tool)(
|
|
|
1085
1100
|
{
|
|
1086
1101
|
name: "write_file",
|
|
1087
1102
|
description: "Write content to a file in the mock filesystem",
|
|
1088
|
-
schema:
|
|
1089
|
-
file_path:
|
|
1090
|
-
content:
|
|
1103
|
+
schema: import_zod5.z.object({
|
|
1104
|
+
file_path: import_zod5.z.string().describe("Absolute path to the file to write"),
|
|
1105
|
+
content: import_zod5.z.string().describe("Content to write to the file")
|
|
1091
1106
|
})
|
|
1092
1107
|
}
|
|
1093
1108
|
);
|
|
1094
1109
|
var editFile = (0, import_tools2.tool)(
|
|
1095
1110
|
(input, config) => {
|
|
1096
|
-
const state = (0,
|
|
1111
|
+
const state = (0, import_langgraph3.getCurrentTaskInput)();
|
|
1097
1112
|
const mockFilesystem = { ...state.files || {} };
|
|
1098
1113
|
const { file_path, old_string, new_string, replace_all = false } = input;
|
|
1099
1114
|
if (!(file_path in mockFilesystem)) {
|
|
@@ -1129,7 +1144,7 @@ var editFile = (0, import_tools2.tool)(
|
|
|
1129
1144
|
newContent = content.replace(old_string, new_string);
|
|
1130
1145
|
}
|
|
1131
1146
|
mockFilesystem[file_path] = newContent;
|
|
1132
|
-
return new
|
|
1147
|
+
return new import_langgraph3.Command({
|
|
1133
1148
|
update: {
|
|
1134
1149
|
files: mockFilesystem,
|
|
1135
1150
|
messages: [
|
|
@@ -1144,11 +1159,11 @@ var editFile = (0, import_tools2.tool)(
|
|
|
1144
1159
|
{
|
|
1145
1160
|
name: "edit_file",
|
|
1146
1161
|
description: EDIT_DESCRIPTION,
|
|
1147
|
-
schema:
|
|
1148
|
-
file_path:
|
|
1149
|
-
old_string:
|
|
1150
|
-
new_string:
|
|
1151
|
-
replace_all:
|
|
1162
|
+
schema: import_zod5.z.object({
|
|
1163
|
+
file_path: import_zod5.z.string().describe("Absolute path to the file to edit"),
|
|
1164
|
+
old_string: import_zod5.z.string().describe("String to be replaced (must match exactly)"),
|
|
1165
|
+
new_string: import_zod5.z.string().describe("String to replace with"),
|
|
1166
|
+
replace_all: import_zod5.z.boolean().optional().default(false).describe("Whether to replace all occurrences")
|
|
1152
1167
|
})
|
|
1153
1168
|
}
|
|
1154
1169
|
);
|
|
@@ -1208,7 +1223,7 @@ function createTaskTool(inputs) {
|
|
|
1208
1223
|
).join(", ")}`;
|
|
1209
1224
|
}
|
|
1210
1225
|
try {
|
|
1211
|
-
const currentState = (0,
|
|
1226
|
+
const currentState = (0, import_langgraph4.getCurrentTaskInput)();
|
|
1212
1227
|
const modifiedState = {
|
|
1213
1228
|
...currentState,
|
|
1214
1229
|
messages: [
|
|
@@ -1219,7 +1234,7 @@ function createTaskTool(inputs) {
|
|
|
1219
1234
|
]
|
|
1220
1235
|
};
|
|
1221
1236
|
const result = await reactAgent.invoke(modifiedState, config);
|
|
1222
|
-
return new
|
|
1237
|
+
return new import_langgraph4.Command({
|
|
1223
1238
|
update: {
|
|
1224
1239
|
files: result.files || {},
|
|
1225
1240
|
messages: [
|
|
@@ -1231,11 +1246,11 @@ function createTaskTool(inputs) {
|
|
|
1231
1246
|
}
|
|
1232
1247
|
});
|
|
1233
1248
|
} catch (error) {
|
|
1234
|
-
if (error instanceof
|
|
1249
|
+
if (error instanceof import_langgraph4.GraphInterrupt) {
|
|
1235
1250
|
throw error;
|
|
1236
1251
|
}
|
|
1237
1252
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1238
|
-
return new
|
|
1253
|
+
return new import_langgraph4.Command({
|
|
1239
1254
|
update: {
|
|
1240
1255
|
messages: [
|
|
1241
1256
|
new import_messages2.ToolMessage({
|
|
@@ -1253,9 +1268,9 @@ function createTaskTool(inputs) {
|
|
|
1253
1268
|
"{other_agents}",
|
|
1254
1269
|
subagents.map((a) => `- ${a.name}: ${a.description}`).join("\n")
|
|
1255
1270
|
) + TASK_DESCRIPTION_SUFFIX,
|
|
1256
|
-
schema:
|
|
1257
|
-
description:
|
|
1258
|
-
subagent_type:
|
|
1271
|
+
schema: import_zod6.z.object({
|
|
1272
|
+
description: import_zod6.z.string().describe("The task to execute with the selected agent"),
|
|
1273
|
+
subagent_type: import_zod6.z.string().describe(
|
|
1259
1274
|
`Name of the agent to use. Available: ${subagents.map((a) => a.name).join(", ")}`
|
|
1260
1275
|
)
|
|
1261
1276
|
})
|
|
@@ -1264,10 +1279,10 @@ function createTaskTool(inputs) {
|
|
|
1264
1279
|
}
|
|
1265
1280
|
|
|
1266
1281
|
// src/deep_agent/state.ts
|
|
1267
|
-
var
|
|
1268
|
-
var
|
|
1269
|
-
var
|
|
1270
|
-
var
|
|
1282
|
+
var import_zod7 = require("@langchain/langgraph/zod");
|
|
1283
|
+
var import_langgraph5 = require("@langchain/langgraph");
|
|
1284
|
+
var import_zod8 = require("@langchain/langgraph/zod");
|
|
1285
|
+
var import_zod9 = require("zod");
|
|
1271
1286
|
function fileReducer(left, right) {
|
|
1272
1287
|
if (left == null) {
|
|
1273
1288
|
return right || {};
|
|
@@ -1283,16 +1298,16 @@ function todoReducer(left, right) {
|
|
|
1283
1298
|
}
|
|
1284
1299
|
return left || [];
|
|
1285
1300
|
}
|
|
1286
|
-
var DeepAgentState =
|
|
1287
|
-
todos: (0,
|
|
1301
|
+
var DeepAgentState = import_langgraph5.MessagesZodState.extend({
|
|
1302
|
+
todos: (0, import_zod8.withLangGraph)(import_zod9.z.custom(), {
|
|
1288
1303
|
reducer: {
|
|
1289
|
-
schema:
|
|
1304
|
+
schema: import_zod9.z.custom(),
|
|
1290
1305
|
fn: todoReducer
|
|
1291
1306
|
}
|
|
1292
1307
|
}),
|
|
1293
|
-
files: (0,
|
|
1308
|
+
files: (0, import_zod8.withLangGraph)(import_zod9.z.custom(), {
|
|
1294
1309
|
reducer: {
|
|
1295
|
-
schema:
|
|
1310
|
+
schema: import_zod9.z.custom(),
|
|
1296
1311
|
fn: fileReducer
|
|
1297
1312
|
}
|
|
1298
1313
|
})
|
|
@@ -1384,9 +1399,9 @@ var DeepAgentGraphBuilder = class {
|
|
|
1384
1399
|
};
|
|
1385
1400
|
|
|
1386
1401
|
// src/createPlanExecuteAgent.ts
|
|
1387
|
-
var
|
|
1402
|
+
var import_langgraph7 = require("@langchain/langgraph");
|
|
1388
1403
|
var import_messages6 = require("@langchain/core/messages");
|
|
1389
|
-
var
|
|
1404
|
+
var import_zod10 = require("zod");
|
|
1390
1405
|
|
|
1391
1406
|
// src/logger/Logger.ts
|
|
1392
1407
|
var import_pino = __toESM(require("pino"));
|
|
@@ -1584,10 +1599,10 @@ var getLastHumanMessageData = (messages) => {
|
|
|
1584
1599
|
var import_tools7 = require("@langchain/core/tools");
|
|
1585
1600
|
|
|
1586
1601
|
// src/util/PGMemory.ts
|
|
1587
|
-
var
|
|
1602
|
+
var import_langgraph6 = require("@langchain/langgraph");
|
|
1588
1603
|
var import_langgraph_checkpoint_postgres = require("@langchain/langgraph-checkpoint-postgres");
|
|
1589
1604
|
var globalMemory = import_langgraph_checkpoint_postgres.PostgresSaver.fromConnString(process.env.DATABASE_URL);
|
|
1590
|
-
var memory2 = new
|
|
1605
|
+
var memory2 = new import_langgraph6.MemorySaver();
|
|
1591
1606
|
var _MemoryManager = class _MemoryManager {
|
|
1592
1607
|
static getInstance() {
|
|
1593
1608
|
return _MemoryManager.instance;
|
|
@@ -1598,40 +1613,40 @@ var MemoryManager = _MemoryManager;
|
|
|
1598
1613
|
|
|
1599
1614
|
// src/createPlanExecuteAgent.ts
|
|
1600
1615
|
var import_prebuilt4 = require("@langchain/langgraph/prebuilt");
|
|
1601
|
-
var PlanExecuteState =
|
|
1616
|
+
var PlanExecuteState = import_langgraph7.Annotation.Root({
|
|
1602
1617
|
// 输入
|
|
1603
|
-
input: (0,
|
|
1618
|
+
input: (0, import_langgraph7.Annotation)({
|
|
1604
1619
|
reducer: (x, y) => y ?? x ?? ""
|
|
1605
1620
|
}),
|
|
1606
1621
|
// 计划步骤列表
|
|
1607
|
-
plan: (0,
|
|
1622
|
+
plan: (0, import_langgraph7.Annotation)({
|
|
1608
1623
|
reducer: (x, y) => y ?? x ?? []
|
|
1609
1624
|
}),
|
|
1610
1625
|
// 已执行的步骤 [步骤名称, 执行结果]
|
|
1611
|
-
pastSteps: (0,
|
|
1626
|
+
pastSteps: (0, import_langgraph7.Annotation)({
|
|
1612
1627
|
reducer: (x, y) => x.concat(y),
|
|
1613
1628
|
default: () => []
|
|
1614
1629
|
}),
|
|
1615
1630
|
// 最终响应
|
|
1616
|
-
response: (0,
|
|
1631
|
+
response: (0, import_langgraph7.Annotation)({
|
|
1617
1632
|
reducer: (x, y) => y ?? x
|
|
1618
1633
|
}),
|
|
1619
1634
|
// 错误信息
|
|
1620
|
-
error: (0,
|
|
1635
|
+
error: (0, import_langgraph7.Annotation)({
|
|
1621
1636
|
reducer: (x, y) => y ?? x
|
|
1622
1637
|
}),
|
|
1623
1638
|
// 继承基础状态
|
|
1624
|
-
"x-tenant-id": (0,
|
|
1625
|
-
messages: (0,
|
|
1626
|
-
reducer:
|
|
1639
|
+
"x-tenant-id": (0, import_langgraph7.Annotation)(),
|
|
1640
|
+
messages: (0, import_langgraph7.Annotation)({
|
|
1641
|
+
reducer: import_langgraph7.messagesStateReducer,
|
|
1627
1642
|
default: () => []
|
|
1628
1643
|
})
|
|
1629
1644
|
});
|
|
1630
|
-
var planSchema =
|
|
1631
|
-
steps:
|
|
1645
|
+
var planSchema = import_zod10.z.object({
|
|
1646
|
+
steps: import_zod10.z.array(import_zod10.z.string()).describe("\u9700\u8981\u6267\u884C\u7684\u6B65\u9AA4\u5217\u8868\uFF0C\u5E94\u6309\u7167\u6267\u884C\u987A\u5E8F\u6392\u5E8F")
|
|
1632
1647
|
});
|
|
1633
|
-
var responseSchema =
|
|
1634
|
-
response:
|
|
1648
|
+
var responseSchema = import_zod10.z.object({
|
|
1649
|
+
response: import_zod10.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")
|
|
1635
1650
|
});
|
|
1636
1651
|
function createPlanExecuteAgent(config) {
|
|
1637
1652
|
const {
|
|
@@ -1723,7 +1738,7 @@ ${executorTools.map((tool5) => tool5.name).join("\n")}
|
|
|
1723
1738
|
error: void 0
|
|
1724
1739
|
};
|
|
1725
1740
|
} catch (error) {
|
|
1726
|
-
if (error instanceof
|
|
1741
|
+
if (error instanceof import_langgraph7.GraphInterrupt) {
|
|
1727
1742
|
throw error;
|
|
1728
1743
|
}
|
|
1729
1744
|
const errorMsg = `\u4EFB\u52A1\u6267\u884C\u5931\u8D25: ${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`;
|
|
@@ -1816,7 +1831,7 @@ Only add steps to the plan that still NEED to be done. Do not return previously
|
|
|
1816
1831
|
};
|
|
1817
1832
|
}
|
|
1818
1833
|
} catch (error) {
|
|
1819
|
-
if (error instanceof
|
|
1834
|
+
if (error instanceof import_langgraph7.GraphInterrupt) {
|
|
1820
1835
|
throw error;
|
|
1821
1836
|
}
|
|
1822
1837
|
const errorMsg = `\u91CD\u65B0\u89C4\u5212\u5931\u8D25: ${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`;
|
|
@@ -1848,8 +1863,8 @@ Only add steps to the plan that still NEED to be done. Do not return previously
|
|
|
1848
1863
|
}
|
|
1849
1864
|
return "continue";
|
|
1850
1865
|
}
|
|
1851
|
-
const workflow = new
|
|
1852
|
-
end:
|
|
1866
|
+
const workflow = new import_langgraph7.StateGraph(PlanExecuteState).addNode("planner", planStep).addNode("executor", executeStep).addNode("replanner", replanStep).addEdge(import_langgraph7.START, "planner").addEdge("planner", "executor").addEdge("executor", "replanner").addConditionalEdges("replanner", shouldEnd, {
|
|
1867
|
+
end: import_langgraph7.END,
|
|
1853
1868
|
continue: "executor"
|
|
1854
1869
|
});
|
|
1855
1870
|
const compiledGraph = workflow.compile({
|
|
@@ -2029,7 +2044,8 @@ var AgentParamsBuilder = class {
|
|
|
2029
2044
|
tools,
|
|
2030
2045
|
model,
|
|
2031
2046
|
subAgents,
|
|
2032
|
-
prompt: agentLattice.config.prompt
|
|
2047
|
+
prompt: agentLattice.config.prompt,
|
|
2048
|
+
stateSchema: agentLattice.config.schema
|
|
2033
2049
|
};
|
|
2034
2050
|
}
|
|
2035
2051
|
};
|