@axiom-lattice/core 1.0.13 → 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 (52) hide show
  1. package/LICENSE +201 -0
  2. package/package.json +16 -13
  3. package/.eslintrc.json +0 -22
  4. package/.turbo/turbo-build.log +0 -21
  5. package/jest.config.js +0 -21
  6. package/src/__tests__/AgentManager.test.ts +0 -202
  7. package/src/__tests__/setup.ts +0 -5
  8. package/src/agent_lattice/AgentLatticeManager.ts +0 -216
  9. package/src/agent_lattice/builders/AgentBuilder.ts +0 -79
  10. package/src/agent_lattice/builders/AgentGraphBuilder.ts +0 -22
  11. package/src/agent_lattice/builders/AgentGraphBuilderFactory.ts +0 -70
  12. package/src/agent_lattice/builders/AgentParamsBuilder.ts +0 -86
  13. package/src/agent_lattice/builders/DeepAgentGraphBuilder.ts +0 -46
  14. package/src/agent_lattice/builders/PlanExecuteAgentGraphBuilder.ts +0 -46
  15. package/src/agent_lattice/builders/ReActAgentGraphBuilder.ts +0 -42
  16. package/src/agent_lattice/builders/index.ts +0 -14
  17. package/src/agent_lattice/index.ts +0 -27
  18. package/src/agent_lattice/types.ts +0 -42
  19. package/src/base/BaseLatticeManager.ts +0 -145
  20. package/src/base/index.ts +0 -1
  21. package/src/createPlanExecuteAgent.ts +0 -475
  22. package/src/deep_agent/graph.ts +0 -106
  23. package/src/deep_agent/index.ts +0 -25
  24. package/src/deep_agent/prompts.ts +0 -284
  25. package/src/deep_agent/state.ts +0 -63
  26. package/src/deep_agent/subAgent.ts +0 -185
  27. package/src/deep_agent/tools.ts +0 -273
  28. package/src/deep_agent/types.ts +0 -71
  29. package/src/index.ts +0 -9
  30. package/src/logger/Logger.ts +0 -186
  31. package/src/memory_lattice/DefaultMemorySaver.ts +0 -4
  32. package/src/memory_lattice/MemoryLatticeManager.ts +0 -105
  33. package/src/memory_lattice/index.ts +0 -9
  34. package/src/model_lattice/ModelLattice.ts +0 -208
  35. package/src/model_lattice/ModelLatticeManager.ts +0 -125
  36. package/src/model_lattice/index.ts +0 -1
  37. package/src/tool_lattice/ToolLatticeManager.ts +0 -221
  38. package/src/tool_lattice/get_current_date_time/index.ts +0 -14
  39. package/src/tool_lattice/index.ts +0 -2
  40. package/src/tool_lattice/internet_search/index.ts +0 -66
  41. package/src/types.ts +0 -28
  42. package/src/util/PGMemory.ts +0 -16
  43. package/src/util/genUICard.ts +0 -3
  44. package/src/util/genUIMarkdown.ts +0 -3
  45. package/src/util/getLastHumanMessageData.ts +0 -41
  46. package/src/util/returnAIResponse.ts +0 -30
  47. package/src/util/returnErrorResponse.ts +0 -26
  48. package/src/util/returnFeedbackResponse.ts +0 -25
  49. package/src/util/returnToolResponse.ts +0 -32
  50. package/src/util/withAgentName.ts +0 -220
  51. package/src/util/zod-to-prompt.ts +0 -50
  52. package/tsconfig.json +0 -26
