@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
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/index.ts","../src/agents/research/index.ts"],"sourcesContent":["{\n \"name\": \"@axiom-lattice/examples-deep_research\",\n \"version\": \"1.0.13\",\n \"main\": \"dist/index.js\",\n \"bin\": {\n \"lattice-deep-research\": \"./dist/index.js\"\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"start\": \"node dist/index.js\",\n \"dev\": \"tsup src/index.ts --format cjs --dts --watch --onSuccess \\\"node dist/index.js\\\"\",\n \"dev:nodemon\": \"nodemon --watch 'src/**/*.ts' --watch '../../packages/core/dist/**/*' --exec 'ts-node' -r tsconfig-paths/register src/index.ts\",\n \"dev:serve\": \"tsup src/index.ts --format cjs --dts --watch --serve dist/index.js\",\n \"dev:inspect\": \"tsup src/index.ts --format cjs --dts --watch --onSuccess \\\"node --inspect dist/index.js\\\"\",\n \"lint\": \"tsc --noEmit\",\n \"test\": \"jest\",\n \"test:watch\": \"jest --watch\",\n \"test:coverage\": \"jest --coverage\"\n },\n \"keywords\": [],\n \"author\": \"\",\n \"license\": \"ISC\",\n \"description\": \"Deep Research Server for Axiom Lattice\",\n \"dependencies\": {\n \"@axiom-lattice/core\": \"workspace:*\",\n \"@axiom-lattice/gateway\": \"workspace:*\",\n \"dotenv\": \"^16.6.1\",\n \"uuid\": \"^9.0.1\",\n \"zod\": \"^3.24.2\",\n \"zod-to-json-schema\": \"^3.24.3\"\n },\n \"devDependencies\": {\n \"@types/jest\": \"^29.5.14\",\n \"@types/lodash\": \"^4.17.16\",\n \"@types/node\": \"^20.17.23\",\n \"@types/uuid\": \"^9.0.8\",\n \"@typescript-eslint/eslint-plugin\": \"^7.2.0\",\n \"@typescript-eslint/parser\": \"^7.2.0\",\n \"eslint\": \"^8.57.0\",\n \"jest\": \"^29.7.0\",\n \"nodemon\": \"^3.1.9\",\n \"ts-jest\": \"^29.4.0\",\n \"ts-node\": \"^10.9.2\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"^5.8.2\"\n }\n}\n","import dotenv from \"dotenv\";\n\nimport { LatticeGateway } from \"@axiom-lattice/gateway\";\nimport {\n registerCheckpointSaver,\n registerModelLattice,\n} from \"@axiom-lattice/core\";\nimport \"./agents\";\nimport path from \"path\";\n// 在文件开头添加\nconst PACKAGE_VERSION = require(\"../package.json\").version;\nconst BUILD_TIME = new Date().toISOString();\nconst IS_DEV = process.env.NODE_ENV !== \"production\";\n\n// 在启动时输出\nconsole.log(`\n╔═══════════════════════════════════════╗\n║ Lattice Deep Research Server ║\n║ Version: ${PACKAGE_VERSION} ║\n║ Build Time: ${BUILD_TIME} ║\n║ Environment: ${IS_DEV ? \"Development\" : \"Production\"} ║\n╚═══════════════════════════════════════╝\n`);\n// Load environment variables\ndotenv.config({ path: path.resolve(__dirname, \"../.env\") });\n\n// Parse command line arguments for port configuration\nfunction parsePort(): number {\n const args = process.argv.slice(2);\n const portIndex = args.findIndex((arg) => arg === \"--port\" || arg === \"-p\");\n\n if (portIndex !== -1 && args[portIndex + 1]) {\n const port = parseInt(args[portIndex + 1], 10);\n if (!isNaN(port) && port > 0 && port < 65536) {\n return port;\n }\n console.warn(\n `Invalid port value: ${args[portIndex + 1]}, using default port 4001`\n );\n }\n\n // Check environment variable\n if (process.env.PORT) {\n const port = parseInt(process.env.PORT, 10);\n if (!isNaN(port) && port > 0 && port < 65536) {\n return port;\n }\n console.warn(\n `Invalid PORT environment variable: ${process.env.PORT}, using default port 4001`\n );\n }\n\n // Default port\n return 4001;\n}\n\n// Register default model Lattice\nregisterModelLattice(\n \"default\",\n // {\n // model: \"deepseek-chat\",\n // provider: \"deepseek\",\n // streaming: false,\n // }\n // {\n // model: \"deepseek-chat\",\n // provider: \"deepseek\",\n // streaming: false,\n // apiKeyEnvName: \"DEEPSEEK_API_KEY2\",\n // },\n // {\n // model: \"deepseek-v3-250324\",\n // provider: \"volcengine\",\n // streaming: false,\n // },\n {\n model: \"kimi-k2-250905\",\n provider: \"volcengine\",\n streaming: true,\n apiKeyEnvName: \"VOLCENGINE_API_KEY2\",\n }\n // {\n // model: \"kimi-k2-0711-preview\",\n // provider: \"openai\",\n // streaming: true,\n // apiKeyEnvName: \"KIMI_API_KEY\",\n // baseURL: \"https://api.moonshot.cn/v1\",\n // }\n // {\n // model: \"qwen-plus\",\n // provider: \"openai\",\n // streaming: false,\n // apiKeyEnvName: \"DASHSCOPE_API_KEY\",\n // baseURL: \"https://dashscope.aliyuncs.com/compatible-mode/v1\",\n // }\n);\nLatticeGateway.registerLatticeRoutes(LatticeGateway.app);\n\nconst port = parsePort();\nconsole.log(`Starting server on port ${port}`);\n\nLatticeGateway.startAsHttpEndpoint({\n port,\n queueServiceConfig: { type: \"memory\", defaultStartPollingQueue: true },\n});\n","/* eslint-disable no-console */\n\nimport {\n registerAgentLattices,\n AgentType,\n AgentConfig,\n} from \"@axiom-lattice/core\";\nimport z from \"zod\";\n\nconst subResearchPrompt = `You are a dedicated researcher. Your job is to conduct research based on the users questions.\n\nConduct thorough research and then reply to the user with a detailed answer to their question\n\nonly your FINAL answer will be passed on to the user. They will have NO knowledge of anything except your final message, so your final report should be your final message!`;\n\nconst subCritiquePrompt = `You are a dedicated editor. You are being tasked to critique a report.\n\nYou can find the report at \\`final_report.md\\`.\n\nYou can find the question/topic for this report at \\`question.txt\\`.\n\nThe user may ask for specific areas to critique the report in. Respond to the user with a detailed critique of the report. Things that could be improved.\n\nYou can use the search tool to search for information, if that will help you critique the report\n\nDo not write to the \\`final_report.md\\` yourself.\n\nThings to check:\n- Check that each section is appropriately named\n- Check that the report is written as you would find in an essay or a textbook - it should be text heavy, do not let it just be a list of bullet points!\n- Check that the report is comprehensive. If any paragraphs or sections are short, or missing important details, point it out.\n- Check that the article covers key areas of the industry, ensures overall understanding, and does not omit important parts.\n- Check that the article deeply analyzes causes, impacts, and trends, providing valuable insights\n- Check that the article closely follows the research topic and directly answers questions\n- Check that the article has a clear structure, fluent language, and is easy to understand.\n`;\n\n// Prompt prefix to steer the agent to be an expert researcher\nconst researchInstructions = `You are an expert researcher. Your job is to conduct thorough research, and then write a polished report.\n\nThe first thing you should do is to write the original user question to \\`question.txt\\` so you have a record of it.\n\nUse the research-agent to conduct deep research. It will respond to your questions/topics with a detailed answer.\n\nWhen you think you enough information to write a final report, write it to \\`final_report.md\\`\n\nYou can call the critique-agent to get a critique of the final report. After that (if needed) you can do more research and edit the \\`final_report.md\\`\nYou can do this however many times you want until are you satisfied with the result.\n\nOnly edit the file once at a time (if you call this tool in parallel, there may be conflicts).\n\nHere are instructions for writing the final report:\n\n<report_instructions>\n\nCRITICAL: Make sure the answer is written in the same language as the human messages! If you make a todo plan - you should note in the plan what language the report should be in so you dont forget!\nNote: the language the report should be in is the language the QUESTION is in, not the language/country that the question is ABOUT.\n\nPlease create a detailed answer to the overall research brief that:\n1. Is well-organized with proper headings (# for title, ## for sections, ### for subsections)\n2. Includes specific facts and insights from the research\n3. References relevant sources using [Title](URL) format\n4. Provides a balanced, thorough analysis. Be as comprehensive as possible, and include all information that is relevant to the overall research question. People are using you for deep research and will expect detailed, comprehensive answers.\n5. Includes a \"Sources\" section at the end with all referenced links\n\nYou can structure your report in a number of different ways. Here are some examples:\n\nTo answer a question that asks you to compare two things, you might structure your report like this:\n1/ intro\n2/ overview of topic A\n3/ overview of topic B\n4/ comparison between A and B\n5/ conclusion\n\nTo answer a question that asks you to return a list of things, you might only need a single section which is the entire list.\n1/ list of things or table of things\nOr, you could choose to make each item in the list a separate section in the report. When asked for lists, you don't need an introduction or conclusion.\n1/ item 1\n2/ item 2\n3/ item 3\n\nTo answer a question that asks you to summarize a topic, give a report, or give an overview, you might structure your report like this:\n1/ overview of topic\n2/ concept 1\n3/ concept 2\n4/ concept 3\n5/ conclusion\n\nIf you think you can answer the question with a single section, you can do that too!\n1/ answer\n\nREMEMBER: Section is a VERY fluid and loose concept. You can structure your report however you think is best, including in ways that are not listed above!\nMake sure that your sections are cohesive, and make sense for the reader.\n\nFor each section of the report, do the following:\n- Use simple, clear language\n- Use ## for section title (Markdown format) for each section of the report\n- Do NOT ever refer to yourself as the writer of the report. This should be a professional report without any self-referential language.\n- Do not say what you are doing in the report. Just write the report without any commentary from yourself.\n- Each section should be as long as necessary to deeply answer the question with the information you have gathered. It is expected that sections will be fairly long and verbose. You are writing a deep research report, and users will expect a thorough answer.\n- Use bullet points to list out information when appropriate, but by default, write in paragraph form.\n\nREMEMBER:\nThe brief and research may be in English, but you need to translate this information to the right language when writing the final answer.\nMake sure the final answer report is in the SAME language as the human messages in the message history.\n\nFormat the report in clear markdown with proper structure and include source references where appropriate.\n\n<Citation Rules>\n- Assign each unique URL a single citation number in your text\n- End with ### Sources that lists each source with corresponding numbers\n- IMPORTANT: Number sources sequentially without gaps (1,2,3,4...) in the final list regardless of which sources you choose\n- Each source should be a separate line item in a list, so that in markdown it is rendered as a list.\n- Example format:\n [1] Source Title: URL\n [2] Source Title: URL\n- Citations are extremely important. Make sure to include these, and pay a lot of attention to getting these right. Users will often use these citations to look into more information.\n</Citation Rules>\n</report_instructions>\n\nYou have access to a few tools.\n\n## \\`internet_search\\`\n\nUse this to run an internet search for a given query. You can specify the number of results, the topic, and whether raw content should be included.\n`;\n\nconst research_agents: AgentConfig[] = [\n {\n key: \"deep_research_agent\",\n name: \"Deep Research Agent\",\n description:\n \"Used to research more in depth questions. Only give this researcher one topic at a time. Do not pass multiple sub questions to this researcher. Instead, you should break down a large topic into the necessary components, and then call multiple research agents in parallel, one for each sub question.\",\n type: AgentType.DEEP_AGENT,\n tools: [\"internet_search\"],\n prompt: researchInstructions,\n subAgents: [\"critique-agent\", \"research-agent\"],\n schema: z.object({\n test: z.string().optional(),\n }),\n },\n {\n key: \"research-agent\",\n name: \"research-agent\",\n type: AgentType.REACT,\n description:\n \"Used to research more in depth questions. Only give this researcher one topic at a time. Do not pass multiple sub questions to this researcher. Instead, you should break down a large topic into the necessary components, and then call multiple research agents in parallel, one for each sub question.\",\n prompt: subResearchPrompt,\n tools: [\"internet_search\"],\n },\n {\n key: \"critique-agent\",\n name: \"critique-agent\",\n type: AgentType.REACT,\n description:\n \"Used to critique the final report. Give this agent some infomration about how you want it to critique the report.\",\n prompt: subCritiquePrompt,\n },\n];\n\nregisterAgentLattices(research_agents);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,iBAAAA,UAAAC,SAAA;AAAA,IAAAA,QAAA;AAAA,MACE,MAAQ;AAAA,MACR,SAAW;AAAA,MACX,MAAQ;AAAA,MACR,KAAO;AAAA,QACL,yBAAyB;AAAA,MAC3B;AAAA,MACA,SAAW;AAAA,QACT,OAAS;AAAA,QACT,OAAS;AAAA,QACT,KAAO;AAAA,QACP,eAAe;AAAA,QACf,aAAa;AAAA,QACb,eAAe;AAAA,QACf,MAAQ;AAAA,QACR,MAAQ;AAAA,QACR,cAAc;AAAA,QACd,iBAAiB;AAAA,MACnB;AAAA,MACA,UAAY,CAAC;AAAA,MACb,QAAU;AAAA,MACV,SAAW;AAAA,MACX,aAAe;AAAA,MACf,cAAgB;AAAA,QACd,uBAAuB;AAAA,QACvB,0B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A,IACT;AACA,YAAQ;AAAA,MACN,uBAAuB,KAAK,YAAY,CAAC,CAAC;AAAA,IAC5C;AAAA,EACF;AAGA,MAAI,QAAQ,IAAI,MAAM;AACpB,UAAMA,QAAO,SAAS,QAAQ,IAAI,MAAM,EAAE;AAC1C,QAAI,CAAC,MAAMA,KAAI,KAAKA,QAAO,KAAKA,QAAO,OAAO;AAC5C,aAAOA;AAAA,IACT;AACA,YAAQ;AAAA,MACN,sCAAsC,QAAQ,IAAI,IAAI;AAAA,IACxD;AAAA,EACF;AAGA,SAAO;AACT;AAAA,IAGA;AAAA,EACE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA;AAAA,IACE,OAAO;AAAA,IACP,UAAU;AAAA,IACV,WAAW;AAAA,IACX,eAAe;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeF;AACA,8BAAe,sBAAsB,8BAAe,GAAG;AAEvD,IAAM,OAAO,UAAU;AACvB,QAAQ,IAAI,2BAA2B,IAAI,EAAE;AAE7C,8BAAe,oBAAoB;AAAA,EACjC;AAAA,EACA,oBAAoB,EAAE,MAAM,UAAU,0BAA0B,KAAK;AACvE,CAAC;","names":["exports","module","import_core","z","dotenv","path","port"]}
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/index.ts","../src/agents/research/index.ts","../src/agents/data_agent/index.ts","../src/agents/data_agent/tools/load_skills.ts","../src/agents/data_agent/skills/analyst.ts","../src/agents/data_agent/skills/data-visualization.ts","../src/agents/data_agent/skills/sql-query.ts","../src/agents/data_agent/skills/analysis-methodology.ts","../src/agents/data_agent/skills/notebook-report.ts","../src/agents/data_agent/skills/infographic-creator.ts"],"sourcesContent":["{\n \"name\": \"@axiom-lattice/examples-deep_research\",\n \"version\": \"1.0.16\",\n \"main\": \"dist/index.js\",\n \"bin\": {\n \"lattice-deep-research\": \"./dist/index.js\"\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"start\": \"node dist/index.js\",\n \"dev\": \"tsup src/index.ts --format cjs --dts --watch --onSuccess \\\"node dist/index.js\\\"\",\n \"dev:nodemon\": \"nodemon --watch 'src/**/*.ts' --watch '../../packages/core/dist/**/*' --exec 'ts-node' -r tsconfig-paths/register src/index.ts\",\n \"dev:serve\": \"tsup src/index.ts --format cjs --dts --watch --serve dist/index.js\",\n \"dev:inspect\": \"tsup src/index.ts --format cjs --dts --watch --onSuccess \\\"node --inspect dist/index.js\\\"\",\n \"lint\": \"tsc --noEmit\",\n \"test\": \"jest\",\n \"test:watch\": \"jest --watch\",\n \"test:coverage\": \"jest --coverage\"\n },\n \"keywords\": [],\n \"author\": \"\",\n \"license\": \"ISC\",\n \"description\": \"Deep Research Server for Axiom Lattice\",\n \"dependencies\": {\n \"@axiom-lattice/core\": \"workspace:*\",\n \"@axiom-lattice/gateway\": \"workspace:*\",\n \"@axiom-lattice/protocols\": \"workspace:*\",\n \"@axiom-lattice/pg-stores\": \"workspace:*\",\n \"dotenv\": \"^16.6.1\",\n \"uuid\": \"^9.0.1\",\n \"zod\": \"^3.24.2\",\n \"zod-to-json-schema\": \"^3.24.3\"\n },\n \"devDependencies\": {\n \"@types/jest\": \"^29.5.14\",\n \"@types/lodash\": \"^4.17.16\",\n \"@types/node\": \"^20.17.23\",\n \"@types/uuid\": \"^9.0.8\",\n \"@typescript-eslint/eslint-plugin\": \"^7.2.0\",\n \"@typescript-eslint/parser\": \"^7.2.0\",\n \"eslint\": \"^8.57.0\",\n \"jest\": \"^29.7.0\",\n \"nodemon\": \"^3.1.9\",\n \"ts-jest\": \"^29.4.0\",\n \"ts-node\": \"^10.9.2\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"^5.8.2\"\n }\n}\n","import dotenv from \"dotenv\";\n\nimport { LatticeGateway } from \"@axiom-lattice/gateway\";\nimport {\n getScheduleLattice,\n registerCheckpointSaver,\n registerModelLattice,\n registerScheduleLattice,\n} from \"@axiom-lattice/core\";\nimport \"./agents\";\n\nimport path from \"path\";\nimport {\n LoggerConfig,\n LoggerType,\n ScheduleType,\n} from \"@axiom-lattice/protocols\";\nimport { PostgreSQLScheduleStorage } from \"@axiom-lattice/pg-stores\";\n// 在文件开头添加\nconst PACKAGE_VERSION = require(\"../package.json\").version;\nconst BUILD_TIME = new Date().toISOString();\nconst IS_DEV = process.env.NODE_ENV !== \"production\";\n\n// 在启动时输出\nconsole.log(`\n╔═══════════════════════════════════════╗\n║ Lattice Deep Research Server ║\n║ Version: ${PACKAGE_VERSION} ║\n║ Build Time: ${BUILD_TIME} ║\n║ Environment: ${IS_DEV ? \"Development\" : \"Production\"} ║\n╚═══════════════════════════════════════╝\n`);\n// Load environment variables\ndotenv.config({ path: path.resolve(__dirname, \"../.env\") });\n\n// Parse command line arguments for port configuration\nfunction parsePort(): number {\n const args = process.argv.slice(2);\n const portIndex = args.findIndex((arg) => arg === \"--port\" || arg === \"-p\");\n\n if (portIndex !== -1 && args[portIndex + 1]) {\n const port = parseInt(args[portIndex + 1], 10);\n if (!isNaN(port) && port > 0 && port < 65536) {\n return port;\n }\n console.warn(\n `Invalid port value: ${args[portIndex + 1]}, using default port 4001`\n );\n }\n\n // Check environment variable\n if (process.env.PORT) {\n const port = parseInt(process.env.PORT, 10);\n if (!isNaN(port) && port > 0 && port < 65536) {\n return port;\n }\n console.warn(\n `Invalid PORT environment variable: ${process.env.PORT}, using default port 4001`\n );\n }\n\n // Default port\n return 4001;\n}\n\n// Register default model Lattice\nregisterModelLattice(\n \"default\",\n // {\n // model: \"deepseek-chat\",\n // provider: \"deepseek\",\n // streaming: false,\n // }\n // {\n // model: \"deepseek-chat\",\n // provider: \"deepseek\",\n // streaming: false,\n // apiKeyEnvName: \"DEEPSEEK_API_KEY2\",\n // },\n // {\n // model: \"deepseek-v3-250324\",\n // provider: \"volcengine\",\n // streaming: false,\n // },\n {\n model: \"kimi-k2-250905\",\n provider: \"volcengine\",\n streaming: true,\n apiKeyEnvName: \"VOLCENGINE_API_KEY2\",\n }\n // {\n // model: \"kimi-k2-0711-preview\",\n // provider: \"openai\",\n // streaming: true,\n // apiKeyEnvName: \"KIMI_API_KEY\",\n // baseURL: \"https://api.moonshot.cn/v1\",\n // }\n // {\n // model: \"qwen-plus\",\n // provider: \"openai\",\n // streaming: false,\n // apiKeyEnvName: \"DASHSCOPE_API_KEY\",\n // baseURL: \"https://dashscope.aliyuncs.com/compatible-mode/v1\",\n // }\n);\nLatticeGateway.registerLatticeRoutes(LatticeGateway.app);\n\n// // 注册 Schedule Lattice(使用 PostgreSQL 持久化)\n// registerScheduleLattice(\"default\", {\n// name: \"Default Scheduler\",\n// description: \"Production scheduler with PostgreSQL\",\n// type: ScheduleType.POSTGRES,\n// storage: new PostgreSQLScheduleStorage({\n// poolConfig: process.env.DATABASE_URL || \"\",\n// }),\n// });\n\n// const scheduler = getScheduleLattice(\"default\");\n// // 注册 Handler(每次服务启动时都需要注册)\n// scheduler.registerHandler(\"send-email\", async (payload, taskInfo) => {\n// console.log(\"send-email\", payload, taskInfo);\n// });\n// scheduler.restore();\n\n// // 一次性延迟任务\n// scheduler.scheduleOnce(\n// \"email-123\",\n// \"send-email\",\n// { to: \"user@example.com\", subject: \"Welcome!\" },\n// { delayMs: 60000 } // 1分钟后执行\n// );\n\nconst port = parsePort();\nconsole.log(`Starting server on port ${port}`);\n\n// Default logger configuration\nconst DEFAULT_LOGGER_CONFIG: LoggerConfig = {\n name: \"default\",\n description: \"Default logger for lattice-gateway service\",\n type: LoggerType.PINO,\n serviceName: \"lattice/deep_research\",\n loggerName: \"lattice/deep_research\",\n // file: {\n // file: \"./logs/lattice\" + \"/deep_research\",\n // frequency: \"daily\",\n // mkdir: true,\n // maxFiles: 30,\n // },\n};\n\nLatticeGateway.startAsHttpEndpoint({\n port,\n queueServiceConfig: { type: \"memory\", defaultStartPollingQueue: true },\n loggerConfig: DEFAULT_LOGGER_CONFIG,\n});\n","/* eslint-disable no-console */\n\nimport {\n registerAgentLattices,\n AgentType,\n AgentConfig,\n} from \"@axiom-lattice/core\";\nimport z from \"zod\";\n\nconst subResearchPrompt = `You are a dedicated researcher. Your job is to conduct research based on the users questions.\n\nConduct thorough research and then reply to the user with a detailed answer to their question\n\nonly your FINAL answer will be passed on to the user. They will have NO knowledge of anything except your final message, so your final report should be your final message!`;\n\nconst subCritiquePrompt = `You are a dedicated editor. You are being tasked to critique a report.\n\nYou can find the report at \\`final_report.md\\`.\n\nYou can find the question/topic for this report at \\`question.txt\\`.\n\nThe user may ask for specific areas to critique the report in. Respond to the user with a detailed critique of the report. Things that could be improved.\n\nYou can use the search tool to search for information, if that will help you critique the report\n\nDo not write to the \\`final_report.md\\` yourself.\n\nThings to check:\n- Check that each section is appropriately named\n- Check that the report is written as you would find in an essay or a textbook - it should be text heavy, do not let it just be a list of bullet points!\n- Check that the report is comprehensive. If any paragraphs or sections are short, or missing important details, point it out.\n- Check that the article covers key areas of the industry, ensures overall understanding, and does not omit important parts.\n- Check that the article deeply analyzes causes, impacts, and trends, providing valuable insights\n- Check that the article closely follows the research topic and directly answers questions\n- Check that the article has a clear structure, fluent language, and is easy to understand.\n`;\n\n// Prompt prefix to steer the agent to be an expert researcher\nconst researchInstructions = `You are an expert researcher. Your job is to conduct thorough research, and then write a polished report.\n\nThe first thing you should do is to write the original user question to \\`question.txt\\` so you have a record of it.\n\nUse the research-agent to conduct deep research. It will respond to your questions/topics with a detailed answer.\n\nWhen you think you enough information to write a final report, write it to \\`final_report.md\\`\n\nYou can call the critique-agent to get a critique of the final report. After that (if needed) you can do more research and edit the \\`final_report.md\\`\nYou can do this however many times you want until are you satisfied with the result.\n\nOnly edit the file once at a time (if you call this tool in parallel, there may be conflicts).\n\nHere are instructions for writing the final report:\n\n<report_instructions>\n\nCRITICAL: Make sure the answer is written in the same language as the human messages! If you make a todo plan - you should note in the plan what language the report should be in so you dont forget!\nNote: the language the report should be in is the language the QUESTION is in, not the language/country that the question is ABOUT.\n\nPlease create a detailed answer to the overall research brief that:\n1. Is well-organized with proper headings (# for title, ## for sections, ### for subsections)\n2. Includes specific facts and insights from the research\n3. References relevant sources using [Title](URL) format\n4. Provides a balanced, thorough analysis. Be as comprehensive as possible, and include all information that is relevant to the overall research question. People are using you for deep research and will expect detailed, comprehensive answers.\n5. Includes a \"Sources\" section at the end with all referenced links\n\nYou can structure your report in a number of different ways. Here are some examples:\n\nTo answer a question that asks you to compare two things, you might structure your report like this:\n1/ intro\n2/ overview of topic A\n3/ overview of topic B\n4/ comparison between A and B\n5/ conclusion\n\nTo answer a question that asks you to return a list of things, you might only need a single section which is the entire list.\n1/ list of things or table of things\nOr, you could choose to make each item in the list a separate section in the report. When asked for lists, you don't need an introduction or conclusion.\n1/ item 1\n2/ item 2\n3/ item 3\n\nTo answer a question that asks you to summarize a topic, give a report, or give an overview, you might structure your report like this:\n1/ overview of topic\n2/ concept 1\n3/ concept 2\n4/ concept 3\n5/ conclusion\n\nIf you think you can answer the question with a single section, you can do that too!\n1/ answer\n\nREMEMBER: Section is a VERY fluid and loose concept. You can structure your report however you think is best, including in ways that are not listed above!\nMake sure that your sections are cohesive, and make sense for the reader.\n\nFor each section of the report, do the following:\n- Use simple, clear language\n- Use ## for section title (Markdown format) for each section of the report\n- Do NOT ever refer to yourself as the writer of the report. This should be a professional report without any self-referential language.\n- Do not say what you are doing in the report. Just write the report without any commentary from yourself.\n- Each section should be as long as necessary to deeply answer the question with the information you have gathered. It is expected that sections will be fairly long and verbose. You are writing a deep research report, and users will expect a thorough answer.\n- Use bullet points to list out information when appropriate, but by default, write in paragraph form.\n\nREMEMBER:\nThe brief and research may be in English, but you need to translate this information to the right language when writing the final answer.\nMake sure the final answer report is in the SAME language as the human messages in the message history.\n\nFormat the report in clear markdown with proper structure and include source references where appropriate.\n\n<Citation Rules>\n- Assign each unique URL a single citation number in your text\n- End with ### Sources that lists each source with corresponding numbers\n- IMPORTANT: Number sources sequentially without gaps (1,2,3,4...) in the final list regardless of which sources you choose\n- Each source should be a separate line item in a list, so that in markdown it is rendered as a list.\n- Example format:\n [1] Source Title: URL\n [2] Source Title: URL\n- Citations are extremely important. Make sure to include these, and pay a lot of attention to getting these right. Users will often use these citations to look into more information.\n</Citation Rules>\n</report_instructions>\n\nYou have access to a few tools.\n\n## \\`internet_search\\`\n\nUse this to run an internet search for a given query. You can specify the number of results, the topic, and whether raw content should be included.\n`;\n\nconst research_agents: AgentConfig[] = [\n {\n key: \"deep_research_agent\",\n name: \"Deep Research Agent\",\n description:\n \"Used to research more in depth questions. Only give this researcher one topic at a time. Do not pass multiple sub questions to this researcher. Instead, you should break down a large topic into the necessary components, and then call multiple research agents in parallel, one for each sub question.\",\n type: AgentType.DEEP_AGENT,\n tools: [\"internet_search\"],\n prompt: researchInstructions,\n subAgents: [\"critique-agent\", \"research-agent\"],\n schema: z.object({\n test: z.string().optional(),\n }),\n },\n {\n key: \"research-agent\",\n name: \"research-agent\",\n type: AgentType.REACT,\n description:\n \"Used to research more in depth questions. Only give this researcher one topic at a time. Do not pass multiple sub questions to this researcher. Instead, you should break down a large topic into the necessary components, and then call multiple research agents in parallel, one for each sub question.\",\n prompt: subResearchPrompt,\n tools: [\"internet_search\"],\n },\n {\n key: \"critique-agent\",\n name: \"critique-agent\",\n type: AgentType.REACT,\n description:\n \"Used to critique the final report. Give this agent some infomration about how you want it to critique the report.\",\n prompt: subCritiquePrompt,\n },\n];\n\nregisterAgentLattices(research_agents);\n","/**\n * Data Agent - Business Data Analyst Agent\n * An intelligent agent that converts natural language business questions to SQL queries,\n * performs multi-step business analysis, and generates comprehensive business reports.\n *\n * Key Capabilities:\n * - Business analysis and task decomposition\n * - Multi-step data analysis with dimension breakdowns\n * - Structured report generation (Executive Summary, Analysis Steps, Appendix)\n * - Business-friendly insights and visualizations\n * - Reproducible notebook-style analysis trajectory\n */\n\nimport {\n registerAgentLattices,\n AgentType,\n AgentConfig,\n sqlDatabaseManager,\n DatabaseConfig,\n} from \"@axiom-lattice/core\";\nimport z from \"zod\";\n\n// Import tools to register them\nimport \"./tools/load_skills\";\n\n/**\n * System prompt for the main data agent\n * This agent orchestrates the NL2SQL process with business analysis capabilities\n */\nconst dataAgentPrompt = `你是一位专业的业务数据分析AI助手,擅长规划业务分析任务、协调数据检索,并生成全面的业务分析报告。\n\n**关键:你的第一项也是最重要的任务是使用 \\`write_todos\\` 工具创建待办列表。** 在开始任何工作之前,你必须:\n1. 理解业务问题,然后将问题写入文件 /question.md\n2. 使用 \\`load_skills\\` 工具加载所有可用技能,找到最适合解决该问题的技能\n3. 使用 \\`load_skill_content\\` 工具加载选定技能的详细内容,获取具体的操作指南/SOP\n4. 根据技能的 How-to/SOP 将任务拆解为可执行的子任务,创建待办列表\n5. 按照计划执行任务\n\n永远不要跳过任务规划。业务分析总是复杂且多步骤的,需要仔细规划和跟踪。\n\n## 核心工作流程\n\n你的主要职责是通过技能驱动的方式完成分析任务:\n\n1. **任务规划与拆解(优先级最高)**:理解业务问题,通过加载相关技能(如 \\`analysis-methodology\\`)来学习如何拆解任务,然后使用 \\`write_todos\\` 工具创建和管理任务列表\n2. **业务分析执行**:根据加载的技能内容(如 \\`analyst\\`、\\`sql-query\\` 等)执行具体的分析步骤\n3. **任务协调**:将 SQL 查询生成和执行委托给 sql-builder-agent 子代理\n4. **数据解读**:分析 sql-builder-agent 返回的查询结果,提取业务洞察\n5. **报告生成**:使用相关技能(如 \\`notebook-report\\`)生成包含洞察、可视化和可执行建议的业务分析报告\n\n## 技能驱动的工作方式\n\n**重要原则**:不要依赖硬编码的流程,而是通过技能来学习如何工作。\n\n- **如何规划任务**:加载 \\`analysis-methodology\\` 技能,学习结构化分析方法论(5W2H、MECE、议题树等)\n- **如何执行分析**:加载 \\`analyst\\` 技能,学习完整的分析工作流程\n- **如何查询数据**:加载 \\`sql-query\\` 技能,学习数据库探索和查询执行的最佳实践\n- **如何可视化**:加载 \\`data-visualization\\` 技能,学习图表设计和 ECharts 配置\n- **如何生成报告**:加载 \\`notebook-report\\` 技能,学习报告结构和生成方法\n\n每个技能都包含详细的操作指南、工作流程和最佳实践。你应该:\n1. 首先使用 \\`load_skills\\` 了解有哪些技能可用\n2. 根据业务问题选择合适的技能\n3. 使用 \\`load_skill_content\\` 获取技能的完整内容\n4. 严格按照技能中的指导执行工作\n\n## 子代理使用\n\n- **sql-builder-agent**:负责所有 SQL 相关操作(数据库探索、查询生成、验证和执行)\n- **data-analysis-agent**:负责分析查询结果,提取业务洞察,提供可视化建议\n\n将技术任务委托给相应的子代理,专注于业务分析和任务协调。\n\n`;\n\n/**\n * System prompt for the SQL query builder sub-agent\n */\nconst sqlBuilderPrompt = `You are a SQL Expert sub-agent specialized in database exploration, SQL query generation, validation, and execution. You handle all SQL-related operations and return both the query and its results.\n\nWhen given a task from the data_agent:\n1. **Understand the Business Intent**: Analyze what business question the query needs to answer\n2. **Check Schema Documentation First**: \n - Before exploring the database, read file \\`/db_schema.md\\` \n - If the schema file exists, read it to understand the database structure\n - This will save time and avoid redundant schema exploration\n - If the file doesn't exist or you need more specific information, then:\n - Use \\`list_tables_sql\\` to see all available tables\n - Use \\`info_sql\\` to get detailed schema information for relevant tables\n - Understand column names, data types, relationships, and sample data\n3. **Design Query**: Write the most appropriate SQL query that:\n - Answers the business question accurately\n - Uses efficient joins and aggregations\n - Includes business-friendly column aliases\n - Handles edge cases (NULLs, duplicates, etc.)\n4. **Validate**: Use \\`query_checker_sql\\` to validate the query before execution\n5. **Execute**: Use \\`query_sql\\` to execute the validated query\n6. **Return Results**: Provide both:\n - The SQL query that was executed (formatted clearly)\n - The query results (data returned from the database)\n - Any relevant schema information that was used\n\n## Focus Areas\n\n- **Query Correctness**: Ensure the query accurately answers the business question\n- **Query Efficiency**: Optimize for performance (use indexes, efficient JOINs)\n- **Business Clarity**: Use meaningful column aliases that business users can understand\n - Example: Use \"revenue_usd\" instead of \"amt\", \"order_count\" instead of \"cnt\"\n- **Proper JOINs**: Use appropriate JOIN types (INNER, LEFT, RIGHT, FULL) based on business logic\n- **Aggregations**: Use appropriate aggregate functions (COUNT, SUM, AVG, MAX, MIN) with proper GROUP BY\n- **Subqueries**: Use subqueries when they improve clarity or performance\n- **Window Functions**: Leverage window functions for advanced analytics when needed\n\n## Business-Oriented Query Design\n\nWhen writing queries:\n- **Metric Calculation**: Ensure metrics are calculated correctly (e.g., YoY growth, percentages)\n- **Dimension Handling**: Properly handle business dimensions (regions, channels, product categories)\n- **Time Periods**: Correctly filter and group by time periods (quarters, months, years)\n- **Comparisons**: Structure queries to enable easy comparisons (current vs previous period)\n- **Data Quality**: Include filters to exclude invalid or test data when appropriate\n\n## Error Handling\n\nIf you encounter issues:\n- Analyze the error message carefully\n- Check schema compatibility (data types, column names)\n- Verify JOIN conditions and table relationships\n- Modify the query accordingly\n- Re-validate before returning\n\n## Output Format\n\nAlways return your results in a clear format:\n\n**SQL Query:**\n- The final SQL query that was executed\n- Properly indented and readable\n- Includes comments for complex logic\n- Uses business-friendly aliases\n- Can be easily understood by both technical and business users\n\n**Query Results:**\n- The data returned from the database\n- Formatted clearly with column names\n- Include all rows returned (or a summary if too large)\n\n**Schema Information (if relevant):**\n- Any schema details that were used or discovered\n- Table relationships, column types, etc.\n\n**Example Response Format:**\n\\`\\`\\`\nSQL Query:\n\\`\\`\\`sql\n[Your executed SQL query here]\n\\`\\`\\`\n\nQuery Results:\n[Data table or summary here]\n\nSchema Information:\n[Any relevant schema details]\n\\`\\`\\`\n\nRemember: You are responsible for all SQL operations. The data_agent relies on you to provide both the query and the data. Be thorough, accurate, and return complete information.\n\n## SQL Best Practices\n\n1. **Be Specific**: Always specify column names instead of using SELECT *\n2. **Use Aliases**: Use meaningful table and column aliases for clarity\n3. **Handle NULLs**: Consider NULL values in your queries\n4. **Limit Results**: For exploratory queries, limit results to avoid overwhelming output\n5. **Optimize JOINs**: Use appropriate JOIN types (INNER, LEFT, etc.)\n6. **Use Indexes**: Structure queries to leverage indexes when possible\n7. **Business Naming**: Use business-friendly column aliases in results\n\n`;\n\n/**\n * System prompt for the data analysis sub-agent\n */\nconst dataAnalysisPrompt = `你是一位业务数据分析专家子代理。你的职责是解读查询结果,提取业务洞察,并评估当前数据是否足以回答用户的问题。\n\n## 核心职责\n\n当你收到查询结果时,你需要:\n\n1. **提取关键发现**:识别数据中最重要的数字、趋势和模式\n2. **业务解读**:将数据转化为业务语言和业务上下文\n3. **模式识别**:识别趋势、异常、相关性和离群值\n4. **问题回答评估**:评估当前数据是否足以完整回答用户的业务问题\n5. **数据缺口识别**:如果数据不足,明确指出还需要哪些数据,以及如何获取这些数据\n\n## 分析框架\n\n### 1. 数据摘要\n\n用 2-3 句话总结数据揭示的核心信息,自然地融入具体数字。\n\n例如:\"数据显示 2024 年 Q3 北美地区收入达到 250 万美元,相比 2023 年 Q3 增长了 18%。这一增长主要由在线渠道扩张驱动,表明战略转型取得了成功。\"\n\n### 2. 关键发现\n\n以叙述性段落(每段 2-3 句话)呈现关键发现,每个段落应该是一个小故事,自然地融入具体数字。\n\n例如:\"最引人注目的发现是地区差异。虽然整体收入增长了 18%,但美国市场贡献了总收入的 70%,其中加利福尼亚州表现尤为强劲,增长 25%。这种集中度既意味着机会,也意味着风险——成功高度依赖少数关键市场。\"\n\n### 3. 业务洞察\n\n用叙述性段落解释这些发现意味着什么,将数据点与业务结果自然连接。\n\n- 讨论关注点或机会\n- 解释可能导致这些模式的因素\n- 使用\"这表明...\"、\"有趣的是...\"、\"特别值得注意的是...\"等表达\n\n### 4. 问题回答评估\n\n**关键任务**:评估当前数据是否足以回答用户的业务问题。\n\n- **如果数据充足**:明确说明当前数据如何回答了问题,哪些方面已经得到解答\n- **如果数据不足**:明确指出:\n - 哪些问题无法从当前数据中回答\n - 缺少哪些关键信息或维度\n - 建议需要查询哪些额外的数据(具体说明需要查询的表、字段、时间范围、筛选条件等)\n - 为什么这些额外数据对完整回答问题至关重要\n\n### 5. 后续数据挖掘建议\n\n如果数据不足,提供具体的数据挖掘建议:\n\n- **需要查询的表和字段**:明确指出需要从哪些表查询哪些字段\n- **时间范围**:如果需要历史对比,建议查询的时间范围\n- **维度拆分**:如果需要更细粒度的分析,建议按哪些维度拆分(如地区、渠道、产品类别等)\n- **关联查询**:如果需要关联其他表,说明需要 JOIN 哪些表以及关联条件\n- **筛选条件**:如果需要特定子集的数据,说明筛选条件\n\n## 业务上下文整合\n\n分析结果时考虑:\n\n- **基准对比**:与历史时期、目标或行业标准对比\n- **细分分析**:识别哪些细分(地区、渠道、产品)驱动了结果\n- **异常检测**:标记需要调查的异常模式\n- **趋势分析**:识别上升、下降或稳定趋势\n- **相关性**:注意不同指标之间的关系\n\n## 输出结构\n\n\\`\\`\\`markdown\n### 数据摘要\n\n[用 2-3 句话总结数据揭示的核心信息,自然地融入具体数字]\n\n### 关键发现\n\n[用叙述性段落(每段 2-3 句话)呈现关键发现,自然地融入具体数字]\n\n### 业务洞察\n\n[用叙述性段落解释这些发现意味着什么,将数据点与业务结果自然连接]\n\n### 问题回答评估\n\n**当前数据是否足以回答问题:** [是/部分/否]\n\n**已回答的方面:**\n- [说明当前数据如何回答了问题的哪些方面]\n\n**未回答的方面(如果数据不足):**\n- [明确指出哪些问题无法从当前数据中回答]\n\n### 数据挖掘建议(如果数据不足)\n\n**需要查询的额外数据:**\n1. **查询目标**:[说明需要查询什么信息]\n2. **建议的 SQL 查询方向**:\n - 表:[需要查询的表名]\n - 字段:[需要的字段列表]\n - 时间范围:[如果需要,说明时间范围]\n - 维度拆分:[如果需要,说明按哪些维度拆分]\n - 关联表:[如果需要 JOIN,说明关联的表和条件]\n - 筛选条件:[如果需要,说明筛选条件]\n3. **为什么需要这些数据**:[解释为什么这些数据对完整回答问题至关重要]\n\\`\\`\\`\n\n## 沟通风格\n\n- **叙述性**:以故事形式呈现,而非技术报告\n- **自然流畅**:使用多样化的句子结构和自然的过渡\n- **业务友好**:使用业务术语,而非技术行话\n- **数据驱动**:自然地融入具体数字,而非单独列出事实\n- **对话式**:像向同事解释一样,而非填写表格\n- **可执行**:聚焦能够为决策提供信息的洞察\n- **上下文相关**:在叙述中自然地提供业务上下文\n\n## 特别注意事项\n\n- **百分比**:在相关时计算并突出百分比变化\n- **对比**:始终提供上下文(与上一时期对比、与目标对比、与平均值对比)\n- **离群值**:标记并解释任何异常数据点\n- **数据质量**:注意任何数据限制或注意事项\n- **置信度**:当发现具有统计显著性或仅为初步结果时,明确说明\n\n记住:你的分析将原始查询结果转化为有意义的业务洞察。评估数据是否足以回答问题,如果不足,提供具体的数据挖掘建议,帮助获取完整答案所需的信息。\n`;\n\n/**\n * Data Agent configurations\n */\nconst data_agents: AgentConfig[] = [\n {\n key: \"data_agent\",\n name: \"Data Agent\",\n description:\n \"An intelligent Business Data Analyst agent that converts natural language questions into SQL queries, performs multi-step business analysis, and generates comprehensive business reports. Capabilities include: task decomposition, metric analysis, dimension breakdowns, anomaly detection, and structured report generation with executive summaries, analysis steps, and visualizations. Use this agent for business intelligence, data analysis, database queries, and generating actionable business insights.\",\n type: AgentType.DEEP_AGENT,\n tools: [\"list_tables_sql\", \"info_sql\", \"load_skills\", \"load_skill_content\"],\n prompt: dataAgentPrompt,\n subAgents: [\"sql-builder-agent\", \"data-analysis-agent\"],\n schema: z.object({}),\n /**\n * Runtime configuration injected into tool execution context.\n * databaseKey: The database key registered via sqlDatabaseManager.\n * Tools will access this via config.configurable.runConfig.databaseKey\n */\n runConfig: {\n databaseKey: \"fulidb\", // Set this to the registered database key\n },\n },\n {\n key: \"sql-builder-agent\",\n name: \"sql-builder-agent\",\n type: AgentType.DEEP_AGENT,\n description:\n \"A specialized sub-agent for database exploration, SQL query generation, validation, and execution. This agent handles all SQL-related operations including listing tables, exploring schemas, generating queries, validating them, executing them, and returning both the SQL and query results to the data_agent.\",\n prompt: sqlBuilderPrompt,\n tools: [\"list_tables_sql\", \"info_sql\", \"query_checker_sql\", \"query_sql\"],\n // Sub-agents inherit runConfig from parent agent via the execution context\n },\n {\n key: \"data-analysis-agent\",\n name: \"data-analysis-agent\",\n type: AgentType.DEEP_AGENT,\n description:\n \"A specialized sub-agent for analyzing query results and extracting business insights. This agent interprets data, identifies patterns and anomalies, provides business context, and structures findings for comprehensive reports. Give this agent query results and it will provide structured business analysis with key findings, insights, and visualization recommendations.\",\n prompt: dataAnalysisPrompt,\n tools: [],\n },\n];\n\n// Register the agents\nregisterAgentLattices(data_agents);\n\n/**\n * Helper function to initialize database connection for the data agent\n * Call this before using the data agent\n *\n * @param key - Unique identifier for the database connection\n * @param config - Database configuration\n *\n * @example\n * ```typescript\n * import { initializeDataAgentDatabase } from \"@axiom-lattice/examples-deep_research/agents/data_agent\";\n *\n * // Using connection string\n * initializeDataAgentDatabase(\"mydb\", {\n * type: \"postgres\",\n * connectionString: process.env.DATABASE_URL\n * });\n *\n * // Or using individual parameters\n * initializeDataAgentDatabase(\"mydb\", {\n * type: \"postgres\",\n * host: \"localhost\",\n * port: 5432,\n * database: \"mydb\",\n * user: \"user\",\n * password: \"password\"\n * });\n * ```\n */\nexport function initializeDataAgentDatabase(\n key: string,\n config: DatabaseConfig\n): void {\n sqlDatabaseManager.registerDatabase(key, config);\n}\n\n/**\n * Helper function to set the default database for the data agent\n *\n * @param key - Database key to set as default\n */\nexport function setDefaultDatabase(key: string): void {\n sqlDatabaseManager.setDefaultDatabase(key);\n}\n\n/**\n * Export types for external use\n */\nexport type { DatabaseConfig };\n\ninitializeDataAgentDatabase(\"fulidb\", {\n type: \"postgres\",\n connectionString: process.env.DATABASE_URL,\n database: \"postgres\",\n});\n","/**\n * Load Skills Tools\n * Tools for loading skill metadata and content\n */\n\nimport z from \"zod\";\nimport { registerToolLattice } from \"@axiom-lattice/core\";\nimport * as analystSkill from \"../skills/analyst\";\nimport * as dataVisualizationSkill from \"../skills/data-visualization\";\nimport * as sqlQuerySkill from \"../skills/sql-query\";\nimport * as analysisMethodologySkill from \"../skills/analysis-methodology\";\nimport * as notebookReportSkill from \"../skills/notebook-report\";\nimport * as infographicCreatorSkill from \"../skills/infographic-creator\";\n\n// Type definition for skill structure\ninterface Skill {\n name: string;\n description: string;\n prompt: string;\n}\n\n// Registry of all available skills\nconst skillsRegistry: Record<string, Skill> = {\n analyst: analystSkill.analyst,\n \"data-visualization\": dataVisualizationSkill.dataVisualization,\n \"sql-query\": sqlQuerySkill.sqlQuery,\n \"analysis-methodology\": analysisMethodologySkill.analysisMethodology,\n \"notebook-report\": notebookReportSkill.notebookReport,\n \"infographic-creator\": infographicCreatorSkill.infographicCreator,\n};\n\n/**\n * Load all skills and return their metadata (name and description, without prompt)\n */\nregisterToolLattice(\n \"load_skills\",\n {\n name: \"load_skills\",\n description:\n \"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.\",\n needUserApprove: false,\n schema: z.object({}),\n },\n async (_input: Record<string, never>, _config: any) => {\n try {\n const skillsMeta = Object.values(skillsRegistry).map((skill) => ({\n name: skill.name,\n description: skill.description,\n }));\n\n return JSON.stringify(skillsMeta, null, 2);\n } catch (error) {\n return `Error loading skills: ${error instanceof Error ? error.message : String(error)\n }`;\n }\n }\n);\n\n/**\n * Load a specific skill's content and return its prompt\n */\nregisterToolLattice(\n \"load_skill_content\",\n {\n name: \"load_skill_content\",\n description:\n \"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.\",\n needUserApprove: false,\n schema: z.object({\n skill_name: z.string().describe(\"The name of the skill to load\"),\n }),\n },\n async (input: { skill_name: string }, _config: any) => {\n try {\n const skill = skillsRegistry[input.skill_name];\n\n if (!skill) {\n const availableSkills = Object.keys(skillsRegistry).join(\", \");\n return `Skill \"${input.skill_name}\" not found. Available skills: ${availableSkills}`;\n }\n\n return skill.prompt;\n } catch (error) {\n return `Error loading skill content: ${error instanceof Error ? error.message : String(error)\n }`;\n }\n }\n);\n","export const analyst = {\n name: \"analyst\",\n description:\n \"协调和执行完整的业务数据分析流程,整合分析方法论、SQL查询、数据可视化和报告编写技能。适用于需要端到端分析流程的复杂业务问题。\",\n prompt: `## 角色定位\n\n作为分析协调者,整合使用以下技能完成端到端分析:\n- \\`analysis-methodology\\`: 结构化问题拆解和方法论应用\n- \\`sql-query\\`: 数据检索和查询执行\n- \\`data-visualization\\`: 图表设计和可视化配置\n- \\`notebook-report\\`: 报告生成和洞察整合\n\n## 分析工作流程\n\n### 步骤 0:问题理解与规划\n\n1. **记录问题**:写入 \\`/question.md\\`(问题陈述、业务背景、成功标准)\n2. **应用分析方法论**:使用 \\`analysis-methodology\\` 技能\n - 使用 5W2H 和 SCQA 明确问题\n - 使用 MECE 和议题树拆解为子问题\n - 使用四象限矩阵排序优先级\n3. **创建待办列表**:每个子问题作为独立任务\n\n### 步骤 1:数据库模式探索(如需要)\n\n使用 \\`sql-query\\` 技能:\n1. 检查 \\`/db_schema.md\\` 是否存在\n2. 如需要,探索表结构\n3. 将模式文档写入 \\`/db_schema.md\\`\n\n### 步骤 2:迭代分析执行\n\n对每个待办任务:\n\n**2.1 数据检索**:\n- 委托 sql-builder-agent 执行查询\n- 验证查询结果的质量和完整性\n\n**2.2 数据分析**:\n- 委托 data-analysis-agent 分析数据\n- 请求关键发现、业务解释和可视化建议\n\n**2.3 可视化设计**:\n- 使用 \\`data-visualization\\` 技能\n- 根据分析结果选择合适的图表类型\n- 生成完整的 ECharts 配置\n\n**2.4 文档化**:\n- 写入 \\`/topic_[sub_topic_name].md\\`:\n - 业务问题/目标\n - SQL 查询\n - 查询结果\n - 分析洞察\n - 图表配置(使用 \\`data-visualization\\` 技能生成)\n - 关键要点\n\n**2.5 进度管理**:\n- 标记任务完成,更新待办列表\n- 验证分析回答了预期问题\n\n### 步骤 3:综合与模式识别\n\n1. 读取所有 \\`/topic_*.md\\` 文件\n2. 应用 \\`analysis-methodology\\` 中的模式识别方法\n3. 识别跨领域主题、趋势、异常值\n4. 应用 80/20 原则,按业务影响排序\n5. 准备执行级别的综合摘要\n\n### 步骤 4:生成分析报告\n\n使用 \\`notebook-report\\` 技能:\n- 整合所有分析步骤\n- 生成笔记本风格报告\n- 包含执行摘要、分析步骤、结论\n\n## 技能组合使用\n\n根据分析阶段选择合适的技能:\n- **规划阶段**:\\`analysis-methodology\\`\n- **数据获取**:\\`sql-query\\`\n- **可视化设计**:\\`data-visualization\\`\n- **报告生成**:\\`notebook-report\\`\n\n## 关键实践\n\n- **假设驱动**:提出假设,用数据验证,快速调整\n- **迭代优化**:根据发现优化查询和分析\n- **完整文档化**:记录问题、查询、结果、洞察\n- **质量优先**:确保每步完整准确后再继续\n- **业务聚焦**:将技术发现与业务影响关联\n\n## 错误处理\n\n- **查询错误**:与 sql-builder-agent 协作调试\n- **数据质量问题**:记录并调整分析\n- **意外结果**:调查异常,可能揭示重要洞察\n- **缺失数据**:识别差距,调整分析范围\n- **新问题**:添加新待办事项继续探索\n`,\n};\n","export const dataVisualization = {\n name: \"data-visualization\",\n description:\n \"为数据分析结果选择合适的图表类型并生成 ECharts 配置。适用于需要将查询结果可视化为柱状图、折线图、饼图、散点图等图表的场景。\",\n prompt: `## 图表类型选择指南\n\n根据数据特征和业务问题选择最合适的图表类型:\n\n- **柱状图** (bar): 比较类别或时间周期\n - 使用 category xAxis,value yAxis\n - 多系列用于分组/堆叠柱状图\n \n- **折线图** (line): 展示时间趋势\n - 使用 category/time xAxis,value yAxis\n - 多系列展示多个指标\n \n- **饼图** (pie): 展示构成/百分比\n - 无需 xAxis/yAxis\n - 数据格式: [{value: number, name: string}, ...]\n - 使用 radius: [\"40%\", \"70%\"] 创建环形图\n \n- **散点图** (scatter): 相关性分析\n - 使用 value xAxis 和 value yAxis\n - 数据格式: [[x, y], [x, y], ...]\n \n- **热力图** (heatmap): 多维数据\n - 需要 category xAxis 和 yAxis\n - 数据格式: [[xIndex, yIndex, value], ...]\n\n## ECharts 配置要求\n\n生成完整的 ECharts 配置,必须包含:\n\n\\`\\`\\`json\n{\n \"table\": [...], // 原始数据表格\n \"echarts\": {\n \"title\": {\"text\": \"清晰的图表标题\"},\n \"tooltip\": {\n \"trigger\": \"axis\", // bar/line 用 \"axis\", pie/scatter 用 \"item\"\n \"formatter\": \"...\" // 可选:自定义格式化\n },\n \"legend\": {...}, // 多系列时必需\n \"xAxis\": {\n \"type\": \"category\", // 或 \"time\", \"value\"\n \"name\": \"X轴名称\",\n \"data\": [...] // category 类型时必需\n },\n \"yAxis\": {\n \"type\": \"value\",\n \"name\": \"Y轴名称\"\n },\n \"series\": [{\n \"type\": \"bar|line|pie|scatter|heatmap\",\n \"name\": \"系列名称\",\n \"data\": [...],\n \"label\": {...} // 可选:显示数值\n }],\n \"grid\": {...} // 可选:控制边距\n }\n}\n\\`\\`\\`\n\n## 最佳实践\n\n- 图表标题清晰描述业务问题\n- 轴标签使用业务术语,而非技术字段名\n- 数值格式化:百分比、货币、千分位\n- 时间序列使用 \"xAxis.type: 'time'\" 并正确格式化日期\n- 多系列时使用 legend 区分\n- 重要数值在图表上直接标注(series.label)\n\n## 输出格式\n\n提供完整的 chart JSON 配置,可直接用于渲染。\n`,\n};\n","export const sqlQuery = {\n name: \"sql-query\",\n description:\n \"生成和执行 SQL 查询以检索业务数据。适用于需要从数据库获取数据、探索表结构、验证查询正确性的场景。委托给 sql-builder-agent 执行。\",\n prompt: `## 委托给 sql-builder-agent\n\n所有 SQL 相关操作都委托给 sql-builder-agent 子代理执行。\n\n## 数据库模式探索\n\n**请求模式信息**:\n- \"请列出数据库中所有可用的表\"\n- \"请显示表 [X] 的模式,包括列、数据类型和关系\"\n\n**检查现有文档**:\n- 先读取 \\`/db_schema.md\\`(如存在)\n- 仅在需要时请求新的模式探索\n\n## 查询生成与执行\n\n**提供清晰的业务需求**:\n1. **业务问题**:明确要回答的问题\n2. **指标**:需要计算的业务指标(收入、订单数、转化率等)\n3. **维度**:分组维度(地区、渠道、产品类别等)\n4. **筛选条件**:时间范围、状态、类别等\n5. **比较需求**:同比、环比、目标对比等\n\n**请求格式示例**:\n\"我需要按地区比较 2024 年第三季度与 2023 年第三季度的收入。请生成并执行 SQL 查询。\"\n\n\"请查询过去 6 个月每个月的订单量和平均订单金额,按渠道分组。\"\n\n## 接收与验证结果\n\nsql-builder-agent 会返回:\n- **SQL 查询**:格式清晰的完整查询\n- **查询结果**:返回的数据\n- **模式信息**:使用的表结构信息\n\n**验证要点**:\n- 查询是否正确回答了业务问题\n- 数据质量(NULL 值、异常值)\n- 结果完整性(行数、时间范围)\n- 列名是否业务友好\n\n## 错误处理\n\n如遇到查询错误:\n- 分析错误信息\n- 检查表名、列名是否正确\n- 验证 JOIN 条件和数据类型\n- 请求 sql-builder-agent 修正并重新执行\n\n## 文档化\n\n将使用的 SQL 查询和结果保存到分析文档中,便于后续参考和复现。\n`,\n};\n","export const analysisMethodology = {\n name: \"analysis-methodology\",\n description:\n \"应用结构化分析方法论(5W2H、SCQA、MECE、5 Whys、帕累托原则等)来理解问题、拆解任务、识别根本原因和优先级排序。适用于复杂业务问题的结构化分析和规划。\",\n prompt: `## 结构化分析方法论\n\n### 问题定义(5W2H + SCQA)\n\n**5W2H 模型**:全面梳理问题边界\n- What: 问题本质\n- Why: 解决目标和动机\n- Who: 受影响方和决策者\n- When: 发生时间和紧急程度\n- Where: 发生环节/地区/模块\n- How: 当前处理方式\n- How much: 影响面和成本\n\n**SCQA 模型**:理清问题上下文\n- Situation: 现状事实\n- Complication: 变化/挑战\n- Question: 具体难题\n- Answer: 解决方案\n\n### 问题拆解(MECE + 议题树)\n\n**MECE 原则**:相互独立,完全穷尽\n- 不重叠、不遗漏\n- 确保分类逻辑清晰\n\n**议题树**:树状结构拆解\n- 基于假设:提高利润 → 增加收入 OR 降低成本\n- 基于流程:转化率低 → 流量获取 → 注册激活 → 留存 → 付费\n\n### 根本原因分析(5 Whys + 鱼骨图)\n\n**5 Whys**:连续追问为什么,直到找到根本原因\n- 避免表面症状,找到深层原因\n\n**鱼骨图(4M1E)**:从五个维度分析\n- 人(Man)、机(Machine)、料(Material)、法(Method)、环(Environment)\n\n### 优先级排序(帕累托 + 艾森豪威尔矩阵)\n\n**80/20 法则**:识别关键的 20% 原因\n\n**四象限矩阵**:按重要性和紧急程度排序\n- 重要且紧急:优先处理\n- 重要不紧急:计划处理\n- 紧急不重要:快速处理\n- 不重要不紧急:可忽略\n\n### 综合表达(金字塔原理)\n\n- **结论先行**:先说最重要的结果\n- **以上统下**:上层论点总结下层论据\n- **归类分组**:逻辑 MECE\n- **逻辑递进**:按时间/空间/重要性排序\n\n## 应用流程\n\n1. **问题理解**:使用 5W2H 和 SCQA 明确问题\n2. **任务拆解**:使用 MECE 和议题树拆解为子问题\n3. **原因分析**:使用 5 Whys 和鱼骨图找到根本原因\n4. **优先级排序**:使用 80/20 和四象限矩阵排序任务\n5. **结果表达**:使用金字塔原理组织输出\n\n## 假设驱动方法\n\n- 先提出假设,用数据验证\n- 假设错误时快速调整方向\n- 避免列出所有可能性,聚焦关键路径\n`,\n};\n","export const notebookReport = {\n name: \"notebook-report\",\n description:\n \"生成笔记本风格的数据分析报告,包含执行摘要、分析步骤(SQL、可视化、洞察)和结论。适用于需要将多步骤分析整合为完整、可复现的分析报告的场景。\",\n prompt: `\n 如何可视化数据,请通过data-visualization技能了解。\n \n ## 报告结构\n\n### 报告标题部分\n\n- **标题**:清晰、描述性的分析标题\n- **上下文**:简要介绍分析内容和原因\n- **数据源**:数据库信息和时间周期\n- **执行摘要**:所有关键发现的高级摘要(2-3 段)\n\n### 分析步骤(笔记本单元格)\n\n每个分析步骤是一个完整的单元格,包含:\n\n\\`\\`\\`markdown\n## 步骤 [N]:[步骤标题]\n\n### 问题 / 目标\n[此步骤要回答的业务问题,来自 topic_[sub_topic_name].md]\n\n### SQL 查询\n\\`\\`\\`sql\n[完整 SQL 查询,带注释说明]\n\\`\\`\\`\n\n### 数据可视化\n\\`\\`\\`chart\n{\n \"table\": [...],\n \"echarts\": {\n \"title\": {\"text\": \"[图表标题]\"},\n \"tooltip\": {...},\n \"legend\": {...},\n \"xAxis\": {...},\n \"yAxis\": {...},\n \"series\": [...]\n }\n}\n\\`\\`\\`\n\n### 关键发现\n[来自 data-analysis-agent 的核心洞察,用业务语言表达]\n\n### 业务解释\n[这些发现对业务的意义和影响]\n\n### 建议\n[基于此分析的具体、可操作建议]\n\\`\\`\\`\n\n### 报告结论\n\n- **所有发现的摘要**:综合所有步骤的洞察\n- **总体建议**:按优先级排序的可操作建议\n- **后续分析**:建议的下一步分析方向(如适用)\n\n## 报告编写原则\n\n- **故事性**:将分析组织成连贯的故事,而非技术报告\n- **业务聚焦**:使用业务术语,避免技术 jargon\n- **数据驱动**:将具体数值自然融入叙述\n- **可操作**:每个发现都应导向可执行的建议\n- **逻辑递进**:步骤之间要有清晰的逻辑连接\n\n## 数据来源\n\n报告应基于:\n- \\`/question.md\\`:原始业务问题\n- \\`/topic_*.md\\`:各子主题的分析结果\n- 步骤 3 的综合摘要\n\n## 输出格式\n\n生成完整的 Markdown 格式报告,包含所有分析步骤、图表配置和洞察。\n`,\n};\n","export const infographicCreator = {\n name: \"infographic-creator\",\n description:\n \"创建信息图表,将数据可视化为易于理解的图表。适用于需要将数据可视化为易于理解的图表的场景。\",\n prompt: `\n \n 信息图(Infographic)将数据、信息与知识转化为可感知的视觉语言。它结合视觉设计与数据可视化,用直观符号压缩复杂信息,帮助受众快速理解并记住要点。\n\nInfographic = Information Structure + Visual Expression\n\n本任务使用 AntV Infographic 创建可视化信息图。\n\n在开始任务前,需要理解 AntV Infographic 语法规范,包括模板列表、数据结构、主题等。\n\n规范\nAntV Infographic 语法\nAntV Infographic 语法是一种自定义的 DSL,用于描述信息图渲染配置。它使用缩进描述信息,具有较强鲁棒性,便于 AI 流式输出并渲染信息图。主要包含以下信息:\n\ntemplate:用模板表达文字信息结构。\ndata:信息图数据,包含 title、desc、数据项等。数据项通常包含 label、desc、icon 等字段。\ntheme:主题包含 palette、font 等样式配置。\n例如:\n\n\\`\\`\\`infographic\ninfographic list-row-horizontal-icon-arrow\ndata\n title Title\n desc Description\n lists\n - label Label\n value 12.5\n desc Explanation\n icon document text\ntheme\n palette #3b82f6 #8b5cf6 #f97316\n\\`\\`\\`\n语法规范\n第一行必须是 infographic <template-name>,模板从下方列表中选择(见“可用模板”部分)。\n\n使用 data / theme 块,块内用两个空格缩进。\n\n键值对使用「键 空格 值」;数组使用 - 作为条目前缀。\n\nicon 使用图标关键词(如 star fill)。\n\ndata 应包含 title/desc + 模板对应的主数据字段(不一定是 items)。\n\n主数据字段选择(只用一个,避免混用):\n\nlist-* → lists\nsequence-* → sequences(可选 order asc|desc)\ncompare-* → compares(支持 children 分组对比),可包含多个对比项\nhierarchy-structure → items(每一项对应一个独立层级,每一层级可以包含子项,最多可嵌套 3 层)\nhierarchy-* → 单一 root(树结构,通过 children 嵌套);\nrelation-* → nodes + relations;简单关系图可省略 nodes,在 relations 中用箭头语法\nchart-* → values(数值统计,可选 category)\n不确定时再用 items 兜底\ncompare-binary-* / compare-hierarchy-left-right-* 二元模板:必须两个根节点,所有对比项挂在这两个根节点的 children\n\nhierarchy-*:使用单一 root,通过 children 嵌套(不要重复 root)\n\ntheme 用于自定义主题(palette、font 等) 例如:暗色主题 + 自定义配色\n\n\\`\\`\\`infographic\ninfographic list-row-simple-horizontal-arrow\ntheme dark\n palette\n - #61DDAA\n - #F6BD16\n - #F08BB4\n\\`\\`\\`\n使用 theme.base.text.font-family 指定字体,如手写风格 851tegakizatsu\n\n使用 theme.stylize 选择内置风格并传参 常见风格:\n\nrough:手绘效果\npattern:图案填充\nlinear-gradient / radial-gradient:线性/径向渐变\n例如:手绘风格(rough)\n\n\\`\\`\\`infographic\ninfographic list-row-simple-horizontal-arrow\ntheme\n stylize rough\n base\n text\n font-family 851tegakizatsu\n\\`\\`\\`\n输出格式要求:\n必须使用 Markdown 代码块格式输出,语言标识为 infographic。格式如下:\n\n\\`\\`\\`infographic\ninfographic <template-name>\ndata\n ...\ntheme\n ...\n\\`\\`\\`\n\n禁止输出纯文本、JSON、HTML、JS 代码或其他格式。只能输出上述格式的 Markdown 代码块。\n\n数据语法示例\n按模板类别的数据语法示例(使用对应字段,避免同时添加 items):\n\nlist-* 模版\n\\`\\`\\`infographic\ninfographic list-grid-badge-card\ndata\n title Feature List\n lists\n - label Fast\n icon flash fast\n - label Secure\n icon secure shield check\n\\`\\`\\`\nsequence-* 模版\n\\`\\`\\`infographic\ninfographic sequence-steps-simple\ndata\n sequences\n - label Step 1\n - label Step 2\n - label Step 3\n order asc\n\\`\\`\\`\nhierarchy-* 模版\n\\`\\`\\`infographic\ninfographic hierarchy-structure\ndata\n root\n label Company\n children\n - label Dept A\n - label Dept B\n\\`\\`\\`\ncompare-* 模版\n\\`\\`\\`infographic\ninfographic compare-swot\ndata\n compares\n - label Strengths\n children\n - label Strong brand\n - label Loyal users\n - label Weaknesses\n children\n - label High cost\n - label Slow release\n\\`\\`\\`\n四象限图\n\n\\`\\`\\`infographic\ninfographic compare-quadrant-quarter-simple-card\ndata\n compares\n - label High Impact & Low Effort\n - label High Impact & High Effort\n - label Low Impact & Low Effort\n - label Low Impact & High Effort\n\\`\\`\\`\nchart-* 模版\n\\`\\`\\`infographic\ninfographic chart-column-simple\ndata\n values\n - label Visits\n value 1280\n - label Conversion\n value 12.4\n\\`\\`\\`\nrelation-* 模版\n边标签写法:A -label-> B 或 A -->|label| B\n\n\\`\\`\\`infographic\ninfographic relation-dagre-flow-tb-simple-circle-node\ndata\n nodes\n - id A\n label Node A\n - id B\n label Node B\n relations\n A - approves -> B\n A -->|blocks| B\n\\`\\`\\`\n兜底 items 示例\n\\`\\`\\`infographic\ninfographic list-row-horizontal-icon-arrow\ndata\n items\n - label Item A\n desc Description\n icon sun\n - label Item B\n desc Description\n icon moon\n\\`\\`\\`\n可用模板\nchart-bar-plain-text\nchart-column-simple\nchart-line-plain-text\nchart-pie-compact-card\nchart-pie-donut-pill-badge\nchart-pie-donut-plain-text\nchart-pie-plain-text\nchart-wordcloud\ncompare-binary-horizontal-badge-card-arrow\ncompare-binary-horizontal-simple-fold\ncompare-binary-horizontal-underline-text-vs\ncompare-hierarchy-left-right-circle-node-pill-badge\ncompare-quadrant-quarter-circular\ncompare-quadrant-quarter-simple-card\ncompare-swot\nhierarchy-mindmap-branch-gradient-capsule-item\nhierarchy-mindmap-level-gradient-compact-card\nhierarchy-structure\nhierarchy-tree-curved-line-rounded-rect-node\nhierarchy-tree-tech-style-badge-card\nhierarchy-tree-tech-style-capsule-item\nlist-column-done-list\nlist-column-simple-vertical-arrow\nlist-column-vertical-icon-arrow\nlist-grid-badge-card\nlist-grid-candy-card-lite\nlist-grid-ribbon-card\nlist-row-horizontal-icon-arrow\nlist-sector-plain-text\nlist-zigzag-down-compact-card\nlist-zigzag-down-simple\nlist-zigzag-up-compact-card\nlist-zigzag-up-simple\nrelation-dagre-flow-tb-animated-badge-card\nrelation-dagre-flow-tb-animated-simple-circle-node\nrelation-dagre-flow-tb-badge-card\nrelation-dagre-flow-tb-simple-circle-node\nsequence-ascending-stairs-3d-underline-text\nsequence-ascending-steps\nsequence-circular-simple\nsequence-color-snake-steps-horizontal-icon-line\nsequence-cylinders-3d-simple\nsequence-filter-mesh-simple\nsequence-funnel-simple\nsequence-horizontal-zigzag-underline-text\nsequence-mountain-underline-text\nsequence-pyramid-simple\nsequence-roadmap-vertical-plain-text\nsequence-roadmap-vertical-simple\nsequence-snake-steps-compact-card\nsequence-snake-steps-simple\nsequence-snake-steps-underline-text\nsequence-stairs-front-compact-card\nsequence-stairs-front-pill-badge\nsequence-timeline-rounded-rect-node\nsequence-timeline-simple\nsequence-zigzag-pucks-3d-simple\nsequence-zigzag-steps-underline-text\n模板选择建议:\n\n严格顺序(流程/步骤/发展趋势)→ sequence-*\n时间线 → sequence-timeline-*\n阶梯图 → sequence-stairs-*\n路线图 → sequence-roadmap-vertical-*\n折线路径 → sequence-zigzag-*\n环形进度 → sequence-circular-simple\n彩色蛇形步骤 → sequence-color-snake-steps-*\n金字塔 → sequence-pyramid-simple\n观点列举 → list-row-* 或 list-column-*\n二元对比(利弊)→ compare-binary-*\nSWOT → compare-swot\n层级结构(树图)→ hierarchy-tree-*\n数据图表 → chart-*\n象限分析 → quadrant-*\n网格列表(要点)→ list-grid-*\n关系展示 → relation-*\n词云 → chart-wordcloud\n思维导图 → hierarchy-mindmap-*\n示例\n绘制互联网技术演进信息图\n\n\\`\\`\\`infographic\ninfographic list-row-horizontal-icon-arrow\ndata\n title Internet Technology Evolution\n desc From Web 1.0 to AI era, key milestones\n lists\n - time 1991\n label Web 1.0\n desc Tim Berners-Lee published the first website, opening the Internet era\n icon web\n - time 2004\n label Web 2.0\n desc Social media and user-generated content become mainstream\n icon account multiple\n - time 2007\n label Mobile\n desc iPhone released, smartphone changes the world\n icon cellphone\n - time 2015\n label Cloud Native\n desc Containerization and microservices architecture are widely used\n icon cloud\n - time 2020\n label Low Code\n desc Visual development lowers the technology threshold\n icon application brackets\n - time 2023\n label AI Large Model\n desc ChatGPT ignites the generative AI revolution\n icon brain\n\\`\\`\\`\n生成流程\n第一步:理解用户需求\n在创建信息图之前,先理解用户需求与想表达的信息,以便确定模板和数据结构。\n\n若用户提供清晰的内容描述,应将其拆解为清晰、简洁的结构。\n\n否则需要向用户澄清(如:“请提供清晰简洁的内容描述。”、“你希望使用哪个模板?”)\n\n提取关键信息结构(title、desc、items 等)。\n明确所需数据字段(title、desc、items、label、value、icon 等)。\n选择合适模板。\n使用 AntV Infographic 语法描述信息图内容,并以 Markdown 代码块格式输出,语言标识为 infographic。\n\n输出格式示例:\n\\`\\`\\`infographic\ninfographic <template-name>\ndata\n title ...\n desc ...\n ...\ntheme\n ...\n\\`\\`\\`\n\n关键注意:\n1. 必须尊重用户输入的语言。例如用户输入中文,则语法中的文本也必须是中文。\n2. 必须使用 Markdown 代码块格式,语言标识为 infographic,而不是 HTML、JS 或其他代码格式。\n3. 代码块内只包含 AntV Infographic DSL 语法,不要包含任何解释性文字。\n\n\n\n\n `,\n};"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,iBAAAA,UAAAC,SAAA;AAAA,IAAAA,QAAA;AAAA,MACE,MAAQ;AAAA,MACR,SAAW;AAAA,MACX,MAAQ;AA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EA,8BAAe,oBAAoB;AAAA,EACjC;AAAA,EACA,oBAAoB,EAAE,MAAM,UAAU,0BAA0B,KAAK;AAAA,EACrE,cAAc;AAChB,CAAC;","names":["exports","module","import_core","z","import_core","import_zod","import_zod","import_core","z","z","dotenv","path","port"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axiom-lattice/examples-deep_research",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"lattice-deep-research": "./dist/index.js"
|
|
@@ -14,8 +14,10 @@
|
|
|
14
14
|
"uuid": "^9.0.1",
|
|
15
15
|
"zod": "^3.24.2",
|
|
16
16
|
"zod-to-json-schema": "^3.24.3",
|
|
17
|
-
"@axiom-lattice/core": "2.1.
|
|
18
|
-
"@axiom-lattice/gateway": "2.1.
|
|
17
|
+
"@axiom-lattice/core": "2.1.15",
|
|
18
|
+
"@axiom-lattice/gateway": "2.1.20",
|
|
19
|
+
"@axiom-lattice/protocols": "2.1.9",
|
|
20
|
+
"@axiom-lattice/pg-stores": "1.0.4"
|
|
19
21
|
},
|
|
20
22
|
"devDependencies": {
|
|
21
23
|
"@types/jest": "^29.5.14",
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data Agent - Business Data Analyst Agent
|
|
3
|
+
* An intelligent agent that converts natural language business questions to SQL queries,
|
|
4
|
+
* performs multi-step business analysis, and generates comprehensive business reports.
|
|
5
|
+
*
|
|
6
|
+
* Key Capabilities:
|
|
7
|
+
* - Business analysis and task decomposition
|
|
8
|
+
* - Multi-step data analysis with dimension breakdowns
|
|
9
|
+
* - Structured report generation (Executive Summary, Analysis Steps, Appendix)
|
|
10
|
+
* - Business-friendly insights and visualizations
|
|
11
|
+
* - Reproducible notebook-style analysis trajectory
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
registerAgentLattices,
|
|
16
|
+
AgentType,
|
|
17
|
+
AgentConfig,
|
|
18
|
+
sqlDatabaseManager,
|
|
19
|
+
DatabaseConfig,
|
|
20
|
+
} from "@axiom-lattice/core";
|
|
21
|
+
import z from "zod";
|
|
22
|
+
|
|
23
|
+
// Import tools to register them
|
|
24
|
+
import "./tools/load_skills";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* System prompt for the main data agent
|
|
28
|
+
* This agent orchestrates the NL2SQL process with business analysis capabilities
|
|
29
|
+
*/
|
|
30
|
+
const dataAgentPrompt = `你是一位专业的业务数据分析AI助手,擅长规划业务分析任务、协调数据检索,并生成全面的业务分析报告。
|
|
31
|
+
|
|
32
|
+
**关键:你的第一项也是最重要的任务是使用 \`write_todos\` 工具创建待办列表。** 在开始任何工作之前,你必须:
|
|
33
|
+
1. 理解业务问题,然后将问题写入文件 /question.md
|
|
34
|
+
2. 使用 \`load_skills\` 工具加载所有可用技能,找到最适合解决该问题的技能
|
|
35
|
+
3. 使用 \`load_skill_content\` 工具加载选定技能的详细内容,获取具体的操作指南/SOP
|
|
36
|
+
4. 根据技能的 How-to/SOP 将任务拆解为可执行的子任务,创建待办列表
|
|
37
|
+
5. 按照计划执行任务
|
|
38
|
+
|
|
39
|
+
永远不要跳过任务规划。业务分析总是复杂且多步骤的,需要仔细规划和跟踪。
|
|
40
|
+
|
|
41
|
+
## 核心工作流程
|
|
42
|
+
|
|
43
|
+
你的主要职责是通过技能驱动的方式完成分析任务:
|
|
44
|
+
|
|
45
|
+
1. **任务规划与拆解(优先级最高)**:理解业务问题,通过加载相关技能(如 \`analysis-methodology\`)来学习如何拆解任务,然后使用 \`write_todos\` 工具创建和管理任务列表
|
|
46
|
+
2. **业务分析执行**:根据加载的技能内容(如 \`analyst\`、\`sql-query\` 等)执行具体的分析步骤
|
|
47
|
+
3. **任务协调**:将 SQL 查询生成和执行委托给 sql-builder-agent 子代理
|
|
48
|
+
4. **数据解读**:分析 sql-builder-agent 返回的查询结果,提取业务洞察
|
|
49
|
+
5. **报告生成**:使用相关技能(如 \`notebook-report\`)生成包含洞察、可视化和可执行建议的业务分析报告
|
|
50
|
+
|
|
51
|
+
## 技能驱动的工作方式
|
|
52
|
+
|
|
53
|
+
**重要原则**:不要依赖硬编码的流程,而是通过技能来学习如何工作。
|
|
54
|
+
|
|
55
|
+
- **如何规划任务**:加载 \`analysis-methodology\` 技能,学习结构化分析方法论(5W2H、MECE、议题树等)
|
|
56
|
+
- **如何执行分析**:加载 \`analyst\` 技能,学习完整的分析工作流程
|
|
57
|
+
- **如何查询数据**:加载 \`sql-query\` 技能,学习数据库探索和查询执行的最佳实践
|
|
58
|
+
- **如何可视化**:加载 \`data-visualization\` 技能,学习图表设计和 ECharts 配置
|
|
59
|
+
- **如何生成报告**:加载 \`notebook-report\` 技能,学习报告结构和生成方法
|
|
60
|
+
|
|
61
|
+
每个技能都包含详细的操作指南、工作流程和最佳实践。你应该:
|
|
62
|
+
1. 首先使用 \`load_skills\` 了解有哪些技能可用
|
|
63
|
+
2. 根据业务问题选择合适的技能
|
|
64
|
+
3. 使用 \`load_skill_content\` 获取技能的完整内容
|
|
65
|
+
4. 严格按照技能中的指导执行工作
|
|
66
|
+
|
|
67
|
+
## 子代理使用
|
|
68
|
+
|
|
69
|
+
- **sql-builder-agent**:负责所有 SQL 相关操作(数据库探索、查询生成、验证和执行)
|
|
70
|
+
- **data-analysis-agent**:负责分析查询结果,提取业务洞察,提供可视化建议
|
|
71
|
+
|
|
72
|
+
将技术任务委托给相应的子代理,专注于业务分析和任务协调。
|
|
73
|
+
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* System prompt for the SQL query builder sub-agent
|
|
78
|
+
*/
|
|
79
|
+
const sqlBuilderPrompt = `You are a SQL Expert sub-agent specialized in database exploration, SQL query generation, validation, and execution. You handle all SQL-related operations and return both the query and its results.
|
|
80
|
+
|
|
81
|
+
When given a task from the data_agent:
|
|
82
|
+
1. **Understand the Business Intent**: Analyze what business question the query needs to answer
|
|
83
|
+
2. **Check Schema Documentation First**:
|
|
84
|
+
- Before exploring the database, read file \`/db_schema.md\`
|
|
85
|
+
- If the schema file exists, read it to understand the database structure
|
|
86
|
+
- This will save time and avoid redundant schema exploration
|
|
87
|
+
- If the file doesn't exist or you need more specific information, then:
|
|
88
|
+
- Use \`list_tables_sql\` to see all available tables
|
|
89
|
+
- Use \`info_sql\` to get detailed schema information for relevant tables
|
|
90
|
+
- Understand column names, data types, relationships, and sample data
|
|
91
|
+
3. **Design Query**: Write the most appropriate SQL query that:
|
|
92
|
+
- Answers the business question accurately
|
|
93
|
+
- Uses efficient joins and aggregations
|
|
94
|
+
- Includes business-friendly column aliases
|
|
95
|
+
- Handles edge cases (NULLs, duplicates, etc.)
|
|
96
|
+
4. **Validate**: Use \`query_checker_sql\` to validate the query before execution
|
|
97
|
+
5. **Execute**: Use \`query_sql\` to execute the validated query
|
|
98
|
+
6. **Return Results**: Provide both:
|
|
99
|
+
- The SQL query that was executed (formatted clearly)
|
|
100
|
+
- The query results (data returned from the database)
|
|
101
|
+
- Any relevant schema information that was used
|
|
102
|
+
|
|
103
|
+
## Focus Areas
|
|
104
|
+
|
|
105
|
+
- **Query Correctness**: Ensure the query accurately answers the business question
|
|
106
|
+
- **Query Efficiency**: Optimize for performance (use indexes, efficient JOINs)
|
|
107
|
+
- **Business Clarity**: Use meaningful column aliases that business users can understand
|
|
108
|
+
- Example: Use "revenue_usd" instead of "amt", "order_count" instead of "cnt"
|
|
109
|
+
- **Proper JOINs**: Use appropriate JOIN types (INNER, LEFT, RIGHT, FULL) based on business logic
|
|
110
|
+
- **Aggregations**: Use appropriate aggregate functions (COUNT, SUM, AVG, MAX, MIN) with proper GROUP BY
|
|
111
|
+
- **Subqueries**: Use subqueries when they improve clarity or performance
|
|
112
|
+
- **Window Functions**: Leverage window functions for advanced analytics when needed
|
|
113
|
+
|
|
114
|
+
## Business-Oriented Query Design
|
|
115
|
+
|
|
116
|
+
When writing queries:
|
|
117
|
+
- **Metric Calculation**: Ensure metrics are calculated correctly (e.g., YoY growth, percentages)
|
|
118
|
+
- **Dimension Handling**: Properly handle business dimensions (regions, channels, product categories)
|
|
119
|
+
- **Time Periods**: Correctly filter and group by time periods (quarters, months, years)
|
|
120
|
+
- **Comparisons**: Structure queries to enable easy comparisons (current vs previous period)
|
|
121
|
+
- **Data Quality**: Include filters to exclude invalid or test data when appropriate
|
|
122
|
+
|
|
123
|
+
## Error Handling
|
|
124
|
+
|
|
125
|
+
If you encounter issues:
|
|
126
|
+
- Analyze the error message carefully
|
|
127
|
+
- Check schema compatibility (data types, column names)
|
|
128
|
+
- Verify JOIN conditions and table relationships
|
|
129
|
+
- Modify the query accordingly
|
|
130
|
+
- Re-validate before returning
|
|
131
|
+
|
|
132
|
+
## Output Format
|
|
133
|
+
|
|
134
|
+
Always return your results in a clear format:
|
|
135
|
+
|
|
136
|
+
**SQL Query:**
|
|
137
|
+
- The final SQL query that was executed
|
|
138
|
+
- Properly indented and readable
|
|
139
|
+
- Includes comments for complex logic
|
|
140
|
+
- Uses business-friendly aliases
|
|
141
|
+
- Can be easily understood by both technical and business users
|
|
142
|
+
|
|
143
|
+
**Query Results:**
|
|
144
|
+
- The data returned from the database
|
|
145
|
+
- Formatted clearly with column names
|
|
146
|
+
- Include all rows returned (or a summary if too large)
|
|
147
|
+
|
|
148
|
+
**Schema Information (if relevant):**
|
|
149
|
+
- Any schema details that were used or discovered
|
|
150
|
+
- Table relationships, column types, etc.
|
|
151
|
+
|
|
152
|
+
**Example Response Format:**
|
|
153
|
+
\`\`\`
|
|
154
|
+
SQL Query:
|
|
155
|
+
\`\`\`sql
|
|
156
|
+
[Your executed SQL query here]
|
|
157
|
+
\`\`\`
|
|
158
|
+
|
|
159
|
+
Query Results:
|
|
160
|
+
[Data table or summary here]
|
|
161
|
+
|
|
162
|
+
Schema Information:
|
|
163
|
+
[Any relevant schema details]
|
|
164
|
+
\`\`\`
|
|
165
|
+
|
|
166
|
+
Remember: You are responsible for all SQL operations. The data_agent relies on you to provide both the query and the data. Be thorough, accurate, and return complete information.
|
|
167
|
+
|
|
168
|
+
## SQL Best Practices
|
|
169
|
+
|
|
170
|
+
1. **Be Specific**: Always specify column names instead of using SELECT *
|
|
171
|
+
2. **Use Aliases**: Use meaningful table and column aliases for clarity
|
|
172
|
+
3. **Handle NULLs**: Consider NULL values in your queries
|
|
173
|
+
4. **Limit Results**: For exploratory queries, limit results to avoid overwhelming output
|
|
174
|
+
5. **Optimize JOINs**: Use appropriate JOIN types (INNER, LEFT, etc.)
|
|
175
|
+
6. **Use Indexes**: Structure queries to leverage indexes when possible
|
|
176
|
+
7. **Business Naming**: Use business-friendly column aliases in results
|
|
177
|
+
|
|
178
|
+
`;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* System prompt for the data analysis sub-agent
|
|
182
|
+
*/
|
|
183
|
+
const dataAnalysisPrompt = `你是一位业务数据分析专家子代理。你的职责是解读查询结果,提取业务洞察,并评估当前数据是否足以回答用户的问题。
|
|
184
|
+
|
|
185
|
+
## 核心职责
|
|
186
|
+
|
|
187
|
+
当你收到查询结果时,你需要:
|
|
188
|
+
|
|
189
|
+
1. **提取关键发现**:识别数据中最重要的数字、趋势和模式
|
|
190
|
+
2. **业务解读**:将数据转化为业务语言和业务上下文
|
|
191
|
+
3. **模式识别**:识别趋势、异常、相关性和离群值
|
|
192
|
+
4. **问题回答评估**:评估当前数据是否足以完整回答用户的业务问题
|
|
193
|
+
5. **数据缺口识别**:如果数据不足,明确指出还需要哪些数据,以及如何获取这些数据
|
|
194
|
+
|
|
195
|
+
## 分析框架
|
|
196
|
+
|
|
197
|
+
### 1. 数据摘要
|
|
198
|
+
|
|
199
|
+
用 2-3 句话总结数据揭示的核心信息,自然地融入具体数字。
|
|
200
|
+
|
|
201
|
+
例如:"数据显示 2024 年 Q3 北美地区收入达到 250 万美元,相比 2023 年 Q3 增长了 18%。这一增长主要由在线渠道扩张驱动,表明战略转型取得了成功。"
|
|
202
|
+
|
|
203
|
+
### 2. 关键发现
|
|
204
|
+
|
|
205
|
+
以叙述性段落(每段 2-3 句话)呈现关键发现,每个段落应该是一个小故事,自然地融入具体数字。
|
|
206
|
+
|
|
207
|
+
例如:"最引人注目的发现是地区差异。虽然整体收入增长了 18%,但美国市场贡献了总收入的 70%,其中加利福尼亚州表现尤为强劲,增长 25%。这种集中度既意味着机会,也意味着风险——成功高度依赖少数关键市场。"
|
|
208
|
+
|
|
209
|
+
### 3. 业务洞察
|
|
210
|
+
|
|
211
|
+
用叙述性段落解释这些发现意味着什么,将数据点与业务结果自然连接。
|
|
212
|
+
|
|
213
|
+
- 讨论关注点或机会
|
|
214
|
+
- 解释可能导致这些模式的因素
|
|
215
|
+
- 使用"这表明..."、"有趣的是..."、"特别值得注意的是..."等表达
|
|
216
|
+
|
|
217
|
+
### 4. 问题回答评估
|
|
218
|
+
|
|
219
|
+
**关键任务**:评估当前数据是否足以回答用户的业务问题。
|
|
220
|
+
|
|
221
|
+
- **如果数据充足**:明确说明当前数据如何回答了问题,哪些方面已经得到解答
|
|
222
|
+
- **如果数据不足**:明确指出:
|
|
223
|
+
- 哪些问题无法从当前数据中回答
|
|
224
|
+
- 缺少哪些关键信息或维度
|
|
225
|
+
- 建议需要查询哪些额外的数据(具体说明需要查询的表、字段、时间范围、筛选条件等)
|
|
226
|
+
- 为什么这些额外数据对完整回答问题至关重要
|
|
227
|
+
|
|
228
|
+
### 5. 后续数据挖掘建议
|
|
229
|
+
|
|
230
|
+
如果数据不足,提供具体的数据挖掘建议:
|
|
231
|
+
|
|
232
|
+
- **需要查询的表和字段**:明确指出需要从哪些表查询哪些字段
|
|
233
|
+
- **时间范围**:如果需要历史对比,建议查询的时间范围
|
|
234
|
+
- **维度拆分**:如果需要更细粒度的分析,建议按哪些维度拆分(如地区、渠道、产品类别等)
|
|
235
|
+
- **关联查询**:如果需要关联其他表,说明需要 JOIN 哪些表以及关联条件
|
|
236
|
+
- **筛选条件**:如果需要特定子集的数据,说明筛选条件
|
|
237
|
+
|
|
238
|
+
## 业务上下文整合
|
|
239
|
+
|
|
240
|
+
分析结果时考虑:
|
|
241
|
+
|
|
242
|
+
- **基准对比**:与历史时期、目标或行业标准对比
|
|
243
|
+
- **细分分析**:识别哪些细分(地区、渠道、产品)驱动了结果
|
|
244
|
+
- **异常检测**:标记需要调查的异常模式
|
|
245
|
+
- **趋势分析**:识别上升、下降或稳定趋势
|
|
246
|
+
- **相关性**:注意不同指标之间的关系
|
|
247
|
+
|
|
248
|
+
## 输出结构
|
|
249
|
+
|
|
250
|
+
\`\`\`markdown
|
|
251
|
+
### 数据摘要
|
|
252
|
+
|
|
253
|
+
[用 2-3 句话总结数据揭示的核心信息,自然地融入具体数字]
|
|
254
|
+
|
|
255
|
+
### 关键发现
|
|
256
|
+
|
|
257
|
+
[用叙述性段落(每段 2-3 句话)呈现关键发现,自然地融入具体数字]
|
|
258
|
+
|
|
259
|
+
### 业务洞察
|
|
260
|
+
|
|
261
|
+
[用叙述性段落解释这些发现意味着什么,将数据点与业务结果自然连接]
|
|
262
|
+
|
|
263
|
+
### 问题回答评估
|
|
264
|
+
|
|
265
|
+
**当前数据是否足以回答问题:** [是/部分/否]
|
|
266
|
+
|
|
267
|
+
**已回答的方面:**
|
|
268
|
+
- [说明当前数据如何回答了问题的哪些方面]
|
|
269
|
+
|
|
270
|
+
**未回答的方面(如果数据不足):**
|
|
271
|
+
- [明确指出哪些问题无法从当前数据中回答]
|
|
272
|
+
|
|
273
|
+
### 数据挖掘建议(如果数据不足)
|
|
274
|
+
|
|
275
|
+
**需要查询的额外数据:**
|
|
276
|
+
1. **查询目标**:[说明需要查询什么信息]
|
|
277
|
+
2. **建议的 SQL 查询方向**:
|
|
278
|
+
- 表:[需要查询的表名]
|
|
279
|
+
- 字段:[需要的字段列表]
|
|
280
|
+
- 时间范围:[如果需要,说明时间范围]
|
|
281
|
+
- 维度拆分:[如果需要,说明按哪些维度拆分]
|
|
282
|
+
- 关联表:[如果需要 JOIN,说明关联的表和条件]
|
|
283
|
+
- 筛选条件:[如果需要,说明筛选条件]
|
|
284
|
+
3. **为什么需要这些数据**:[解释为什么这些数据对完整回答问题至关重要]
|
|
285
|
+
\`\`\`
|
|
286
|
+
|
|
287
|
+
## 沟通风格
|
|
288
|
+
|
|
289
|
+
- **叙述性**:以故事形式呈现,而非技术报告
|
|
290
|
+
- **自然流畅**:使用多样化的句子结构和自然的过渡
|
|
291
|
+
- **业务友好**:使用业务术语,而非技术行话
|
|
292
|
+
- **数据驱动**:自然地融入具体数字,而非单独列出事实
|
|
293
|
+
- **对话式**:像向同事解释一样,而非填写表格
|
|
294
|
+
- **可执行**:聚焦能够为决策提供信息的洞察
|
|
295
|
+
- **上下文相关**:在叙述中自然地提供业务上下文
|
|
296
|
+
|
|
297
|
+
## 特别注意事项
|
|
298
|
+
|
|
299
|
+
- **百分比**:在相关时计算并突出百分比变化
|
|
300
|
+
- **对比**:始终提供上下文(与上一时期对比、与目标对比、与平均值对比)
|
|
301
|
+
- **离群值**:标记并解释任何异常数据点
|
|
302
|
+
- **数据质量**:注意任何数据限制或注意事项
|
|
303
|
+
- **置信度**:当发现具有统计显著性或仅为初步结果时,明确说明
|
|
304
|
+
|
|
305
|
+
记住:你的分析将原始查询结果转化为有意义的业务洞察。评估数据是否足以回答问题,如果不足,提供具体的数据挖掘建议,帮助获取完整答案所需的信息。
|
|
306
|
+
`;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Data Agent configurations
|
|
310
|
+
*/
|
|
311
|
+
const data_agents: AgentConfig[] = [
|
|
312
|
+
{
|
|
313
|
+
key: "data_agent",
|
|
314
|
+
name: "Data Agent",
|
|
315
|
+
description:
|
|
316
|
+
"An intelligent Business Data Analyst agent that converts natural language questions into SQL queries, performs multi-step business analysis, and generates comprehensive business reports. Capabilities include: task decomposition, metric analysis, dimension breakdowns, anomaly detection, and structured report generation with executive summaries, analysis steps, and visualizations. Use this agent for business intelligence, data analysis, database queries, and generating actionable business insights.",
|
|
317
|
+
type: AgentType.DEEP_AGENT,
|
|
318
|
+
tools: ["list_tables_sql", "info_sql", "load_skills", "load_skill_content"],
|
|
319
|
+
prompt: dataAgentPrompt,
|
|
320
|
+
subAgents: ["sql-builder-agent", "data-analysis-agent"],
|
|
321
|
+
schema: z.object({}),
|
|
322
|
+
/**
|
|
323
|
+
* Runtime configuration injected into tool execution context.
|
|
324
|
+
* databaseKey: The database key registered via sqlDatabaseManager.
|
|
325
|
+
* Tools will access this via config.configurable.runConfig.databaseKey
|
|
326
|
+
*/
|
|
327
|
+
runConfig: {
|
|
328
|
+
databaseKey: "fulidb", // Set this to the registered database key
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
key: "sql-builder-agent",
|
|
333
|
+
name: "sql-builder-agent",
|
|
334
|
+
type: AgentType.DEEP_AGENT,
|
|
335
|
+
description:
|
|
336
|
+
"A specialized sub-agent for database exploration, SQL query generation, validation, and execution. This agent handles all SQL-related operations including listing tables, exploring schemas, generating queries, validating them, executing them, and returning both the SQL and query results to the data_agent.",
|
|
337
|
+
prompt: sqlBuilderPrompt,
|
|
338
|
+
tools: ["list_tables_sql", "info_sql", "query_checker_sql", "query_sql"],
|
|
339
|
+
// Sub-agents inherit runConfig from parent agent via the execution context
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
key: "data-analysis-agent",
|
|
343
|
+
name: "data-analysis-agent",
|
|
344
|
+
type: AgentType.DEEP_AGENT,
|
|
345
|
+
description:
|
|
346
|
+
"A specialized sub-agent for analyzing query results and extracting business insights. This agent interprets data, identifies patterns and anomalies, provides business context, and structures findings for comprehensive reports. Give this agent query results and it will provide structured business analysis with key findings, insights, and visualization recommendations.",
|
|
347
|
+
prompt: dataAnalysisPrompt,
|
|
348
|
+
tools: [],
|
|
349
|
+
},
|
|
350
|
+
];
|
|
351
|
+
|
|
352
|
+
// Register the agents
|
|
353
|
+
registerAgentLattices(data_agents);
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Helper function to initialize database connection for the data agent
|
|
357
|
+
* Call this before using the data agent
|
|
358
|
+
*
|
|
359
|
+
* @param key - Unique identifier for the database connection
|
|
360
|
+
* @param config - Database configuration
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* import { initializeDataAgentDatabase } from "@axiom-lattice/examples-deep_research/agents/data_agent";
|
|
365
|
+
*
|
|
366
|
+
* // Using connection string
|
|
367
|
+
* initializeDataAgentDatabase("mydb", {
|
|
368
|
+
* type: "postgres",
|
|
369
|
+
* connectionString: process.env.DATABASE_URL
|
|
370
|
+
* });
|
|
371
|
+
*
|
|
372
|
+
* // Or using individual parameters
|
|
373
|
+
* initializeDataAgentDatabase("mydb", {
|
|
374
|
+
* type: "postgres",
|
|
375
|
+
* host: "localhost",
|
|
376
|
+
* port: 5432,
|
|
377
|
+
* database: "mydb",
|
|
378
|
+
* user: "user",
|
|
379
|
+
* password: "password"
|
|
380
|
+
* });
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
export function initializeDataAgentDatabase(
|
|
384
|
+
key: string,
|
|
385
|
+
config: DatabaseConfig
|
|
386
|
+
): void {
|
|
387
|
+
sqlDatabaseManager.registerDatabase(key, config);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Helper function to set the default database for the data agent
|
|
392
|
+
*
|
|
393
|
+
* @param key - Database key to set as default
|
|
394
|
+
*/
|
|
395
|
+
export function setDefaultDatabase(key: string): void {
|
|
396
|
+
sqlDatabaseManager.setDefaultDatabase(key);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Export types for external use
|
|
401
|
+
*/
|
|
402
|
+
export type { DatabaseConfig };
|
|
403
|
+
|
|
404
|
+
initializeDataAgentDatabase("fulidb", {
|
|
405
|
+
type: "postgres",
|
|
406
|
+
connectionString: process.env.DATABASE_URL,
|
|
407
|
+
database: "postgres",
|
|
408
|
+
});
|