@axiom-lattice/core 1.0.26 → 1.0.29

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.mjs CHANGED
@@ -483,7 +483,11 @@ var ToolLatticeManager = class _ToolLatticeManager extends BaseLatticeManager {
483
483
  };
484
484
  var toolLatticeManager = ToolLatticeManager.getInstance();
485
485
  var registerToolLattice = (key, config, executor) => toolLatticeManager.registerLattice(key, config, executor);
486
+ var getToolLattice = (key) => toolLatticeManager.getToolLattice(key);
487
+ var getToolDefinition = (key) => toolLatticeManager.getToolDefinition(key);
486
488
  var getToolClient = (key) => toolLatticeManager.getToolClient(key);
489
+ var getAllToolDefinitions = () => toolLatticeManager.getAllToolDefinitions();
490
+ var validateToolInput = (key, input) => toolLatticeManager.validateToolInput(key, input);
487
491
 
488
492
  // src/tool_lattice/get_current_date_time/index.ts
489
493
  registerToolLattice(
@@ -550,6 +554,101 @@ import {
550
554
 
551
555
  // src/agent_lattice/builders/ReActAgentGraphBuilder.ts
552
556
  import { createReactAgent } from "@langchain/langgraph/prebuilt";
557
+
558
+ // src/memory_lattice/DefaultMemorySaver.ts
559
+ import { MemorySaver } from "@langchain/langgraph";
560
+
561
+ // src/memory_lattice/MemoryLatticeManager.ts
562
+ import { MemoryType } from "@axiom-lattice/protocols";
563
+ var _MemoryLatticeManager = class _MemoryLatticeManager extends BaseLatticeManager {
564
+ /**
565
+ * 私有构造函数,防止外部直接实例化
566
+ */
567
+ constructor() {
568
+ super();
569
+ }
570
+ /**
571
+ * 获取单例实例
572
+ */
573
+ static getInstance() {
574
+ if (!_MemoryLatticeManager.instance) {
575
+ _MemoryLatticeManager.instance = new _MemoryLatticeManager();
576
+ }
577
+ return _MemoryLatticeManager.instance;
578
+ }
579
+ /**
580
+ * 获取Lattice类型
581
+ */
582
+ getLatticeType() {
583
+ return "memory";
584
+ }
585
+ /**
586
+ * 注册检查点保存器
587
+ * @param key 保存器键名
588
+ * @param saver 检查点保存器实例
589
+ */
590
+ registerCheckpointSaver(key, saver) {
591
+ if (_MemoryLatticeManager.checkpointSavers.has(key)) {
592
+ throw new Error(`\u68C0\u67E5\u70B9\u4FDD\u5B58\u5668 "${key}" \u5DF2\u7ECF\u5B58\u5728\uFF0C\u65E0\u6CD5\u91CD\u590D\u6CE8\u518C`);
593
+ }
594
+ _MemoryLatticeManager.checkpointSavers.set(key, saver);
595
+ }
596
+ /**
597
+ * 获取检查点保存器
598
+ * @param key 保存器键名
599
+ */
600
+ getCheckpointSaver(key) {
601
+ const saver = _MemoryLatticeManager.checkpointSavers.get(key);
602
+ if (!saver) {
603
+ throw new Error(`\u68C0\u67E5\u70B9\u4FDD\u5B58\u5668 "${key}" \u4E0D\u5B58\u5728`);
604
+ }
605
+ return saver;
606
+ }
607
+ /**
608
+ * 获取所有已注册的检查点保存器键名
609
+ */
610
+ getCheckpointSaverKeys() {
611
+ return Array.from(_MemoryLatticeManager.checkpointSavers.keys());
612
+ }
613
+ /**
614
+ * 检查检查点保存器是否存在
615
+ * @param key 保存器键名
616
+ */
617
+ hasCheckpointSaver(key) {
618
+ return _MemoryLatticeManager.checkpointSavers.has(key);
619
+ }
620
+ /**
621
+ * 移除检查点保存器
622
+ * @param key 保存器键名
623
+ */
624
+ removeCheckpointSaver(key) {
625
+ return _MemoryLatticeManager.checkpointSavers.delete(key);
626
+ }
627
+ };
628
+ // 检查点保存器注册表
629
+ _MemoryLatticeManager.checkpointSavers = /* @__PURE__ */ new Map();
630
+ var MemoryLatticeManager = _MemoryLatticeManager;
631
+ var getCheckpointSaver = (key) => MemoryLatticeManager.getInstance().getCheckpointSaver(key);
632
+ var registerCheckpointSaver = (key, saver) => MemoryLatticeManager.getInstance().registerCheckpointSaver(key, saver);
633
+
634
+ // src/memory_lattice/DefaultMemorySaver.ts
635
+ var memory = new MemorySaver();
636
+ registerCheckpointSaver("default", memory);
637
+
638
+ // src/agent_lattice/builders/state.ts
639
+ import "@langchain/langgraph/zod";
640
+ import { MessagesZodState } from "@langchain/langgraph";
641
+ import { z as z3 } from "zod";
642
+ var ReActAgentState = MessagesZodState.extend({
643
+ files: z3.object({
644
+ final_output: z3.record(z3.any())
645
+ })
646
+ });
647
+ var createReactAgentSchema = (schema) => {
648
+ return schema ? MessagesZodState.extend(schema.shape) : void 0;
649
+ };
650
+
651
+ // src/agent_lattice/builders/ReActAgentGraphBuilder.ts
553
652
  var ReActAgentGraphBuilder = class {
554
653
  /**
555
654
  * 构建ReAct Agent Graph
@@ -563,11 +662,14 @@ var ReActAgentGraphBuilder = class {
563
662
  const tool5 = getToolClient(t.key);
564
663
  return tool5;
565
664
  }).filter((tool5) => tool5 !== void 0);
665
+ const stateSchema = createReactAgentSchema(params.stateSchema);
566
666
  return createReactAgent({
567
667
  llm: params.model,
568
668
  tools,
569
669
  prompt: params.prompt,
570
- name: agentLattice.config.name
670
+ name: agentLattice.config.name,
671
+ checkpointer: getCheckpointSaver("default"),
672
+ stateSchema
571
673
  });
572
674
  }
573
675
  };
@@ -581,13 +683,13 @@ import {
581
683
  GraphInterrupt
582
684
  } from "@langchain/langgraph";
583
685
  import { createReactAgent as createReactAgent2 } from "@langchain/langgraph/prebuilt";
584
- import { z as z4 } from "zod";
686
+ import { z as z5 } from "zod";
585
687
 
586
688
  // src/deep_agent/tools.ts
587
689
  import { tool as tool2 } from "@langchain/core/tools";
588
690
  import { ToolMessage } from "@langchain/core/messages";
589
691
  import { Command, getCurrentTaskInput } from "@langchain/langgraph";
590
- import { z as z3 } from "zod";
692
+ import { z as z4 } from "zod";
591
693
 
592
694
  // src/deep_agent/prompts.ts
593
695
  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.
@@ -867,11 +969,11 @@ var writeTodos = tool2(
867
969
  {
868
970
  name: "write_todos",
869
971
  description: WRITE_TODOS_DESCRIPTION,
870
- schema: z3.object({
871
- todos: z3.array(
872
- z3.object({
873
- content: z3.string().describe("Content of the todo item"),
874
- status: z3.enum(["pending", "in_progress", "completed"]).describe("Status of the todo")
972
+ schema: z4.object({
973
+ todos: z4.array(
974
+ z4.object({
975
+ content: z4.string().describe("Content of the todo item"),
976
+ status: z4.enum(["pending", "in_progress", "completed"]).describe("Status of the todo")
875
977
  })
876
978
  ).describe("List of todo items to update")
877
979
  })
@@ -886,7 +988,7 @@ var ls = tool2(
886
988
  {
887
989
  name: "ls",
888
990
  description: "List all files in the mock filesystem",
889
- schema: z3.object({})
991
+ schema: z4.object({})
890
992
  }
891
993
  );
892
994
  var readFile = tool2(
@@ -921,10 +1023,10 @@ var readFile = tool2(
921
1023
  {
922
1024
  name: "read_file",
923
1025
  description: TOOL_DESCRIPTION,
924
- schema: z3.object({
925
- file_path: z3.string().describe("Absolute path to the file to read"),
926
- offset: z3.number().optional().default(0).describe("Line offset to start reading from"),
927
- limit: z3.number().optional().default(2e3).describe("Maximum number of lines to read")
1026
+ schema: z4.object({
1027
+ file_path: z4.string().describe("Absolute path to the file to read"),
1028
+ offset: z4.number().optional().default(0).describe("Line offset to start reading from"),
1029
+ limit: z4.number().optional().default(2e3).describe("Maximum number of lines to read")
928
1030
  })
929
1031
  }
930
1032
  );
@@ -948,9 +1050,9 @@ var writeFile = tool2(
948
1050
  {
949
1051
  name: "write_file",
950
1052
  description: "Write content to a file in the mock filesystem",
951
- schema: z3.object({
952
- file_path: z3.string().describe("Absolute path to the file to write"),
953
- content: z3.string().describe("Content to write to the file")
1053
+ schema: z4.object({
1054
+ file_path: z4.string().describe("Absolute path to the file to write"),
1055
+ content: z4.string().describe("Content to write to the file")
954
1056
  })
955
1057
  }
956
1058
  );
@@ -1007,11 +1109,11 @@ var editFile = tool2(
1007
1109
  {
1008
1110
  name: "edit_file",
1009
1111
  description: EDIT_DESCRIPTION,
1010
- schema: z3.object({
1011
- file_path: z3.string().describe("Absolute path to the file to edit"),
1012
- old_string: z3.string().describe("String to be replaced (must match exactly)"),
1013
- new_string: z3.string().describe("String to replace with"),
1014
- replace_all: z3.boolean().optional().default(false).describe("Whether to replace all occurrences")
1112
+ schema: z4.object({
1113
+ file_path: z4.string().describe("Absolute path to the file to edit"),
1114
+ old_string: z4.string().describe("String to be replaced (must match exactly)"),
1115
+ new_string: z4.string().describe("String to replace with"),
1116
+ replace_all: z4.boolean().optional().default(false).describe("Whether to replace all occurrences")
1015
1117
  })
1016
1118
  }
1017
1119
  );
@@ -1116,9 +1218,9 @@ function createTaskTool(inputs) {
1116
1218
  "{other_agents}",
1117
1219
  subagents.map((a) => `- ${a.name}: ${a.description}`).join("\n")
1118
1220
  ) + TASK_DESCRIPTION_SUFFIX,
1119
- schema: z4.object({
1120
- description: z4.string().describe("The task to execute with the selected agent"),
1121
- subagent_type: z4.string().describe(
1221
+ schema: z5.object({
1222
+ description: z5.string().describe("The task to execute with the selected agent"),
1223
+ subagent_type: z5.string().describe(
1122
1224
  `Name of the agent to use. Available: ${subagents.map((a) => a.name).join(", ")}`
1123
1225
  )
1124
1226
  })
@@ -1128,9 +1230,9 @@ function createTaskTool(inputs) {
1128
1230
 
1129
1231
  // src/deep_agent/state.ts
1130
1232
  import "@langchain/langgraph/zod";
1131
- import { MessagesZodState } from "@langchain/langgraph";
1233
+ import { MessagesZodState as MessagesZodState2 } from "@langchain/langgraph";
1132
1234
  import { withLangGraph } from "@langchain/langgraph/zod";
1133
- import { z as z5 } from "zod";
1235
+ import { z as z6 } from "zod";
1134
1236
  function fileReducer(left, right) {
1135
1237
  if (left == null) {
1136
1238
  return right || {};
@@ -1146,16 +1248,16 @@ function todoReducer(left, right) {
1146
1248
  }
1147
1249
  return left || [];
1148
1250
  }
1149
- var DeepAgentState = MessagesZodState.extend({
1150
- todos: withLangGraph(z5.custom(), {
1251
+ var DeepAgentState = MessagesZodState2.extend({
1252
+ todos: withLangGraph(z6.custom(), {
1151
1253
  reducer: {
1152
- schema: z5.custom(),
1254
+ schema: z6.custom(),
1153
1255
  fn: todoReducer
1154
1256
  }
1155
1257
  }),
1156
- files: withLangGraph(z5.custom(), {
1258
+ files: withLangGraph(z6.custom(), {
1157
1259
  reducer: {
1158
- schema: z5.custom(),
1260
+ schema: z6.custom(),
1159
1261
  fn: fileReducer
1160
1262
  }
1161
1263
  })
@@ -1163,81 +1265,6 @@ var DeepAgentState = MessagesZodState.extend({
1163
1265
 
1164
1266
  // src/deep_agent/graph.ts
1165
1267
  import { createReactAgent as createReactAgent3 } from "@langchain/langgraph/prebuilt";
1166
-
1167
- // src/memory_lattice/MemoryLatticeManager.ts
1168
- import { MemoryType } from "@axiom-lattice/protocols";
1169
- var _MemoryLatticeManager = class _MemoryLatticeManager extends BaseLatticeManager {
1170
- /**
1171
- * 私有构造函数,防止外部直接实例化
1172
- */
1173
- constructor() {
1174
- super();
1175
- }
1176
- /**
1177
- * 获取单例实例
1178
- */
1179
- static getInstance() {
1180
- if (!_MemoryLatticeManager.instance) {
1181
- _MemoryLatticeManager.instance = new _MemoryLatticeManager();
1182
- }
1183
- return _MemoryLatticeManager.instance;
1184
- }
1185
- /**
1186
- * 获取Lattice类型
1187
- */
1188
- getLatticeType() {
1189
- return "memory";
1190
- }
1191
- /**
1192
- * 注册检查点保存器
1193
- * @param key 保存器键名
1194
- * @param saver 检查点保存器实例
1195
- */
1196
- registerCheckpointSaver(key, saver) {
1197
- if (_MemoryLatticeManager.checkpointSavers.has(key)) {
1198
- throw new Error(`\u68C0\u67E5\u70B9\u4FDD\u5B58\u5668 "${key}" \u5DF2\u7ECF\u5B58\u5728\uFF0C\u65E0\u6CD5\u91CD\u590D\u6CE8\u518C`);
1199
- }
1200
- _MemoryLatticeManager.checkpointSavers.set(key, saver);
1201
- }
1202
- /**
1203
- * 获取检查点保存器
1204
- * @param key 保存器键名
1205
- */
1206
- getCheckpointSaver(key) {
1207
- const saver = _MemoryLatticeManager.checkpointSavers.get(key);
1208
- if (!saver) {
1209
- throw new Error(`\u68C0\u67E5\u70B9\u4FDD\u5B58\u5668 "${key}" \u4E0D\u5B58\u5728`);
1210
- }
1211
- return saver;
1212
- }
1213
- /**
1214
- * 获取所有已注册的检查点保存器键名
1215
- */
1216
- getCheckpointSaverKeys() {
1217
- return Array.from(_MemoryLatticeManager.checkpointSavers.keys());
1218
- }
1219
- /**
1220
- * 检查检查点保存器是否存在
1221
- * @param key 保存器键名
1222
- */
1223
- hasCheckpointSaver(key) {
1224
- return _MemoryLatticeManager.checkpointSavers.has(key);
1225
- }
1226
- /**
1227
- * 移除检查点保存器
1228
- * @param key 保存器键名
1229
- */
1230
- removeCheckpointSaver(key) {
1231
- return _MemoryLatticeManager.checkpointSavers.delete(key);
1232
- }
1233
- };
1234
- // 检查点保存器注册表
1235
- _MemoryLatticeManager.checkpointSavers = /* @__PURE__ */ new Map();
1236
- var MemoryLatticeManager = _MemoryLatticeManager;
1237
- var getCheckpointSaver = (key) => MemoryLatticeManager.getInstance().getCheckpointSaver(key);
1238
- var registerCheckpointSaver = (key, saver) => MemoryLatticeManager.getInstance().registerCheckpointSaver(key, saver);
1239
-
1240
- // src/deep_agent/graph.ts
1241
1268
  var BASE_PROMPT = `You have access to a number of standard tools
1242
1269
 
1243
1270
  ## \`write_todos\`
@@ -1333,7 +1360,7 @@ import {
1333
1360
  import {
1334
1361
  HumanMessage as HumanMessage2
1335
1362
  } from "@langchain/core/messages";
1336
- import { z as z6 } from "zod";
1363
+ import { z as z7 } from "zod";
1337
1364
 
1338
1365
  // src/logger/Logger.ts
1339
1366
  import pino from "pino";
@@ -1533,16 +1560,16 @@ var getLastHumanMessageData = (messages) => {
1533
1560
  import { tool as tool4 } from "@langchain/core/tools";
1534
1561
 
1535
1562
  // src/util/PGMemory.ts
1536
- import { MemorySaver } from "@langchain/langgraph";
1563
+ import { MemorySaver as MemorySaver2 } from "@langchain/langgraph";
1537
1564
  import { PostgresSaver } from "@langchain/langgraph-checkpoint-postgres";
1538
1565
  var globalMemory = PostgresSaver.fromConnString(process.env.DATABASE_URL);
1539
- var memory = new MemorySaver();
1566
+ var memory2 = new MemorySaver2();
1540
1567
  var _MemoryManager = class _MemoryManager {
1541
1568
  static getInstance() {
1542
1569
  return _MemoryManager.instance;
1543
1570
  }
1544
1571
  };
1545
- _MemoryManager.instance = memory;
1572
+ _MemoryManager.instance = memory2;
1546
1573
  var MemoryManager = _MemoryManager;
1547
1574
 
1548
1575
  // src/createPlanExecuteAgent.ts
@@ -1576,11 +1603,11 @@ var PlanExecuteState = Annotation.Root({
1576
1603
  default: () => []
1577
1604
  })
1578
1605
  });
1579
- var planSchema = z6.object({
1580
- steps: z6.array(z6.string()).describe("\u9700\u8981\u6267\u884C\u7684\u6B65\u9AA4\u5217\u8868\uFF0C\u5E94\u6309\u7167\u6267\u884C\u987A\u5E8F\u6392\u5E8F")
1606
+ var planSchema = z7.object({
1607
+ steps: z7.array(z7.string()).describe("\u9700\u8981\u6267\u884C\u7684\u6B65\u9AA4\u5217\u8868\uFF0C\u5E94\u6309\u7167\u6267\u884C\u987A\u5E8F\u6392\u5E8F")
1581
1608
  });
1582
- var responseSchema = z6.object({
1583
- response: z6.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")
1609
+ var responseSchema = z7.object({
1610
+ response: z7.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")
1584
1611
  });
1585
1612
  function createPlanExecuteAgent(config) {
1586
1613
  const {
@@ -1978,7 +2005,8 @@ var AgentParamsBuilder = class {
1978
2005
  tools,
1979
2006
  model,
1980
2007
  subAgents,
1981
- prompt: agentLattice.config.prompt
2008
+ prompt: agentLattice.config.prompt,
2009
+ stateSchema: agentLattice.config.schema
1982
2010
  };
1983
2011
  }
1984
2012
  };
@@ -2124,11 +2152,6 @@ var getAllAgentConfigs = () => agentLatticeManager.getAllAgentConfigs();
2124
2152
  var validateAgentInput = (key, input) => agentLatticeManager.validateAgentInput(key, input);
2125
2153
  var getAgentClient = (key, options) => agentLatticeManager.initializeClient(key, options);
2126
2154
 
2127
- // src/memory_lattice/DefaultMemorySaver.ts
2128
- import { MemorySaver as MemorySaver2 } from "@langchain/langgraph";
2129
- var memory2 = new MemorySaver2();
2130
- registerCheckpointSaver("default", memory2);
2131
-
2132
2155
  // src/index.ts
2133
2156
  import * as Protocols from "@axiom-lattice/protocols";
2134
2157
  export {
@@ -2140,18 +2163,26 @@ export {
2140
2163
  MemoryType,
2141
2164
  ModelLatticeManager,
2142
2165
  Protocols,
2166
+ ToolLatticeManager,
2143
2167
  agentLatticeManager,
2144
2168
  getAgentClient,
2145
2169
  getAgentConfig,
2146
2170
  getAgentLattice,
2147
2171
  getAllAgentConfigs,
2172
+ getAllToolDefinitions,
2148
2173
  getCheckpointSaver,
2149
2174
  getModelLattice,
2175
+ getToolClient,
2176
+ getToolDefinition,
2177
+ getToolLattice,
2150
2178
  modelLatticeManager,
2151
2179
  registerAgentLattice,
2152
2180
  registerAgentLattices,
2153
2181
  registerCheckpointSaver,
2154
2182
  registerModelLattice,
2155
- validateAgentInput
2183
+ registerToolLattice,
2184
+ toolLatticeManager,
2185
+ validateAgentInput,
2186
+ validateToolInput
2156
2187
  };
2157
2188
  //# sourceMappingURL=index.mjs.map