@@ -1,41 +0,0 @@
1
- import {
2
- BaseMessage,
3
- HumanMessage,
4
- isHumanMessage,
5
- } from "@langchain/core/messages";
6
- export type UserFile = {
7
- id: number;
8
- name: string;
9
- type?: string;
10
- path?: string;
11
- };
12
- export type UserFileZip = {
13
- id: number;
14
- name: string;
15
- files: UserFile[];
16
- type?: "application/zip" | "application/rar";
17
- totalFiles?: number;
18
- processedFiles?: number;
19
- skippedFiles?: number;
20
- };
21
-
22
- export const isCompressedFile = (fileType: string): boolean => {
23
- return fileType === "application/zip" || fileType === "application/rar";
24
- };
25
-
26
- export const getLastHumanMessageData = (messages: BaseMessage[]) => {
27
- // 从最后一条消息开始向前查找第一个人类消息
28
- for (let i = messages.length - 1; i >= 0; i--) {
29
- const message = messages[i];
30
- if (isHumanMessage(message)) {
31
- const files = message?.additional_kwargs?.files as UserFile[];
32
- return {
33
- files,
34
- content: message?.content,
35
- };
36
- }
37
- }
38
-
39
- // 如果没有找到任何人类消息,返回 null
40
- return null;
41
- };
@@ -1,30 +0,0 @@
1
- import { AIMessage } from "@langchain/core/messages";
2
- import { LangGraphRunnableConfig } from "@langchain/langgraph";
3
- import { v4 } from "uuid";
4
- import { genUIMarkdown } from "./genUIMarkdown";
5
-
6
- export const returnAIResponse = (
7
- config: LangGraphRunnableConfig,
8
- content: string,
9
- type?: string,
10
- data?: Record<string, any>
11
- ) => {
12
- const contents = type
13
- ? [content, genUIMarkdown(type, data)].join("\n")
14
- : content;
15
- const message = {
16
- messages: [
17
- new AIMessage({
18
- content: contents,
19
- }),
20
- // {
21
- // id: v4(),
22
- // role: "ai",
23
- // content: contents,
24
- // type: "message",
25
- // }, // 旧的message
26
- ],
27
- };
28
- // config.writer?.(message);
29
- return message;
30
- };
@@ -1,26 +0,0 @@
1
- import { AIMessage } from "@langchain/core/messages";
2
- import { LangGraphRunnableConfig } from "@langchain/langgraph";
3
- import { v4 } from "uuid";
4
-
5
- export const returnErrorResponse = (
6
- config: LangGraphRunnableConfig,
7
- content: string,
8
- type?: string,
9
- data?: Record<string, any>
10
- ) => {
11
- const contents = type
12
- ? [content, "```" + type, JSON.stringify(data), "```"].join("\n")
13
- : content;
14
- const message = {
15
- messages: [
16
- new AIMessage({
17
- content: contents,
18
- additional_kwargs: {
19
- type: "error",
20
- },
21
- }),
22
- ],
23
- };
24
- //config.writer?.(message);
25
- return message;
26
- };
@@ -1,25 +0,0 @@
1
- import { interrupt, LangGraphRunnableConfig } from "@langchain/langgraph";
2
- import { UserFeedbackResponse } from "../types";
3
-
4
- export const returnFeedbackResponse = async (
5
- content: string,
6
- type: string,
7
- data: Record<string, any>
8
- ) => {
9
- const contents = [
10
- content,
11
- "```" + type,
12
- JSON.stringify({ ...data }),
13
- "```",
14
- ].join("\n");
15
-
16
- const feedback: UserFeedbackResponse = await interrupt(contents);
17
- // console.log("returnFeedbackResponse_feedback", feedback);
18
- const messages = [
19
- {
20
- role: "user",
21
- content: JSON.stringify(feedback),
22
- },
23
- ];
24
- return { feedback, messages };
25
- };
@@ -1,32 +0,0 @@
1
- import { ToolMessage } from "@langchain/core/messages";
2
- import { LangGraphRunnableConfig } from "@langchain/langgraph";
3
- import { v4 } from "uuid";
4
- import { genUIMarkdown } from "./genUIMarkdown";
5
-
6
- export const returnToolResponse = (
7
- config: LangGraphRunnableConfig,
8
- think: {
9
- think_id?: string; // 思考的id,为了解决思考过程分组的问题
10
- title?: string;
11
- content: string;
12
- status?: "success" | "error";
13
- type?: string;
14
- data?: Record<string, any>;
15
- }
16
- ) => {
17
- const { think_id = v4(), content, title, status, type, data } = think;
18
- const contents = type
19
- ? [title, content, genUIMarkdown(type, data)]
20
- : [title, content];
21
- const message = {
22
- messages: [
23
- new ToolMessage({
24
- content: contents.filter((item) => item).join("\n\n"),
25
- tool_call_id: config.configurable?.run_id + "_tool_" + think_id,
26
- status: status || "success",
27
- }),
28
- ],
29
- };
30
-
31
- return message;
32
- };
@@ -1,220 +0,0 @@
1
- import { LanguageModelLike } from "@langchain/core/language_models/base";
2
- import {
3
- AIMessage,
4
- BaseMessage,
5
- BaseMessageLike,
6
- isAIMessage,
7
- isAIMessageChunk,
8
- isBaseMessage,
9
- isBaseMessageChunk,
10
- MessageContent,
11
- } from "@langchain/core/messages";
12
- import { RunnableLambda, RunnableSequence } from "@langchain/core/runnables";
13
-
14
- const NAME_PATTERN = /<name>(.*?)<\/name>/s;
15
- const CONTENT_PATTERN = /<content>(.*?)<\/content>/s;
16
-
17
- export type AgentNameMode = "inline";
18
-
19
- /**
20
- * Attach formatted agent names to the messages passed to and from a language model.
21
- *
22
- * This is useful for making a message history with multiple agents more coherent.
23
- *
24
- * NOTE: agent name is consumed from the message.name field.
25
- * If you're using an agent built with createReactAgent, name is automatically set.
26
- * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.
27
- *
28
- * @param message - Message to add agent name formatting to
29
- * @returns Message with agent name formatting
30
- *
31
- * @internal
32
- */
33
- export function _addInlineAgentName<T extends BaseMessageLike>(
34
- message: T
35
- ): T | AIMessage {
36
- const isAI =
37
- isBaseMessage(message) &&
38
- (isAIMessage(message) ||
39
- (isBaseMessageChunk(message) && isAIMessageChunk(message)));
40
-
41
- if (!isAI || !message.name) {
42
- return message;
43
- }
44
-
45
- const { name } = message;
46
-
47
- if (typeof message.content === "string") {
48
- return new AIMessage({
49
- ...(Object.keys(message.lc_kwargs ?? {}).length > 0
50
- ? message.lc_kwargs
51
- : message),
52
- content: `<name>${name}</name><content>${message.content}</content>`,
53
- name: undefined,
54
- });
55
- }
56
-
57
- const updatedContent = [];
58
- let textBlockCount = 0;
59
-
60
- for (const contentBlock of message.content) {
61
- if (typeof contentBlock === "string") {
62
- textBlockCount += 1;
63
- updatedContent.push(
64
- `<name>${name}</name><content>${contentBlock}</content>`
65
- );
66
- } else if (
67
- typeof contentBlock === "object" &&
68
- "type" in contentBlock &&
69
- contentBlock.type === "text"
70
- ) {
71
- textBlockCount += 1;
72
- updatedContent.push({
73
- ...contentBlock,
74
- text: `<name>${name}</name><content>${contentBlock.text}</content>`,
75
- });
76
- } else {
77
- updatedContent.push(contentBlock);
78
- }
79
- }
80
-
81
- if (!textBlockCount) {
82
- updatedContent.unshift({
83
- type: "text",
84
- text: `<name>${name}</name><content></content>`,
85
- });
86
- }
87
- return new AIMessage({
88
- ...message.lc_kwargs,
89
- content: updatedContent as MessageContent,
90
- name: undefined,
91
- });
92
- }
93
-
94
- /**
95
- * Remove explicit name and content XML tags from the AI message content.
96
- *
97
- * Examples:
98
- *
99
- * @example
100
- * ```typescript
101
- * removeInlineAgentName(new AIMessage({ content: "<name>assistant</name><content>Hello</content>", name: "assistant" }))
102
- * // AIMessage with content: "Hello"
103
- *
104
- * removeInlineAgentName(new AIMessage({ content: [{type: "text", text: "<name>assistant</name><content>Hello</content>"}], name: "assistant" }))
105
- * // AIMessage with content: [{type: "text", text: "Hello"}]
106
- * ```
107
- *
108
- * @internal
109
- */
110
- export function _removeInlineAgentName<T extends BaseMessage>(message: T): T {
111
- if (!isAIMessage(message) || !message.content) {
112
- return message;
113
- }
114
-
115
- let updatedContent: MessageContent = [];
116
- let updatedName: string | undefined;
117
-
118
- if (Array.isArray(message.content)) {
119
- updatedContent = message.content
120
- .filter((block) => {
121
- if (block.type === "text") {
122
- const nameMatch = block.text.match(NAME_PATTERN);
123
- const contentMatch = block.text.match(CONTENT_PATTERN);
124
- // don't include empty content blocks that were added because there was no text block to modify
125
- if (nameMatch && (!contentMatch || contentMatch[1] === "")) {
126
- // capture name from text block
127
- // eslint-disable-next-line prefer-destructuring
128
- updatedName = nameMatch[1];
129
- return false;
130
- }
131
- return true;
132
- }
133
- return true;
134
- })
135
- .map((block) => {
136
- if (block.type === "text") {
137
- const nameMatch = block.text.match(NAME_PATTERN);
138
- const contentMatch = block.text.match(CONTENT_PATTERN);
139
-
140
- if (!nameMatch || !contentMatch) {
141
- return block;
142
- }
143
-
144
- // capture name from text block
145
- // eslint-disable-next-line prefer-destructuring
146
- updatedName = nameMatch[1];
147
-
148
- return {
149
- ...block,
150
- text: contentMatch[1],
151
- };
152
- }
153
- return block;
154
- });
155
- } else {
156
- const content = message.content as string;
157
- const nameMatch = content.match(NAME_PATTERN);
158
- const contentMatch = content.match(CONTENT_PATTERN);
159
-
160
- if (!nameMatch || !contentMatch) {
161
- return message;
162
- }
163
-
164
- // eslint-disable-next-line prefer-destructuring
165
- updatedName = nameMatch[1];
166
- // eslint-disable-next-line prefer-destructuring
167
- updatedContent = contentMatch[1];
168
- }
169
-
170
- return new AIMessage({
171
- ...(Object.keys(message.lc_kwargs ?? {}).length > 0
172
- ? message.lc_kwargs
173
- : message),
174
- content: updatedContent,
175
- name: updatedName,
176
- }) as T;
177
- }
178
-
179
- /**
180
- * Attach formatted agent names to the messages passed to and from a language model.
181
- *
182
- * This is useful for making a message history with multiple agents more coherent.
183
- *
184
- * NOTE: agent name is consumed from the message.name field.
185
- * If you're using an agent built with createReactAgent, name is automatically set.
186
- * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.
187
- *
188
- * @param model - Language model to add agent name formatting to
189
- * @param agentNameMode - How to expose the agent name to the LLM
190
- * - "inline": Add the agent name directly into the content field of the AI message using XML-style tags.
191
- * Example: "How can I help you" -> "<name>agent_name</name><content>How can I help you?</content>".
192
- */
193
- export function withAgentName(
194
- model: LanguageModelLike,
195
- agentNameMode: AgentNameMode
196
- ): LanguageModelLike {
197
- let processInputMessage: (message: BaseMessageLike) => BaseMessageLike;
198
- let processOutputMessage: (message: BaseMessage) => BaseMessage;
199
-
200
- if (agentNameMode === "inline") {
201
- processInputMessage = _addInlineAgentName;
202
- processOutputMessage = _removeInlineAgentName;
203
- } else {
204
- throw new Error(
205
- `Invalid agent name mode: ${agentNameMode}. Needs to be one of: "inline"`
206
- );
207
- }
208
-
209
- function processInputMessages(
210
- messages: BaseMessageLike[]
211
- ): BaseMessageLike[] {
212
- return messages.map(processInputMessage);
213
- }
214
-
215
- return RunnableSequence.from([
216
- RunnableLambda.from(processInputMessages),
217
- model,
218
- RunnableLambda.from(processOutputMessage),
219
- ]);
220
- }
@@ -1,50 +0,0 @@
1
- // filename: zod-to-prompt.ts
2
- import { z, ZodObject, ZodTypeAny } from "zod";
3
-
4
- export function zodToPrompt(schema: ZodObject<any>): string {
5
- const shape = schema.shape;
6
- const lines: string[] = [];
7
-
8
- for (const key in shape) {
9
- const field: ZodTypeAny = shape[key];
10
- const description = field.description || "";
11
- const isOptional = field.isOptional();
12
- let type = field._def.typeName;
13
-
14
- // 处理常见类型
15
- switch (type) {
16
- case "ZodString":
17
- type = "字符串";
18
- break;
19
- case "ZodNumber":
20
- type = "数字";
21
- break;
22
- case "ZodBoolean":
23
- type = "布尔值";
24
- break;
25
- case "ZodArray":
26
- type = "数组";
27
- break;
28
- case "ZodObject":
29
- type = "对象";
30
- break;
31
- default:
32
- type = "未知类型";
33
- }
34
-
35
- lines.push(
36
- `- ${key}(${type}${isOptional ? ",可选" : ",必填"}):${description}`
37
- );
38
- }
39
-
40
- return `请提供以下参数:\n${lines.join("\n")}`;
41
- }
42
-
43
- // // 示例
44
- // const userSchema = z.object({
45
- // username: z.string().min(3).describe("用户名,至少3个字符"),
46
- // age: z.number().int().min(0).describe("年龄,必须为非负整数"),
47
- // email: z.string().email().optional().describe("电子邮箱,可选"),
48
- // });
49
-
50
- // console.log(zodToPrompt(userSchema));
package/tsconfig.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "preserve",
5
- "lib": ["ES2020"],
6
- "outDir": "./dist",
7
- "rootDir": "./src",
8
- "strict": true,
9
- "moduleResolution": "Bundler",
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "resolveJsonModule": true,
14
- "declaration": true,
15
- "declarationMap": true,
16
- "types": ["node", "jest"],
17
- "paths": {
18
- "@*": ["./src/*"]
19
- },
20
- "sourceMap": true,
21
- "incremental": true, // 确保启用增量编译
22
- "tsBuildInfoFile": "./.tsbuildinfo" // 指定构建信息文件位置
23
- },
24
- "include": ["src/index.ts"],
25
- "exclude": ["node_modules", "dist"]
26
- }