@axiom-lattice/core 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/.eslintrc.json +22 -0
  2. package/.turbo/turbo-build.log +21 -0
  3. package/README.md +47 -0
  4. package/dist/index.d.mts +356 -0
  5. package/dist/index.d.ts +356 -0
  6. package/dist/index.js +2191 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/index.mjs +2159 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/jest.config.js +21 -0
  11. package/package.json +63 -0
  12. package/src/__tests__/AgentManager.test.ts +202 -0
  13. package/src/__tests__/setup.ts +5 -0
  14. package/src/agent_lattice/AgentLatticeManager.ts +216 -0
  15. package/src/agent_lattice/builders/AgentBuilder.ts +79 -0
  16. package/src/agent_lattice/builders/AgentGraphBuilder.ts +22 -0
  17. package/src/agent_lattice/builders/AgentGraphBuilderFactory.ts +70 -0
  18. package/src/agent_lattice/builders/AgentParamsBuilder.ts +86 -0
  19. package/src/agent_lattice/builders/DeepAgentGraphBuilder.ts +46 -0
  20. package/src/agent_lattice/builders/PlanExecuteAgentGraphBuilder.ts +46 -0
  21. package/src/agent_lattice/builders/ReActAgentGraphBuilder.ts +42 -0
  22. package/src/agent_lattice/builders/index.ts +14 -0
  23. package/src/agent_lattice/index.ts +27 -0
  24. package/src/agent_lattice/types.ts +42 -0
  25. package/src/base/BaseLatticeManager.ts +145 -0
  26. package/src/base/index.ts +1 -0
  27. package/src/createPlanExecuteAgent.ts +475 -0
  28. package/src/deep_agent/graph.ts +106 -0
  29. package/src/deep_agent/index.ts +25 -0
  30. package/src/deep_agent/prompts.ts +284 -0
  31. package/src/deep_agent/state.ts +63 -0
  32. package/src/deep_agent/subAgent.ts +185 -0
  33. package/src/deep_agent/tools.ts +273 -0
  34. package/src/deep_agent/types.ts +71 -0
  35. package/src/index.ts +9 -0
  36. package/src/logger/Logger.ts +186 -0
  37. package/src/memory_lattice/DefaultMemorySaver.ts +4 -0
  38. package/src/memory_lattice/MemoryLatticeManager.ts +105 -0
  39. package/src/memory_lattice/index.ts +9 -0
  40. package/src/model_lattice/ModelLattice.ts +208 -0
  41. package/src/model_lattice/ModelLatticeManager.ts +125 -0
  42. package/src/model_lattice/index.ts +1 -0
  43. package/src/tool_lattice/ToolLatticeManager.ts +221 -0
  44. package/src/tool_lattice/get_current_date_time/index.ts +14 -0
  45. package/src/tool_lattice/index.ts +2 -0
  46. package/src/tool_lattice/internet_search/index.ts +66 -0
  47. package/src/types.ts +28 -0
  48. package/src/util/PGMemory.ts +16 -0
  49. package/src/util/genUICard.ts +3 -0
  50. package/src/util/genUIMarkdown.ts +3 -0
  51. package/src/util/getLastHumanMessageData.ts +41 -0
  52. package/src/util/returnAIResponse.ts +30 -0
  53. package/src/util/returnErrorResponse.ts +26 -0
  54. package/src/util/returnFeedbackResponse.ts +25 -0
  55. package/src/util/returnToolResponse.ts +32 -0
  56. package/src/util/withAgentName.ts +220 -0
  57. package/src/util/zod-to-prompt.ts +50 -0
  58. package/tsconfig.json +26 -0
