@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,216 @@
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);
@@ -0,0 +1,79 @@
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
+ }
@@ -0,0 +1,22 @@
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
+ }
@@ -0,0 +1,70 @@
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
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Agent parameters builder
3
+ *
4
+ * responsible for preparing the parameters required for building the Agent
5
+ */
6
+
7
+ import { toolLatticeManager } from "../../tool_lattice/ToolLatticeManager";
8
+ import { modelLatticeManager } from "../../model_lattice/ModelLatticeManager";
9
+ import { AgentLattice, AgentBuildParams, GraphBuildOptions } from "../types";
10
+
11
+ /**
12
+ * Get Agent Lattice function type
13
+ */
14
+ export type GetAgentLatticeFunction = (key: string) => AgentLattice | undefined;
15
+
16
+ /**
17
+ * Agent parameters builder
18
+ */
19
+ export class AgentParamsBuilder {
20
+ private getAgentLatticeFunc: GetAgentLatticeFunction;
21
+
22
+ /**
23
+ * constructor
24
+ *
25
+ * @param getAgentLatticeFunc get Agent Lattice function
26
+ */
27
+ constructor(getAgentLatticeFunc: GetAgentLatticeFunction) {
28
+ this.getAgentLatticeFunc = getAgentLatticeFunc;
29
+ }
30
+
31
+ /**
32
+ * build Agent parameters
33
+ *
34
+ * @param agentLattice Agent Lattice object
35
+ * @param options build options
36
+ * @returns Agent build parameters
37
+ */
38
+ public buildParams(
39
+ agentLattice: AgentLattice,
40
+ options?: GraphBuildOptions
41
+ ): AgentBuildParams {
42
+ // get tools
43
+ const toolKeys = options?.overrideTools || agentLattice.config.tools || [];
44
+ const tools = toolKeys.map((toolKey: string) => {
45
+ const toolLattice = toolLatticeManager.getToolLattice(toolKey);
46
+ if (!toolLattice) {
47
+ throw new Error(`Tool "${toolKey}" does not exist`);
48
+ }
49
+ return {
50
+ key: toolKey,
51
+ definition: toolLattice.config,
52
+ executor: toolLattice.client,
53
+ };
54
+ });
55
+
56
+ // get model
57
+ const modelKey = options?.overrideModel || agentLattice.config.modelKey;
58
+ const model = modelKey
59
+ ? modelLatticeManager.getModelLattice(modelKey).client
60
+ : modelLatticeManager.getModelLattice("default").client;
61
+ if (!model) {
62
+ throw new Error(`Model "${modelKey}" does not exist`);
63
+ }
64
+
65
+ // get subAgents
66
+ const subAgentKeys = agentLattice.config.subAgents || [];
67
+ const subAgents = subAgentKeys.map((agentKey: string) => {
68
+ const subAgentLattice = this.getAgentLatticeFunc(agentKey);
69
+ if (!subAgentLattice) {
70
+ throw new Error(`SubAgent "${agentKey}" does not exist`);
71
+ }
72
+ return {
73
+ key: agentKey,
74
+ config: subAgentLattice.config,
75
+ client: subAgentLattice.client,
76
+ };
77
+ });
78
+
79
+ return {
80
+ tools,
81
+ model,
82
+ subAgents,
83
+ prompt: agentLattice.config.prompt,
84
+ };
85
+ }
86
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Deep Agent Graph Builder
3
+ *
4
+ * 实现 Deep Agent 类型的 Agent Graph 构建
5
+ */
6
+
7
+ import { CompiledStateGraph } from "@langchain/langgraph";
8
+ import { DynamicTool } from "@langchain/core/tools";
9
+ import { createDeepAgent } from "../../deep_agent";
10
+ import { AgentLattice, AgentBuildParams } from "../types";
11
+ import { AgentGraphBuilder } from "./AgentGraphBuilder";
12
+ import { getToolClient } from "../../tool_lattice/ToolLatticeManager";
13
+
14
+ export class DeepAgentGraphBuilder implements AgentGraphBuilder {
15
+ /**
16
+ * 构建Deep Agent Graph
17
+ *
18
+ * @param agentLattice Agent Lattice对象
19
+ * @param params Agent构建参数
20
+ * @returns 返回CompiledGraph对象
21
+ */
22
+ build(
23
+ agentLattice: AgentLattice,
24
+ params: AgentBuildParams
25
+ ): CompiledStateGraph<any, any, any, any, any> {
26
+ const tools = params.tools
27
+ .map((t) => {
28
+ const toolClient = getToolClient(t.key);
29
+
30
+ return toolClient;
31
+ })
32
+ .filter((tool) => tool !== undefined);
33
+
34
+ return createDeepAgent({
35
+ tools: tools,
36
+ model: params.model,
37
+ instructions: params.prompt,
38
+ subagents: params.subAgents.map((sa) => ({
39
+ name: sa.key,
40
+ description: sa.config.description,
41
+ prompt: sa.config.prompt,
42
+ tools: sa.config.tools || [],
43
+ })),
44
+ });
45
+ }
46
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Plan Execute Agent Graph Builder
3
+ *
4
+ * 实现 Plan Execute 类型的 Agent Graph 构建
5
+ */
6
+
7
+ import { CompiledStateGraph } from "@langchain/langgraph";
8
+ import { DynamicTool } from "@langchain/core/tools";
9
+ import { AgentLattice, AgentBuildParams } from "../types";
10
+ import { AgentGraphBuilder } from "./AgentGraphBuilder";
11
+ import { getToolClient } from "../../tool_lattice/ToolLatticeManager";
12
+ import { createPlanExecuteAgent } from "@createPlanExecuteAgent";
13
+
14
+ export class PlanExecuteAgentGraphBuilder implements AgentGraphBuilder {
15
+ /**
16
+ * 构建Plan Execute Agent Graph
17
+ *
18
+ * @param agentLattice Agent Lattice对象
19
+ * @param params Agent构建参数
20
+ * @returns 返回CompiledGraph对象
21
+ */
22
+ build(
23
+ agentLattice: AgentLattice,
24
+ params: AgentBuildParams
25
+ ): CompiledStateGraph<any, any, any, any, any> {
26
+ // 创建符合 DynamicTool 接口的工具对象
27
+ const tools = params.tools
28
+ .map((t) => {
29
+ // 使用 DynamicTool 构造工具对象
30
+ const tool = getToolClient(t.key);
31
+ return tool;
32
+ })
33
+ .filter((tool) => tool !== undefined);
34
+
35
+ // 由于createPlanExecuteAgent的返回类型与CompiledStateGraph不兼容
36
+ // 这里我们使用createAgentExecutor作为替代方案
37
+ const agent = createPlanExecuteAgent({
38
+ llmManager: params.model,
39
+ tools: tools,
40
+ prompt: params.prompt,
41
+ name: agentLattice.config.name,
42
+ description: agentLattice.config.description,
43
+ });
44
+ return agent.getCompiledGraph();
45
+ }
46
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * ReAct Agent Graph Builder
3
+ *
4
+ * 实现 ReAct 类型的 Agent Graph 构建
5
+ */
6
+
7
+ import { CompiledStateGraph } from "@langchain/langgraph";
8
+ import { DynamicTool } from "@langchain/core/tools";
9
+ import { AgentLattice, AgentBuildParams } from "../types";
10
+ import { AgentGraphBuilder } from "./AgentGraphBuilder";
11
+ import { getToolClient } from "../../tool_lattice/ToolLatticeManager";
12
+ import { createReactAgent } from "@langchain/langgraph/prebuilt";
13
+
14
+ export class ReActAgentGraphBuilder implements AgentGraphBuilder {
15
+ /**
16
+ * 构建ReAct Agent Graph
17
+ *
18
+ * @param agentLattice Agent Lattice对象
19
+ * @param params Agent构建参数
20
+ * @returns 返回CompiledGraph对象
21
+ */
22
+ build(
23
+ agentLattice: AgentLattice,
24
+ params: AgentBuildParams
25
+ ): CompiledStateGraph<any, any, any, any, any> {
26
+ // 创建符合 DynamicTool 接口的工具对象
27
+ const tools = params.tools
28
+ .map((t) => {
29
+ // 使用 DynamicTool 构造工具对象
30
+ const tool = getToolClient(t.key);
31
+ return tool;
32
+ })
33
+ .filter((tool) => tool !== undefined);
34
+
35
+ return createReactAgent({
36
+ llm: params.model,
37
+ tools: tools,
38
+ prompt: params.prompt,
39
+ name: agentLattice.config.name,
40
+ });
41
+ }
42
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Agent Builder 模块
3
+ *
4
+ * 提供构建Agent Graph的各种Builder和工具
5
+ */
6
+
7
+ // 导出接口
8
+ export { AgentGraphBuilder } from "./AgentGraphBuilder";
9
+ export { GetAgentLatticeFunction } from "./AgentParamsBuilder";
10
+
11
+ // 导出工厂和工具类
12
+ export { AgentGraphBuilderFactory } from "./AgentGraphBuilderFactory";
13
+ export { AgentParamsBuilder } from "./AgentParamsBuilder";
14
+ export { AgentBuilder } from "./AgentBuilder";
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Agent Lattice模块
3
+ *
4
+ * 提供Agent Lattice的管理和Graph构建功能
5
+ */
6
+
7
+ // 导出类型定义
8
+ export {
9
+ AgentType,
10
+ AgentConfig,
11
+ AgentClient,
12
+ AgentLattice,
13
+ GraphBuildOptions,
14
+ } from "./types";
15
+
16
+ // 导出AgentLatticeManager相关内容
17
+ export {
18
+ AgentLatticeManager,
19
+ agentLatticeManager,
20
+ registerAgentLattice,
21
+ registerAgentLattices,
22
+ getAgentLattice,
23
+ getAgentConfig,
24
+ getAllAgentConfigs,
25
+ validateAgentInput,
26
+ getAgentClient,
27
+ } from "./AgentLatticeManager";
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Agent Lattice 类型定义
3
+ *
4
+ * 包含Agent Lattice相关的所有类型定义,供其他模块共享使用
5
+ */
6
+
7
+ import { z } from "zod";
8
+ import { ModelLattice } from "@model_lattice/ModelLattice";
9
+ import { CompiledStateGraph } from "@langchain/langgraph";
10
+ import {
11
+ AgentType,
12
+ AgentConfig,
13
+ GraphBuildOptions,
14
+ } from "@axiom-lattice/protocols";
15
+
16
+ // Re-export types from protocols
17
+ export { AgentType, AgentConfig, GraphBuildOptions };
18
+
19
+ // Agent客户端类型 - CompiledStateGraph
20
+ export type AgentClient = CompiledStateGraph<any, any, any, any, any>;
21
+
22
+ // AgentLattice接口定义
23
+ export interface AgentLattice {
24
+ config: AgentConfig;
25
+ client: AgentClient | undefined;
26
+ }
27
+
28
+ // Agent构建参数接口
29
+ export interface AgentBuildParams {
30
+ tools: Array<{
31
+ key: string;
32
+ definition: any;
33
+ executor: any;
34
+ }>;
35
+ model: ModelLattice;
36
+ subAgents: Array<{
37
+ key: string;
38
+ config: AgentConfig;
39
+ client: AgentClient | undefined;
40
+ }>;
41
+ prompt: string;
42
+ }