@axiom-lattice/core 1.0.20 → 1.0.21

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 +5 -2
  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
@@ -1,86 +0,0 @@
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
- }
@@ -1,46 +0,0 @@
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
- }
@@ -1,46 +0,0 @@
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
- }
@@ -1,42 +0,0 @@
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
- }
@@ -1,14 +0,0 @@
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";
@@ -1,27 +0,0 @@
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";
@@ -1,42 +0,0 @@
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
- }
@@ -1,145 +0,0 @@
1
- /**
2
- * BaseLatticeManager - 抽象基类,为各种Lattice管理器提供通用功能
3
- * 使用统一的Lattice注册表,不同类型的Lattice通过前缀区分
4
- * @template TItem - 管理的项目类型
5
- */
6
- export abstract class BaseLatticeManager<TItem = any> {
7
- // 全局统一的Lattice注册表
8
- protected static registry: Map<string, any> = new Map();
9
-
10
- /**
11
- * 受保护的构造函数,防止外部直接实例化
12
- */
13
- protected constructor() {
14
- // 空实现
15
- }
16
-
17
- /**
18
- * 获取管理器实例(由子类实现)
19
- */
20
- public static getInstance(): BaseLatticeManager<any> {
21
- throw new Error("必须由子类实现");
22
- }
23
-
24
- /**
25
- * 获取Lattice类型,用于构造键前缀
26
- * 子类必须重写此方法以提供唯一的类型标识符
27
- */
28
- protected abstract getLatticeType(): string;
29
-
30
- /**
31
- * 构造完整的键名,包含类型前缀
32
- * @param key 原始键名
33
- */
34
- protected getFullKey(key: string): string {
35
- return `${this.getLatticeType()}.${key}`;
36
- }
37
-
38
- /**
39
- * 注册项目
40
- * @param key 项目键名(不含前缀)
41
- * @param item 项目实例
42
- */
43
- public register(key: string, item: TItem): void {
44
- const fullKey = this.getFullKey(key);
45
- if (BaseLatticeManager.registry.has(fullKey)) {
46
- throw new Error(`项目 "${fullKey}" 已经存在,无法重复注册`);
47
- }
48
-
49
- BaseLatticeManager.registry.set(fullKey, item);
50
- }
51
-
52
- /**
53
- * 获取指定项目
54
- * @param key 项目键名(不含前缀)
55
- */
56
- public get(key: string): TItem | undefined {
57
- const fullKey = this.getFullKey(key);
58
- return BaseLatticeManager.registry.get(fullKey) as TItem | undefined;
59
- }
60
-
61
- /**
62
- * 获取所有当前类型的项目
63
- */
64
- public getAll(): TItem[] {
65
- const prefix = `${this.getLatticeType()}.`;
66
- const result: TItem[] = [];
67
-
68
- for (const [key, value] of BaseLatticeManager.registry.entries()) {
69
- if (key.startsWith(prefix)) {
70
- result.push(value as TItem);
71
- }
72
- }
73
-
74
- return result;
75
- }
76
-
77
- /**
78
- * 检查项目是否存在
79
- * @param key 项目键名(不含前缀)
80
- */
81
- public has(key: string): boolean {
82
- const fullKey = this.getFullKey(key);
83
- return BaseLatticeManager.registry.has(fullKey);
84
- }
85
-
86
- /**
87
- * 移除项目
88
- * @param key 项目键名(不含前缀)
89
- */
90
- public remove(key: string): boolean {
91
- const fullKey = this.getFullKey(key);
92
- return BaseLatticeManager.registry.delete(fullKey);
93
- }
94
-
95
- /**
96
- * 清空当前类型的所有项目
97
- */
98
- public clear(): void {
99
- const prefix = `${this.getLatticeType()}.`;
100
- const keysToDelete: string[] = [];
101
-
102
- for (const key of BaseLatticeManager.registry.keys()) {
103
- if (key.startsWith(prefix)) {
104
- keysToDelete.push(key);
105
- }
106
- }
107
-
108
- for (const key of keysToDelete) {
109
- BaseLatticeManager.registry.delete(key);
110
- }
111
- }
112
-
113
- /**
114
- * 获取当前类型的项目数量
115
- */
116
- public count(): number {
117
- const prefix = `${this.getLatticeType()}.`;
118
- let count = 0;
119
-
120
- for (const key of BaseLatticeManager.registry.keys()) {
121
- if (key.startsWith(prefix)) {
122
- count++;
123
- }
124
- }
125
-
126
- return count;
127
- }
128
-
129
- /**
130
- * 获取当前类型的项目键名列表(不含前缀)
131
- */
132
- public keys(): string[] {
133
- const prefix = `${this.getLatticeType()}.`;
134
- const prefixLength = prefix.length;
135
- const result: string[] = [];
136
-
137
- for (const key of BaseLatticeManager.registry.keys()) {
138
- if (key.startsWith(prefix)) {
139
- result.push(key.substring(prefixLength));
140
- }
141
- }
142
-
143
- return result;
144
- }
145
- }
package/src/base/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./BaseLatticeManager";