@@ -0,0 +1,356 @@
1
+ import { BaseMessage } from '@langchain/core/messages';
2
+ import { ZodType } from 'zod/v3';
3
+ import { $ZodType } from 'zod/v4/core';
4
+ import { BaseChatModel, BaseChatModelCallOptions } from '@langchain/core/language_models/chat_models';
5
+ import { BaseLanguageModelInput } from '@langchain/core/language_models/base';
6
+ import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
7
+ import { ChatResult } from '@langchain/core/outputs';
8
+ import { LLMConfig, AgentConfig, GraphBuildOptions } from '@axiom-lattice/protocols';
9
+ import * as protocols from '@axiom-lattice/protocols';
10
+ export { protocols as Protocols };
11
+ export { AgentConfig, AgentType, GraphBuildOptions, MemoryType } from '@axiom-lattice/protocols';
12
+ import { CompiledStateGraph } from '@langchain/langgraph';
13
+ import { BaseCheckpointSaver } from '@langchain/langgraph-checkpoint';
14
+
15
+ /**
16
+ * BaseLatticeManager - 抽象基类,为各种Lattice管理器提供通用功能
17
+ * 使用统一的Lattice注册表,不同类型的Lattice通过前缀区分
18
+ * @template TItem - 管理的项目类型
19
+ */
20
+ declare abstract class BaseLatticeManager<TItem = any> {
21
+ protected static registry: Map<string, any>;
22
+ /**
23
+ * 受保护的构造函数,防止外部直接实例化
24
+ */
25
+ protected constructor();
26
+ /**
27
+ * 获取管理器实例(由子类实现)
28
+ */
29
+ static getInstance(): BaseLatticeManager<any>;
30
+ /**
31
+ * 获取Lattice类型,用于构造键前缀
32
+ * 子类必须重写此方法以提供唯一的类型标识符
33
+ */
34
+ protected abstract getLatticeType(): string;
35
+ /**
36
+ * 构造完整的键名,包含类型前缀
37
+ * @param key 原始键名
38
+ */
39
+ protected getFullKey(key: string): string;
40
+ /**
41
+ * 注册项目
42
+ * @param key 项目键名(不含前缀)
43
+ * @param item 项目实例
44
+ */
45
+ register(key: string, item: TItem): void;
46
+ /**
47
+ * 获取指定项目
48
+ * @param key 项目键名(不含前缀)
49
+ */
50
+ get(key: string): TItem | undefined;
51
+ /**
52
+ * 获取所有当前类型的项目
53
+ */
54
+ getAll(): TItem[];
55
+ /**
56
+ * 检查项目是否存在
57
+ * @param key 项目键名(不含前缀)
58
+ */
59
+ has(key: string): boolean;
60
+ /**
61
+ * 移除项目
62
+ * @param key 项目键名(不含前缀)
63
+ */
64
+ remove(key: string): boolean;
65
+ /**
66
+ * 清空当前类型的所有项目
67
+ */
68
+ clear(): void;
69
+ /**
70
+ * 获取当前类型的项目数量
71
+ */
72
+ count(): number;
73
+ /**
74
+ * 获取当前类型的项目键名列表(不含前缀)
75
+ */
76
+ keys(): string[];
77
+ }
78
+
79
+ /**
80
+ * ModelLattice类,继承自BaseChatModel
81
+ * 简化版本,只保留通过LLMConfig创建LLM实例的功能
82
+ */
83
+ declare class ModelLattice extends BaseChatModel {
84
+ private config;
85
+ private llm;
86
+ lc_namespace: string[];
87
+ /**
88
+ * 构造函数
89
+ * @param config LLM配置
90
+ */
91
+ constructor(config: LLMConfig);
92
+ /**
93
+ * 返回模型类型
94
+ */
95
+ _llmType(): string;
96
+ /**
97
+ * 返回模型类型
98
+ */
99
+ _modelType(): string;
100
+ /**
101
+ * 实现BaseChatModel的_generate方法
102
+ * @param messages 消息数组
103
+ * @param options 调用选项
104
+ * @param runManager 回调管理器
105
+ * @returns 聊天结果
106
+ */
107
+ _generate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
108
+ /**
109
+ * 将工具绑定到模型
110
+ * @param tools 工具列表
111
+ * @param tool_choice 工具选择选项
112
+ * @returns 绑定工具后的模型
113
+ */
114
+ bindTools(tools: any[], { tool_choice, ...kwargs }?: {
115
+ tool_choice?: "auto" | "none" | "required" | any;
116
+ [key: string]: any;
117
+ }): any;
118
+ /**
119
+ * 使用结构化输出调用LLM
120
+ * @param input 输入
121
+ * @param schema 结构化输出的schema
122
+ * @param options 调用选项
123
+ * @returns 结构化输出
124
+ */
125
+ invokeWithStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(input: BaseLanguageModelInput, schema: ZodType<RunOutput> | $ZodType<RunOutput> | Record<string, any>, options?: BaseChatModelCallOptions & {
126
+ includeRaw?: boolean;
127
+ name?: string;
128
+ method?: "functionCalling" | "jsonMode";
129
+ }): Promise<RunOutput | {
130
+ raw: BaseMessage;
131
+ parsed: RunOutput;
132
+ }>;
133
+ /**
134
+ * 创建LLM实例
135
+ * @param config LLM配置
136
+ * @returns LLM实例
137
+ */
138
+ private initChatModel;
139
+ }
140
+
141
+ type ModelConfig = LLMConfig;
142
+ type ModelClient = ModelLattice;
143
+ interface ModelLatticeInterface {
144
+ key: string;
145
+ client: ModelClient;
146
+ }
147
+ /**
148
+ * ModelLatticeManager - 单例模型Lattice管理器
149
+ * 负责注册、管理各种语言模型Lattice
150
+ */
151
+ declare class ModelLatticeManager extends BaseLatticeManager<ModelLatticeInterface> {
152
+ private static _instance;
153
+ /**
154
+ * 获取ModelLatticeManager单例实例
155
+ */
156
+ static getInstance(): ModelLatticeManager;
157
+ /**
158
+ * 获取Lattice类型前缀
159
+ */
160
+ protected getLatticeType(): string;
161
+ /**
162
+ * 注册模型Lattice
163
+ * @param key Lattice键名
164
+ * @param config 模型配置
165
+ */
166
+ registerLattice(key: string, config: ModelConfig): void;
167
+ /**
168
+ * 获取ModelLattice
169
+ * @param key Lattice键名
170
+ */
171
+ getModelLattice(key: string): ModelLatticeInterface;
172
+ /**
173
+ * 获取所有Lattice
174
+ */
175
+ getAllLattices(): ModelLatticeInterface[];
176
+ /**
177
+ * 检查Lattice是否存在
178
+ * @param key Lattice键名
179
+ */
180
+ hasLattice(key: string): boolean;
181
+ /**
182
+ * 移除Lattice
183
+ * @param key Lattice键名
184
+ */
185
+ removeLattice(key: string): boolean;
186
+ /**
187
+ * 清空所有Lattice
188
+ */
189
+ clearLattices(): void;
190
+ /**
191
+ * 获取Lattice数量
192
+ */
193
+ getLatticeCount(): number;
194
+ /**
195
+ * 获取Lattice键名列表
196
+ */
197
+ getLatticeKeys(): string[];
198
+ }
199
+ declare const modelLatticeManager: ModelLatticeManager;
200
+ declare const registerModelLattice: (key: string, config: ModelConfig) => void;
201
+ declare const getModelLattice: (key: string) => ModelLatticeInterface;
202
+
203
+ /**
204
+ * Agent Lattice 类型定义
205
+ *
206
+ * 包含Agent Lattice相关的所有类型定义,供其他模块共享使用
207
+ */
208
+
209
+ type AgentClient = CompiledStateGraph<any, any, any, any, any>;
210
+ interface AgentLattice {
211
+ config: AgentConfig;
212
+ client: AgentClient | undefined;
213
+ }
214
+
215
+ /**
216
+ * AgentLatticeManager - 单例Agent Lattice管理器
217
+ * 负责注册、管理各种Agent Lattice
218
+ */
219
+ declare class AgentLatticeManager extends BaseLatticeManager<AgentLattice> {
220
+ private static _instance;
221
+ /**
222
+ * 获取AgentLatticeManager单例实例
223
+ */
224
+ static getInstance(): AgentLatticeManager;
225
+ /**
226
+ * 获取Lattice类型前缀
227
+ */
228
+ protected getLatticeType(): string;
229
+ /**
230
+ * 注册Agent Lattice
231
+ * @param config Agent配置
232
+ */
233
+ registerLattice(config: AgentConfig): void;
234
+ /**
235
+ * 获取AgentLattice
236
+ * @param key Lattice键名
237
+ */
238
+ getAgentLattice(key: string): AgentLattice | undefined;
239
+ /**
240
+ * 获取所有Lattice
241
+ */
242
+ getAllLattices(): AgentLattice[];
243
+ /**
244
+ * 检查Lattice是否存在
245
+ * @param key Lattice键名
246
+ */
247
+ hasLattice(key: string): boolean;
248
+ /**
249
+ * 移除Lattice
250
+ * @param key Lattice键名
251
+ */
252
+ removeLattice(key: string): boolean;
253
+ /**
254
+ * 获取Agent配置
255
+ * @param key Lattice键名
256
+ */
257
+ getAgentConfig(key: string): AgentConfig | undefined;
258
+ /**
259
+ * 获取所有Agent配置
260
+ */
261
+ getAllAgentConfigs(): AgentConfig[];
262
+ /**
263
+ * 验证Agent输入参数
264
+ * @param key Lattice键名
265
+ * @param input 输入参数
266
+ */
267
+ validateAgentInput(key: string, input: any): boolean;
268
+ /**
269
+ * 构建Agent参数
270
+ *
271
+ * @param agentLattice Agent Lattice对象
272
+ * @param options 构建选项
273
+ * @returns 返回Agent构建参数
274
+ */
275
+ private buildAgentParams;
276
+ /**
277
+ * 初始化Agent客户端
278
+ *
279
+ * 使用AgentGraphBuilderFactory构建Graph并设置为客户端
280
+ *
281
+ * @param key Lattice键名
282
+ * @param options 构建选项
283
+ * @returns 返回CompiledGraph对象
284
+ */
285
+ initializeClient(key: string, options?: GraphBuildOptions): AgentClient;
286
+ }
287
+ declare const agentLatticeManager: AgentLatticeManager;
288
+ declare const registerAgentLattice: (config: AgentConfig) => void;
289
+ declare const registerAgentLattices: (configs: AgentConfig[]) => void;
290
+ declare const getAgentLattice: (key: string) => AgentLattice | undefined;
291
+ declare const getAgentConfig: (key: string) => AgentConfig | undefined;
292
+ declare const getAllAgentConfigs: () => AgentConfig[];
293
+ declare const validateAgentInput: (key: string, input: any) => boolean;
294
+ /**
295
+ * 获取或初始化Agent客户端
296
+ *
297
+ * @param key Agent Lattice键名
298
+ * @param options 构建选项
299
+ * @returns 返回CompiledGraph对象
300
+ */
301
+ declare const getAgentClient: (key: string, options?: GraphBuildOptions) => AgentClient;
302
+
303
+ /**
304
+ * MemoryLatticeManager
305
+ *
306
+ * 记忆Lattice管理器,负责管理和注册检查点保存器
307
+ */
308
+
309
+ /**
310
+ * 记忆Lattice管理器类
311
+ */
312
+ declare class MemoryLatticeManager extends BaseLatticeManager {
313
+ private static instance;
314
+ private static checkpointSavers;
315
+ /**
316
+ * 私有构造函数,防止外部直接实例化
317
+ */
318
+ private constructor();
319
+ /**
320
+ * 获取单例实例
321
+ */
322
+ static getInstance(): MemoryLatticeManager;
323
+ /**
324
+ * 获取Lattice类型
325
+ */
326
+ protected getLatticeType(): string;
327
+ /**
328
+ * 注册检查点保存器
329
+ * @param key 保存器键名
330
+ * @param saver 检查点保存器实例
331
+ */
332
+ registerCheckpointSaver(key: string, saver: BaseCheckpointSaver): void;
333
+ /**
334
+ * 获取检查点保存器
335
+ * @param key 保存器键名
336
+ */
337
+ getCheckpointSaver(key: string): BaseCheckpointSaver;
338
+ /**
339
+ * 获取所有已注册的检查点保存器键名
340
+ */
341
+ getCheckpointSaverKeys(): string[];
342
+ /**
343
+ * 检查检查点保存器是否存在
344
+ * @param key 保存器键名
345
+ */
346
+ hasCheckpointSaver(key: string): boolean;
347
+ /**
348
+ * 移除检查点保存器
349
+ * @param key 保存器键名
350
+ */
351
+ removeCheckpointSaver(key: string): boolean;
352
+ }
353
+ declare const getCheckpointSaver: (key: string) => BaseCheckpointSaver<number>;
354
+ declare const registerCheckpointSaver: (key: string, saver: BaseCheckpointSaver) => void;
355
+
356
+ export { type AgentClient, type AgentLattice, AgentLatticeManager, MemoryLatticeManager, type ModelConfig, type ModelLatticeInterface, ModelLatticeManager, agentLatticeManager, getAgentClient, getAgentConfig, getAgentLattice, getAllAgentConfigs, getCheckpointSaver, getModelLattice, modelLatticeManager, registerAgentLattice, registerAgentLattices, registerCheckpointSaver, registerModelLattice, validateAgentInput };