@axiom-lattice/core 1.0.20 → 1.0.22

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 (51) hide show
  1. package/package.json +6 -3
  2. package/.eslintrc.json +0 -22
  3. package/.turbo/turbo-build.log +0 -21
  4. package/jest.config.js +0 -21
  5. package/src/__tests__/AgentManager.test.ts +0 -202
  6. package/src/__tests__/setup.ts +0 -5
  7. package/src/agent_lattice/AgentLatticeManager.ts +0 -216
  8. package/src/agent_lattice/builders/AgentBuilder.ts +0 -79
  9. package/src/agent_lattice/builders/AgentGraphBuilder.ts +0 -22
  10. package/src/agent_lattice/builders/AgentGraphBuilderFactory.ts +0 -70
  11. package/src/agent_lattice/builders/AgentParamsBuilder.ts +0 -86
  12. package/src/agent_lattice/builders/DeepAgentGraphBuilder.ts +0 -46
  13. package/src/agent_lattice/builders/PlanExecuteAgentGraphBuilder.ts +0 -46
  14. package/src/agent_lattice/builders/ReActAgentGraphBuilder.ts +0 -42
  15. package/src/agent_lattice/builders/index.ts +0 -14
  16. package/src/agent_lattice/index.ts +0 -27
  17. package/src/agent_lattice/types.ts +0 -42
  18. package/src/base/BaseLatticeManager.ts +0 -145
  19. package/src/base/index.ts +0 -1
  20. package/src/createPlanExecuteAgent.ts +0 -475
  21. package/src/deep_agent/graph.ts +0 -106
  22. package/src/deep_agent/index.ts +0 -25
  23. package/src/deep_agent/prompts.ts +0 -284
  24. package/src/deep_agent/state.ts +0 -63
  25. package/src/deep_agent/subAgent.ts +0 -185
  26. package/src/deep_agent/tools.ts +0 -273
  27. package/src/deep_agent/types.ts +0 -71
  28. package/src/index.ts +0 -9
  29. package/src/logger/Logger.ts +0 -186
  30. package/src/memory_lattice/DefaultMemorySaver.ts +0 -4
  31. package/src/memory_lattice/MemoryLatticeManager.ts +0 -105
  32. package/src/memory_lattice/index.ts +0 -9
  33. package/src/model_lattice/ModelLattice.ts +0 -208
  34. package/src/model_lattice/ModelLatticeManager.ts +0 -125
  35. package/src/model_lattice/index.ts +0 -1
  36. package/src/tool_lattice/ToolLatticeManager.ts +0 -221
  37. package/src/tool_lattice/get_current_date_time/index.ts +0 -14
  38. package/src/tool_lattice/index.ts +0 -2
  39. package/src/tool_lattice/internet_search/index.ts +0 -66
  40. package/src/types.ts +0 -28
  41. package/src/util/PGMemory.ts +0 -16
  42. package/src/util/genUICard.ts +0 -3
  43. package/src/util/genUIMarkdown.ts +0 -3
  44. package/src/util/getLastHumanMessageData.ts +0 -41
  45. package/src/util/returnAIResponse.ts +0 -30
  46. package/src/util/returnErrorResponse.ts +0 -26
  47. package/src/util/returnFeedbackResponse.ts +0 -25
  48. package/src/util/returnToolResponse.ts +0 -32
  49. package/src/util/withAgentName.ts +0 -220
  50. package/src/util/zod-to-prompt.ts +0 -50
  51. package/tsconfig.json +0 -26
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@axiom-lattice/core",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
7
10
  "exports": {
8
11
  ".": {
9
12
  "types": "./dist/index.d.ts",
@@ -18,7 +21,7 @@
18
21
  "dependencies": {
19
22
  "@langchain/core": "^0.3.72",
20
23
  "@langchain/deepseek": "^0.1.0",
21
- "@langchain/langgraph": "^0.4.6",
24
+ "@langchain/langgraph": "^0.4.9",
22
25
  "@langchain/langgraph-checkpoint": "^0.1.1",
23
26
  "@langchain/langgraph-checkpoint-postgres": "^0.1.1",
24
27
  "@langchain/openai": "^0.6.9",
@@ -33,7 +36,7 @@
33
36
  "uuid": "^9.0.1",
34
37
  "zod": "^3.24.2",
35
38
  "zod-to-json-schema": "^3.24.3",
36
- "@axiom-lattice/protocols": "1.0.20"
39
+ "@axiom-lattice/protocols": "1.0.22"
37
40
  },
38
41
  "devDependencies": {
39
42
  "@types/jest": "^29.5.14",
package/.eslintrc.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "root": true,
3
- "env": {
4
- "node": true,
5
- "es2021": true
6
- },
7
- "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
8
- "parser": "@typescript-eslint/parser",
9
- "parserOptions": {
10
- "ecmaVersion": 12,
11
- "sourceType": "module"
12
- },
13
- "plugins": ["@typescript-eslint"],
14
- "rules": {
15
- "indent": "off", // 禁用缩进规则
16
- "linebreak-style": ["warn", "unix"],
17
- "semi": ["warn", "always"],
18
- "no-unused-vars": "off",
19
- "@typescript-eslint/no-unused-vars": ["warn"],
20
- "@typescript-eslint/no-explicit-any": "off" // 禁用对 any 类型的检查
21
- }
22
- }
@@ -1,21 +0,0 @@
1
-
2
- > @axiom-lattice/core@1.0.10 build /home/runner/work/agentic/agentic/packages/core
3
- > tsup src/index.ts --format cjs,esm --dts --clean --sourcemap
4
-
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.5.0
8
- CLI Target: es2020
9
- CLI Cleaning output folder
10
- CJS Build start
11
- ESM Build start
12
- CJS dist/index.js 71.87 KB
13
- CJS dist/index.js.map 125.81 KB
14
- CJS ⚡️ Build success in 201ms
15
- ESM dist/index.mjs 67.73 KB
16
- ESM dist/index.mjs.map 125.90 KB
17
- ESM ⚡️ Build success in 199ms
18
- DTS Build start
19
- DTS ⚡️ Build success in 9506ms
20
- DTS dist/index.d.ts 9.15 KB
21
- DTS dist/index.d.mts 9.15 KB
package/jest.config.js DELETED
@@ -1,21 +0,0 @@
1
- module.exports = {
2
- preset: "ts-jest",
3
- testEnvironment: "node",
4
- roots: ["<rootDir>/src"],
5
- testMatch: ["**/__tests__/**/*.test.ts", "**/?(*.)+(spec|test).ts"],
6
- transform: {
7
- "^.+\\.ts$": [
8
- "ts-jest",
9
- {
10
- isolatedModules: true,
11
- },
12
- ],
13
- },
14
- moduleNameMapper: {
15
- "^@/(.*)$": "<rootDir>/src/$1",
16
- "^@utils/(.*)$": "<rootDir>/src/utils/$1",
17
- },
18
- collectCoverageFrom: ["src/**/*.ts", "!src/**/*.d.ts", "!src/__tests__/**/*"],
19
- coverageReporters: ["text", "lcov", "html"],
20
- testTimeout: 30000,
21
- };
@@ -1,202 +0,0 @@
1
- import { AgentManager, agentManager, AgentDefinition } from "../AgentManager";
2
- import { CompiledStateGraph } from "@langchain/langgraph";
3
-
4
- // 模拟编译后的状态图
5
- const mockExecutor = {
6
- invoke: jest.fn().mockResolvedValue({ result: "success" }),
7
- } as unknown as CompiledStateGraph<any, any, any, any, any, any>;
8
-
9
- describe("AgentManager", () => {
10
- let manager: AgentManager;
11
-
12
- beforeEach(() => {
13
- // 获取单例实例
14
- manager = AgentManager.getInstance();
15
- // 清空代理
16
- manager.clearAgents();
17
- // 重置模拟函数
18
- jest.clearAllMocks();
19
- });
20
-
21
- describe("单例模式", () => {
22
- it("应该返回相同的实例", () => {
23
- const instance1 = AgentManager.getInstance();
24
- const instance2 = AgentManager.getInstance();
25
- expect(instance1).toBe(instance2);
26
- });
27
-
28
- it("应该返回相同的agentManager实例", () => {
29
- expect(agentManager).toBe(manager);
30
- });
31
- });
32
-
33
- describe("代理注册", () => {
34
- const testAgentDefinition: AgentDefinition = {
35
- name: "测试代理",
36
- description: "用于测试的代理",
37
- agent_type: "test",
38
- agent_config: { model: "test-model" },
39
- agent_tools: ["tool1", "tool2"],
40
- agent_flow: ["start", "end"],
41
- };
42
-
43
- it("应该能够注册代理", () => {
44
- manager.registerAgent(testAgentDefinition, mockExecutor, [
45
- "tool1",
46
- "tool2",
47
- ]);
48
- expect(manager.hasAgent("测试代理")).toBe(true);
49
- expect(manager.getAgentCount()).toBe(1);
50
- });
51
-
52
- it("应该防止重复注册同名代理", () => {
53
- manager.registerAgent(testAgentDefinition, mockExecutor, [
54
- "tool1",
55
- "tool2",
56
- ]);
57
-
58
- expect(() => {
59
- manager.registerAgent(testAgentDefinition, mockExecutor, [
60
- "tool1",
61
- "tool2",
62
- ]);
63
- }).toThrow('代理 "测试代理" 已经存在,无法重复注册');
64
- });
65
-
66
- it("应该能够批量注册代理", () => {
67
- const agent1 = {
68
- definition: { ...testAgentDefinition, name: "代理1" },
69
- executor: mockExecutor,
70
- tools: ["tool1"],
71
- };
72
- const agent2 = {
73
- definition: { ...testAgentDefinition, name: "代理2" },
74
- executor: mockExecutor,
75
- tools: ["tool2"],
76
- };
77
-
78
- manager.registerAgents([agent1, agent2]);
79
- expect(manager.getAgentCount()).toBe(2);
80
- expect(manager.hasAgent("代理1")).toBe(true);
81
- expect(manager.hasAgent("代理2")).toBe(true);
82
- });
83
- });
84
-
85
- describe("代理管理", () => {
86
- const testAgents = [
87
- {
88
- definition: {
89
- name: "代理1",
90
- description: "第一个代理",
91
- agent_type: "test",
92
- agent_config: {},
93
- agent_tools: [],
94
- agent_flow: ["start", "end"],
95
- },
96
- executor: mockExecutor,
97
- tools: [],
98
- },
99
- {
100
- definition: {
101
- name: "代理2",
102
- description: "第二个代理",
103
- agent_type: "test",
104
- agent_config: {},
105
- agent_tools: [],
106
- agent_flow: ["start", "end"],
107
- },
108
- executor: mockExecutor,
109
- tools: [],
110
- },
111
- ];
112
-
113
- beforeEach(() => {
114
- manager.registerAgents(testAgents);
115
- });
116
-
117
- it("应该能够获取代理定义", () => {
118
- const definition = manager.getAgentDefinition("代理1");
119
- expect(definition).toBeDefined();
120
- expect(definition?.name).toBe("代理1");
121
- });
122
-
123
- it("应该能够获取所有代理定义", () => {
124
- const definitions = manager.getAllAgentDefinitions();
125
- expect(definitions).toHaveLength(2);
126
- expect(definitions.map((d) => d.name)).toEqual(["代理1", "代理2"]);
127
- });
128
-
129
- it("应该能够获取代理名称列表", () => {
130
- const names = manager.getAgentNames();
131
- expect(names).toEqual(["代理1", "代理2"]);
132
- });
133
-
134
- it("应该能够移除代理", () => {
135
- expect(manager.removeAgent("代理1")).toBe(true);
136
- expect(manager.hasAgent("代理1")).toBe(false);
137
- expect(manager.getAgentCount()).toBe(1);
138
- });
139
-
140
- it("应该能够清空所有代理", () => {
141
- manager.clearAgents();
142
- expect(manager.getAgentCount()).toBe(0);
143
- expect(manager.getAgentNames()).toHaveLength(0);
144
- });
145
-
146
- it("应该能够检查代理是否存在", () => {
147
- expect(manager.hasAgent("代理1")).toBe(true);
148
- expect(manager.hasAgent("不存在的代理")).toBe(false);
149
- });
150
- });
151
-
152
- describe("代理查询", () => {
153
- const testAgentDefinition: AgentDefinition = {
154
- name: "查询测试代理",
155
- description: "用于查询测试的代理",
156
- agent_type: "test",
157
- agent_config: {},
158
- agent_tools: ["tool1"],
159
- agent_flow: ["start", "end"],
160
- };
161
-
162
- beforeEach(() => {
163
- manager.registerAgent(testAgentDefinition, mockExecutor, ["tool1"]);
164
- });
165
-
166
- it("应该能够获取代理执行器", () => {
167
- const executor = manager.getAgentExecutor("查询测试代理");
168
- expect(executor).toBeDefined();
169
- expect(executor).toBe(mockExecutor);
170
- });
171
-
172
- it("应该能够获取代理工具列表", () => {
173
- const tools = manager.getAgentTools("查询测试代理");
174
- expect(tools).toEqual(["tool1"]);
175
- });
176
-
177
- it("应该返回undefined当代理不存在", () => {
178
- const executor = manager.getAgentExecutor("不存在的代理");
179
- const tools = manager.getAgentTools("不存在的代理");
180
- expect(executor).toBeUndefined();
181
- expect(tools).toEqual([]);
182
- });
183
- });
184
-
185
- describe("便捷函数", () => {
186
- it("应该能够通过便捷函数注册代理", () => {
187
- const { registerAgent } = require("../AgentManager");
188
-
189
- const agentDef: AgentDefinition = {
190
- name: "便捷函数测试代理",
191
- description: "测试便捷函数",
192
- agent_type: "test",
193
- agent_config: {},
194
- agent_tools: [],
195
- agent_flow: ["start", "end"],
196
- };
197
-
198
- registerAgent(agentDef, mockExecutor, []);
199
- expect(agentManager.hasAgent("便捷函数测试代理")).toBe(true);
200
- });
201
- });
202
- });
@@ -1,5 +0,0 @@
1
- // 全局测试设置文件
2
- // 这个文件会在所有测试运行前执行
3
-
4
- // 设置Node.js环境变量
5
- process.env.NODE_ENV = "test";
@@ -1,216 +0,0 @@
1
- import { BaseLatticeManager } from "../base/BaseLatticeManager";
2
- import {
3
- AgentConfig,
4
- AgentClient,
5
- AgentLattice,
6
- GraphBuildOptions,
7
- AgentBuildParams,
8
- } from "./types";
9
- import { AgentGraphBuilderFactory } from "./builders/AgentGraphBuilderFactory";
10
- import { AgentParamsBuilder } from "./builders/AgentParamsBuilder";
11
-
12
- // 类型定义已移至 ./types.ts
13
-
14
- /**
15
- * AgentLatticeManager - 单例Agent Lattice管理器
16
- * 负责注册、管理各种Agent Lattice
17
- */
18
- export class AgentLatticeManager extends BaseLatticeManager<AgentLattice> {
19
- private static _instance: AgentLatticeManager;
20
-
21
- /**
22
- * 获取AgentLatticeManager单例实例
23
- */
24
- public static getInstance(): AgentLatticeManager {
25
- if (!AgentLatticeManager._instance) {
26
- AgentLatticeManager._instance = new AgentLatticeManager();
27
- }
28
- return AgentLatticeManager._instance;
29
- }
30
-
31
- /**
32
- * 获取Lattice类型前缀
33
- */
34
- protected getLatticeType(): string {
35
- return "agents";
36
- }
37
-
38
- /**
39
- * 注册Agent Lattice
40
- * @param config Agent配置
41
- */
42
- public registerLattice(config: AgentConfig): void {
43
- // 创建Agent Lattice对象
44
- const agentLattice: AgentLattice = {
45
- config,
46
- client: undefined, // 客户端将在需要时由initializeClient创建
47
- };
48
-
49
- // 调用基类的register方法
50
- this.register(config.key, agentLattice);
51
- }
52
-
53
- /**
54
- * 获取AgentLattice
55
- * @param key Lattice键名
56
- */
57
- public getAgentLattice(key: string): AgentLattice | undefined {
58
- return this.get(key);
59
- }
60
-
61
- /**
62
- * 获取所有Lattice
63
- */
64
- public getAllLattices(): AgentLattice[] {
65
- return this.getAll();
66
- }
67
-
68
- /**
69
- * 检查Lattice是否存在
70
- * @param key Lattice键名
71
- */
72
- public hasLattice(key: string): boolean {
73
- return this.has(key);
74
- }
75
-
76
- /**
77
- * 移除Lattice
78
- * @param key Lattice键名
79
- */
80
- public removeLattice(key: string): boolean {
81
- return this.remove(key);
82
- }
83
-
84
- /**
85
- * 获取Agent配置
86
- * @param key Lattice键名
87
- */
88
- public getAgentConfig(key: string): AgentConfig | undefined {
89
- return this.getAgentLattice(key)?.config;
90
- }
91
-
92
- /**
93
- * 获取所有Agent配置
94
- */
95
- public getAllAgentConfigs(): AgentConfig[] {
96
- return this.getAllLattices().map((lattice) => lattice.config);
97
- }
98
-
99
- /**
100
- * 验证Agent输入参数
101
- * @param key Lattice键名
102
- * @param input 输入参数
103
- */
104
- public validateAgentInput(key: string, input: any): boolean {
105
- const agentLattice = this.getAgentLattice(key);
106
- if (!agentLattice) {
107
- return false;
108
- }
109
-
110
- try {
111
- if (agentLattice.config.schema) {
112
- agentLattice.config.schema.parse(input);
113
- }
114
- return true;
115
- } catch {
116
- return false;
117
- }
118
- }
119
-
120
- /**
121
- * 构建Agent参数
122
- *
123
- * @param agentLattice Agent Lattice对象
124
- * @param options 构建选项
125
- * @returns 返回Agent构建参数
126
- */
127
- private buildAgentParams(
128
- agentLattice: AgentLattice,
129
- options?: GraphBuildOptions
130
- ): AgentBuildParams {
131
- // 创建参数构建器
132
- const paramsBuilder = new AgentParamsBuilder((key: string) =>
133
- this.getAgentLattice(key)
134
- );
135
-
136
- // 构建参数
137
- return paramsBuilder.buildParams(agentLattice, options);
138
- }
139
-
140
- /**
141
- * 初始化Agent客户端
142
- *
143
- * 使用AgentGraphBuilderFactory构建Graph并设置为客户端
144
- *
145
- * @param key Lattice键名
146
- * @param options 构建选项
147
- * @returns 返回CompiledGraph对象
148
- */
149
- public initializeClient(
150
- key: string,
151
- options?: GraphBuildOptions
152
- ): AgentClient {
153
- const agentLattice = this.getAgentLattice(key);
154
- if (!agentLattice) {
155
- throw new Error(`Agent Lattice "${key}" 不存在`);
156
- }
157
-
158
- // 如果客户端已经存在,直接返回
159
- if (agentLattice.client) {
160
- return agentLattice.client;
161
- }
162
-
163
- // 获取工厂实例
164
- const factory = AgentGraphBuilderFactory.getInstance();
165
-
166
- // 获取对应类型的Builder
167
- const builder = factory.getBuilder(agentLattice.config.type);
168
-
169
- // 构建参数
170
- const params = this.buildAgentParams(agentLattice, options);
171
-
172
- // 使用Builder构建Graph
173
- const graph = builder.build(agentLattice, params);
174
-
175
- // 设置为客户端
176
- agentLattice.client = graph;
177
-
178
- return graph;
179
- }
180
- }
181
-
182
- // 导出单例实例
183
- export const agentLatticeManager = AgentLatticeManager.getInstance();
184
-
185
- // 导出便捷方法
186
- export const registerAgentLattice = (config: AgentConfig) => {
187
- agentLatticeManager.registerLattice(config);
188
- };
189
-
190
- export const registerAgentLattices = (configs: AgentConfig[]) => {
191
- configs.forEach((config) => {
192
- agentLatticeManager.registerLattice(config);
193
- });
194
- };
195
-
196
- export const getAgentLattice = (key: string) =>
197
- agentLatticeManager.getAgentLattice(key);
198
-
199
- export const getAgentConfig = (key: string) =>
200
- agentLatticeManager.getAgentConfig(key);
201
-
202
- export const getAllAgentConfigs = () =>
203
- agentLatticeManager.getAllAgentConfigs();
204
-
205
- export const validateAgentInput = (key: string, input: any) =>
206
- agentLatticeManager.validateAgentInput(key, input);
207
-
208
- /**
209
- * 获取或初始化Agent客户端
210
- *
211
- * @param key Agent Lattice键名
212
- * @param options 构建选项
213
- * @returns 返回CompiledGraph对象
214
- */
215
- export const getAgentClient = (key: string, options?: GraphBuildOptions) =>
216
- agentLatticeManager.initializeClient(key, options);
@@ -1,79 +0,0 @@
1
- /**
2
- * Agent Builder 服务
3
- *
4
- * 提供构建和执行Agent的功能
5
- */
6
-
7
- import { CompiledStateGraph } from "@langchain/langgraph";
8
- import { AgentLattice, GraphBuildOptions } from "../types";
9
- import { AgentGraphBuilderFactory } from "./AgentGraphBuilderFactory";
10
- import {
11
- AgentParamsBuilder,
12
- GetAgentLatticeFunction,
13
- } from "./AgentParamsBuilder";
14
-
15
- /**
16
- * Agent Builder 服务
17
- */
18
- export class AgentBuilder {
19
- private graphBuilderFactory: AgentGraphBuilderFactory;
20
- private paramsBuilder: AgentParamsBuilder;
21
-
22
- /**
23
- * 构造函数
24
- *
25
- * @param getAgentLatticeFunc 获取Agent Lattice的函数
26
- */
27
- constructor(getAgentLatticeFunc: GetAgentLatticeFunction) {
28
- this.graphBuilderFactory = AgentGraphBuilderFactory.getInstance();
29
- this.paramsBuilder = new AgentParamsBuilder(getAgentLatticeFunc);
30
- }
31
-
32
- /**
33
- * 构建Agent Graph
34
- *
35
- * @param agentLattice Agent Lattice对象
36
- * @param options 构建选项
37
- * @returns 返回CompiledGraph对象
38
- */
39
- public buildGraph(
40
- agentLattice: AgentLattice,
41
- options?: GraphBuildOptions
42
- ): CompiledStateGraph<any, any, any, any, any> {
43
- // 准备构建参数
44
- const buildParams = this.paramsBuilder.buildParams(agentLattice, options);
45
-
46
- // 获取对应的Builder
47
- const builder = this.graphBuilderFactory.getBuilder(
48
- agentLattice.config.type
49
- );
50
-
51
- // 构建Graph
52
- return builder.build(agentLattice, buildParams);
53
- }
54
-
55
- /**
56
- * 执行Agent
57
- *
58
- * @param agentLattice Agent Lattice对象
59
- * @param input 输入参数
60
- * @param options 执行选项
61
- * @returns 返回执行结果
62
- */
63
- public async execute<TInput = any, TOutput = any>(
64
- agentLattice: AgentLattice,
65
- input: TInput,
66
- options?: GraphBuildOptions & { sessionId?: string }
67
- ): Promise<TOutput> {
68
- // 构建Graph
69
- const graph = this.buildGraph(agentLattice, options);
70
-
71
- // 执行Graph
72
- const config: any = {};
73
- if (options?.metadata) {
74
- config.metadata = options.metadata;
75
- }
76
-
77
- return (await graph.invoke({ input }, config)) as TOutput;
78
- }
79
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Agent Graph Builder 接口
3
- *
4
- * 策略模式的核心接口,定义了构建Agent Graph的方法
5
- */
6
-
7
- import { CompiledStateGraph } from "@langchain/langgraph";
8
- import { AgentLattice, AgentBuildParams } from "../types";
9
-
10
- export interface AgentGraphBuilder {
11
- /**
12
- * 构建Agent Graph
13
- *
14
- * @param agentLattice Agent Lattice对象
15
- * @param params Agent构建参数
16
- * @returns 返回CompiledGraph对象
17
- */
18
- build(
19
- agentLattice: AgentLattice,
20
- params: AgentBuildParams
21
- ): CompiledStateGraph<any, any, any, any, any>;
22
- }
@@ -1,70 +0,0 @@
1
- /**
2
- * Agent Graph Builder Factory
3
- *
4
- * 工厂类,根据Agent类型创建对应的Builder
5
- */
6
-
7
- import { AgentType } from "../types";
8
- import { AgentGraphBuilder } from "./AgentGraphBuilder";
9
- import { ReActAgentGraphBuilder } from "./ReActAgentGraphBuilder";
10
- import { DeepAgentGraphBuilder } from "./DeepAgentGraphBuilder";
11
- import { PlanExecuteAgentGraphBuilder } from "./PlanExecuteAgentGraphBuilder";
12
-
13
- export class AgentGraphBuilderFactory {
14
- // 单例模式
15
- private static instance: AgentGraphBuilderFactory;
16
-
17
- // Builder缓存
18
- private builders: Map<AgentType, AgentGraphBuilder>;
19
-
20
- private constructor() {
21
- this.builders = new Map();
22
- this.registerDefaultBuilders();
23
- }
24
-
25
- /**
26
- * 获取单例实例
27
- */
28
- public static getInstance(): AgentGraphBuilderFactory {
29
- if (!AgentGraphBuilderFactory.instance) {
30
- AgentGraphBuilderFactory.instance = new AgentGraphBuilderFactory();
31
- }
32
- return AgentGraphBuilderFactory.instance;
33
- }
34
-
35
- /**
36
- * 注册默认的Builder
37
- */
38
- private registerDefaultBuilders(): void {
39
- this.builders.set(AgentType.REACT, new ReActAgentGraphBuilder());
40
- this.builders.set(AgentType.DEEP_AGENT, new DeepAgentGraphBuilder());
41
- this.builders.set(
42
- AgentType.PLAN_EXECUTE,
43
- new PlanExecuteAgentGraphBuilder()
44
- );
45
- }
46
-
47
- /**
48
- * 注册自定义Builder
49
- *
50
- * @param type Agent类型
51
- * @param builder Builder实例
52
- */
53
- public registerBuilder(type: AgentType, builder: AgentGraphBuilder): void {
54
- this.builders.set(type, builder);
55
- }
56
-
57
- /**
58
- * 获取Builder
59
- *
60
- * @param type Agent类型
61
- * @returns 返回对应的Builder
62
- */
63
- public getBuilder(type: AgentType): AgentGraphBuilder {
64
- const builder = this.builders.get(type);
65
- if (!builder) {
66
- throw new Error(`不支持的Agent类型: ${type}`);
67
- }
68
- return builder;
69
- }
70
- }