@axiom-lattice/examples-deep_research 1.0.13 → 1.0.16
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.
- package/.env +1 -1
- package/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +29 -0
- package/dist/index.js +1140 -4
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
- package/src/agents/data_agent/index.ts +408 -0
- package/src/agents/data_agent/skills/analysis-methodology.ts +73 -0
- package/src/agents/data_agent/skills/analyst.ts +100 -0
- package/src/agents/data_agent/skills/data-visualization.ts +77 -0
- package/src/agents/data_agent/skills/infographic-creator.ts +344 -0
- package/src/agents/data_agent/skills/notebook-report.ts +82 -0
- package/src/agents/data_agent/skills/sql-query.ts +58 -0
- package/src/agents/data_agent/tools/load_skills.ts +88 -0
- package/src/agents/index.ts +1 -2
- package/src/index.ts +50 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const sqlQuery = {
|
|
2
|
+
name: "sql-query",
|
|
3
|
+
description:
|
|
4
|
+
"生成和执行 SQL 查询以检索业务数据。适用于需要从数据库获取数据、探索表结构、验证查询正确性的场景。委托给 sql-builder-agent 执行。",
|
|
5
|
+
prompt: `## 委托给 sql-builder-agent
|
|
6
|
+
|
|
7
|
+
所有 SQL 相关操作都委托给 sql-builder-agent 子代理执行。
|
|
8
|
+
|
|
9
|
+
## 数据库模式探索
|
|
10
|
+
|
|
11
|
+
**请求模式信息**:
|
|
12
|
+
- "请列出数据库中所有可用的表"
|
|
13
|
+
- "请显示表 [X] 的模式,包括列、数据类型和关系"
|
|
14
|
+
|
|
15
|
+
**检查现有文档**:
|
|
16
|
+
- 先读取 \`/db_schema.md\`(如存在)
|
|
17
|
+
- 仅在需要时请求新的模式探索
|
|
18
|
+
|
|
19
|
+
## 查询生成与执行
|
|
20
|
+
|
|
21
|
+
**提供清晰的业务需求**:
|
|
22
|
+
1. **业务问题**:明确要回答的问题
|
|
23
|
+
2. **指标**:需要计算的业务指标(收入、订单数、转化率等)
|
|
24
|
+
3. **维度**:分组维度(地区、渠道、产品类别等)
|
|
25
|
+
4. **筛选条件**:时间范围、状态、类别等
|
|
26
|
+
5. **比较需求**:同比、环比、目标对比等
|
|
27
|
+
|
|
28
|
+
**请求格式示例**:
|
|
29
|
+
"我需要按地区比较 2024 年第三季度与 2023 年第三季度的收入。请生成并执行 SQL 查询。"
|
|
30
|
+
|
|
31
|
+
"请查询过去 6 个月每个月的订单量和平均订单金额,按渠道分组。"
|
|
32
|
+
|
|
33
|
+
## 接收与验证结果
|
|
34
|
+
|
|
35
|
+
sql-builder-agent 会返回:
|
|
36
|
+
- **SQL 查询**:格式清晰的完整查询
|
|
37
|
+
- **查询结果**:返回的数据
|
|
38
|
+
- **模式信息**:使用的表结构信息
|
|
39
|
+
|
|
40
|
+
**验证要点**:
|
|
41
|
+
- 查询是否正确回答了业务问题
|
|
42
|
+
- 数据质量(NULL 值、异常值)
|
|
43
|
+
- 结果完整性(行数、时间范围)
|
|
44
|
+
- 列名是否业务友好
|
|
45
|
+
|
|
46
|
+
## 错误处理
|
|
47
|
+
|
|
48
|
+
如遇到查询错误:
|
|
49
|
+
- 分析错误信息
|
|
50
|
+
- 检查表名、列名是否正确
|
|
51
|
+
- 验证 JOIN 条件和数据类型
|
|
52
|
+
- 请求 sql-builder-agent 修正并重新执行
|
|
53
|
+
|
|
54
|
+
## 文档化
|
|
55
|
+
|
|
56
|
+
将使用的 SQL 查询和结果保存到分析文档中,便于后续参考和复现。
|
|
57
|
+
`,
|
|
58
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load Skills Tools
|
|
3
|
+
* Tools for loading skill metadata and content
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import z from "zod";
|
|
7
|
+
import { registerToolLattice } from "@axiom-lattice/core";
|
|
8
|
+
import * as analystSkill from "../skills/analyst";
|
|
9
|
+
import * as dataVisualizationSkill from "../skills/data-visualization";
|
|
10
|
+
import * as sqlQuerySkill from "../skills/sql-query";
|
|
11
|
+
import * as analysisMethodologySkill from "../skills/analysis-methodology";
|
|
12
|
+
import * as notebookReportSkill from "../skills/notebook-report";
|
|
13
|
+
import * as infographicCreatorSkill from "../skills/infographic-creator";
|
|
14
|
+
|
|
15
|
+
// Type definition for skill structure
|
|
16
|
+
interface Skill {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
prompt: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Registry of all available skills
|
|
23
|
+
const skillsRegistry: Record<string, Skill> = {
|
|
24
|
+
analyst: analystSkill.analyst,
|
|
25
|
+
"data-visualization": dataVisualizationSkill.dataVisualization,
|
|
26
|
+
"sql-query": sqlQuerySkill.sqlQuery,
|
|
27
|
+
"analysis-methodology": analysisMethodologySkill.analysisMethodology,
|
|
28
|
+
"notebook-report": notebookReportSkill.notebookReport,
|
|
29
|
+
"infographic-creator": infographicCreatorSkill.infographicCreator,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Load all skills and return their metadata (name and description, without prompt)
|
|
34
|
+
*/
|
|
35
|
+
registerToolLattice(
|
|
36
|
+
"load_skills",
|
|
37
|
+
{
|
|
38
|
+
name: "load_skills",
|
|
39
|
+
description:
|
|
40
|
+
"Load all available skills and return their metadata (name and description). This tool returns skill information without the prompt content. Use this to discover what skills are available.",
|
|
41
|
+
needUserApprove: false,
|
|
42
|
+
schema: z.object({}),
|
|
43
|
+
},
|
|
44
|
+
async (_input: Record<string, never>, _config: any) => {
|
|
45
|
+
try {
|
|
46
|
+
const skillsMeta = Object.values(skillsRegistry).map((skill) => ({
|
|
47
|
+
name: skill.name,
|
|
48
|
+
description: skill.description,
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
return JSON.stringify(skillsMeta, null, 2);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return `Error loading skills: ${error instanceof Error ? error.message : String(error)
|
|
54
|
+
}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Load a specific skill's content and return its prompt
|
|
61
|
+
*/
|
|
62
|
+
registerToolLattice(
|
|
63
|
+
"load_skill_content",
|
|
64
|
+
{
|
|
65
|
+
name: "load_skill_content",
|
|
66
|
+
description:
|
|
67
|
+
"Load a specific skill's content by name and return its prompt. Use this tool to get the full prompt content for a skill that you want to use.",
|
|
68
|
+
needUserApprove: false,
|
|
69
|
+
schema: z.object({
|
|
70
|
+
skill_name: z.string().describe("The name of the skill to load"),
|
|
71
|
+
}),
|
|
72
|
+
},
|
|
73
|
+
async (input: { skill_name: string }, _config: any) => {
|
|
74
|
+
try {
|
|
75
|
+
const skill = skillsRegistry[input.skill_name];
|
|
76
|
+
|
|
77
|
+
if (!skill) {
|
|
78
|
+
const availableSkills = Object.keys(skillsRegistry).join(", ");
|
|
79
|
+
return `Skill "${input.skill_name}" not found. Available skills: ${availableSkills}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return skill.prompt;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return `Error loading skill content: ${error instanceof Error ? error.message : String(error)
|
|
85
|
+
}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
);
|
package/src/agents/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,11 +2,20 @@ import dotenv from "dotenv";
|
|
|
2
2
|
|
|
3
3
|
import { LatticeGateway } from "@axiom-lattice/gateway";
|
|
4
4
|
import {
|
|
5
|
+
getScheduleLattice,
|
|
5
6
|
registerCheckpointSaver,
|
|
6
7
|
registerModelLattice,
|
|
8
|
+
registerScheduleLattice,
|
|
7
9
|
} from "@axiom-lattice/core";
|
|
8
10
|
import "./agents";
|
|
11
|
+
|
|
9
12
|
import path from "path";
|
|
13
|
+
import {
|
|
14
|
+
LoggerConfig,
|
|
15
|
+
LoggerType,
|
|
16
|
+
ScheduleType,
|
|
17
|
+
} from "@axiom-lattice/protocols";
|
|
18
|
+
import { PostgreSQLScheduleStorage } from "@axiom-lattice/pg-stores";
|
|
10
19
|
// 在文件开头添加
|
|
11
20
|
const PACKAGE_VERSION = require("../package.json").version;
|
|
12
21
|
const BUILD_TIME = new Date().toISOString();
|
|
@@ -96,10 +105,51 @@ registerModelLattice(
|
|
|
96
105
|
);
|
|
97
106
|
LatticeGateway.registerLatticeRoutes(LatticeGateway.app);
|
|
98
107
|
|
|
108
|
+
// // 注册 Schedule Lattice(使用 PostgreSQL 持久化)
|
|
109
|
+
// registerScheduleLattice("default", {
|
|
110
|
+
// name: "Default Scheduler",
|
|
111
|
+
// description: "Production scheduler with PostgreSQL",
|
|
112
|
+
// type: ScheduleType.POSTGRES,
|
|
113
|
+
// storage: new PostgreSQLScheduleStorage({
|
|
114
|
+
// poolConfig: process.env.DATABASE_URL || "",
|
|
115
|
+
// }),
|
|
116
|
+
// });
|
|
117
|
+
|
|
118
|
+
// const scheduler = getScheduleLattice("default");
|
|
119
|
+
// // 注册 Handler(每次服务启动时都需要注册)
|
|
120
|
+
// scheduler.registerHandler("send-email", async (payload, taskInfo) => {
|
|
121
|
+
// console.log("send-email", payload, taskInfo);
|
|
122
|
+
// });
|
|
123
|
+
// scheduler.restore();
|
|
124
|
+
|
|
125
|
+
// // 一次性延迟任务
|
|
126
|
+
// scheduler.scheduleOnce(
|
|
127
|
+
// "email-123",
|
|
128
|
+
// "send-email",
|
|
129
|
+
// { to: "user@example.com", subject: "Welcome!" },
|
|
130
|
+
// { delayMs: 60000 } // 1分钟后执行
|
|
131
|
+
// );
|
|
132
|
+
|
|
99
133
|
const port = parsePort();
|
|
100
134
|
console.log(`Starting server on port ${port}`);
|
|
101
135
|
|
|
136
|
+
// Default logger configuration
|
|
137
|
+
const DEFAULT_LOGGER_CONFIG: LoggerConfig = {
|
|
138
|
+
name: "default",
|
|
139
|
+
description: "Default logger for lattice-gateway service",
|
|
140
|
+
type: LoggerType.PINO,
|
|
141
|
+
serviceName: "lattice/deep_research",
|
|
142
|
+
loggerName: "lattice/deep_research",
|
|
143
|
+
// file: {
|
|
144
|
+
// file: "./logs/lattice" + "/deep_research",
|
|
145
|
+
// frequency: "daily",
|
|
146
|
+
// mkdir: true,
|
|
147
|
+
// maxFiles: 30,
|
|
148
|
+
// },
|
|
149
|
+
};
|
|
150
|
+
|
|
102
151
|
LatticeGateway.startAsHttpEndpoint({
|
|
103
152
|
port,
|
|
104
153
|
queueServiceConfig: { type: "memory", defaultStartPollingQueue: true },
|
|
154
|
+
loggerConfig: DEFAULT_LOGGER_CONFIG,
|
|
105
155
|
});
|