@axiom-lattice/examples-deep_research 1.0.13 → 1.0.14

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 CHANGED
@@ -18,7 +18,7 @@ VOLCENGINE_API_KEY2=a0533576-d6ed-4ca4-a308-473cbf7ebd10
18
18
 
19
19
  TAVILY_API_KEY=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
20
20
 
21
- # DATABASE_URL=postgresql://postgres.ldejdqkwvlllycysuvsr:jfd4whz@GPF2nqx7zhm@aws-0-ap-southeast-1.pooler.supabase.com:6543/postgres
21
+ DATABASE_URL=postgresql://postgres_fuli:jfd4whz%40GPF2nqx7zhm@pgm-uf615169n98t95tflo.pg.rds.aliyuncs.com:5432/postgres
22
22
  # QUEUE_NAME=simon_tasks
23
23
  # REDIS_URL=redis://localhost:6379
24
24
  # REDIS_PASSWORD=fina
@@ -1,5 +1,5 @@
1
1
 
2
- > @axiom-lattice/examples-deep_research@1.0.13 build /home/runner/work/agentic/agentic/examples/deep_research
2
+ > @axiom-lattice/examples-deep_research@1.0.14 build /home/runner/work/agentic/agentic/examples/deep_research
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -9,9 +9,9 @@
9
9
  CLI Target: es2020
10
10
  CLI Cleaning output folder
11
11
  CJS Build start
12
- CJS dist/index.js 14.28 KB
13
- CJS dist/index.js.map 16.33 KB
14
- CJS ⚡️ Build success in 34ms
12
+ CJS dist/index.js 20.25 KB
13
+ CJS dist/index.js.map 26.46 KB
14
+ CJS ⚡️ Build success in 30ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 5042ms
16
+ DTS ⚡️ Build success in 5094ms
17
17
  DTS dist/index.d.ts 13.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @axiom-lattice/examples-deep_research
2
2
 
3
+ ## 1.0.14
4
+
5
+ ### Patch Changes
6
+
7
+ - d43ea0b: add schedule task
8
+ - Updated dependencies [d43ea0b]
9
+ - @axiom-lattice/pg-stores@1.0.3
10
+ - @axiom-lattice/protocols@2.1.8
11
+ - @axiom-lattice/gateway@2.1.19
12
+ - @axiom-lattice/core@2.1.14
13
+
3
14
  ## 1.0.13
4
15
 
5
16
  ### Patch Changes
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var require_package = __commonJS({
31
31
  "package.json"(exports2, module2) {
32
32
  module2.exports = {
33
33
  name: "@axiom-lattice/examples-deep_research",
34
- version: "1.0.13",
34
+ version: "1.0.14",
35
35
  main: "dist/index.js",
36
36
  bin: {
37
37
  "lattice-deep-research": "./dist/index.js"
@@ -55,6 +55,8 @@ var require_package = __commonJS({
55
55
  dependencies: {
56
56
  "@axiom-lattice/core": "workspace:*",
57
57
  "@axiom-lattice/gateway": "workspace:*",
58
+ "@axiom-lattice/protocols": "workspace:*",
59
+ "@axiom-lattice/pg-stores": "workspace:*",
58
60
  dotenv: "^16.6.1",
59
61
  uuid: "^9.0.1",
60
62
  zod: "^3.24.2",
@@ -82,7 +84,7 @@ var require_package = __commonJS({
82
84
  // src/index.ts
83
85
  var import_dotenv = __toESM(require("dotenv"));
84
86
  var import_gateway = require("@axiom-lattice/gateway");
85
- var import_core2 = require("@axiom-lattice/core");
87
+ var import_core3 = require("@axiom-lattice/core");
86
88
 
87
89
  // src/agents/research/index.ts
88
90
  var import_core = require("@axiom-lattice/core");
@@ -232,6 +234,162 @@ var research_agents = [
232
234
  ];
233
235
  (0, import_core.registerAgentLattices)(research_agents);
234
236
 
237
+ // src/agents/data_agent/index.ts
238
+ var import_core2 = require("@axiom-lattice/core");
239
+ var import_zod2 = __toESM(require("zod"));
240
+ var dataAgentPrompt = `You are an expert Data Analyst AI assistant specialized in converting natural language questions into SQL queries and retrieving data from databases.
241
+
242
+ Your primary responsibilities:
243
+ 1. Understand user questions about data
244
+ 2. Explore the database schema to understand available tables and their relationships
245
+ 3. Write accurate and efficient SQL queries to answer questions
246
+ 4. Present results in a clear and understandable format
247
+
248
+ ## Workflow
249
+
250
+ When a user asks a question about data, follow these steps:
251
+
252
+ ### Step 1: Understand the Database Schema
253
+ - First, use the \`list_tables_sql\` tool to see all available tables
254
+ - Then, use the \`info_sql\` tool to get detailed schema information for relevant tables
255
+ - Pay attention to:
256
+ - Column names and data types
257
+ - Primary keys and foreign keys (relationships between tables)
258
+ - Sample data to understand the data format
259
+
260
+ ### Step 2: Plan Your Query
261
+ - Think about which tables you need to query
262
+ - Consider if you need to JOIN multiple tables
263
+ - Think about filtering conditions (WHERE clauses)
264
+ - Consider if you need aggregations (COUNT, SUM, AVG, etc.)
265
+ - Consider sorting and limiting results
266
+
267
+ ### Step 3: Validate Your Query
268
+ - Use the \`query_checker_sql\` tool to validate your SQL query before execution
269
+ - Fix any issues found by the checker
270
+ - Make sure the query is safe and efficient
271
+
272
+ ### Step 4: Execute and Present Results
273
+ - Use the \`query_sql\` tool to execute your validated query
274
+ - Present the results in a clear format
275
+ - Explain what the data means in context of the user's question
276
+ - If the results are unexpected, analyze and explain possible reasons
277
+
278
+ ## SQL Best Practices
279
+
280
+ 1. **Be Specific**: Always specify column names instead of using SELECT *
281
+ 2. **Use Aliases**: Use meaningful table and column aliases for clarity
282
+ 3. **Handle NULLs**: Consider NULL values in your queries
283
+ 4. **Limit Results**: For exploratory queries, limit results to avoid overwhelming output
284
+ 5. **Optimize JOINs**: Use appropriate JOIN types (INNER, LEFT, etc.)
285
+ 6. **Use Indexes**: Structure queries to leverage indexes when possible
286
+
287
+ ## Communication Guidelines
288
+
289
+ - Explain your thought process as you work
290
+ - If you need clarification about the user's question, ask
291
+ - If a query returns unexpected results, explain what might have happened
292
+ - Suggest follow-up queries or analyses that might be helpful
293
+ - Present data insights, not just raw results
294
+
295
+ ## Error Handling
296
+
297
+ - If a query fails, analyze the error message
298
+ - Try to fix the query and re-execute
299
+ - If you cannot answer the question due to data limitations, explain clearly what is missing
300
+
301
+ Remember: The goal is not just to write SQL, but to help users understand their data and make informed decisions.
302
+ `;
303
+ var sqlBuilderPrompt = `You are a SQL Expert sub-agent. Your job is to write precise, efficient SQL queries.
304
+
305
+ When given a task:
306
+ 1. Analyze the schema information provided
307
+ 2. Write the most appropriate SQL query
308
+ 3. Validate the query using query_checker_sql
309
+ 4. Return the finalized query
310
+
311
+ Focus on:
312
+ - Query correctness
313
+ - Query efficiency
314
+ - Proper use of JOINs and subqueries
315
+ - Appropriate use of aggregate functions
316
+ - Clear column naming and aliasing
317
+
318
+ If you encounter issues:
319
+ - Analyze the error
320
+ - Modify the query accordingly
321
+ - Re-validate before returning
322
+
323
+ Always return your final query in a clear format for execution.
324
+ `;
325
+ var dataAnalysisPrompt = `You are a Data Analysis Expert sub-agent. Your job is to interpret query results and provide insights.
326
+
327
+ When given query results:
328
+ 1. Summarize the key findings
329
+ 2. Identify patterns or anomalies
330
+ 3. Provide context and interpretation
331
+ 4. Suggest potential follow-up analyses
332
+
333
+ Focus on:
334
+ - Clear, concise summaries
335
+ - Statistical insights when appropriate
336
+ - Business context interpretation
337
+ - Visualization suggestions if applicable
338
+
339
+ Present your analysis in a structured format:
340
+ - Summary
341
+ - Key Findings
342
+ - Insights
343
+ - Recommendations (if any)
344
+ `;
345
+ var data_agents = [
346
+ {
347
+ key: "data_agent",
348
+ name: "Data Agent",
349
+ description: "An intelligent NL2SQL agent that converts natural language questions into SQL queries and retrieves data from databases. Use this agent for data analysis tasks, database queries, and data exploration.",
350
+ type: import_core2.AgentType.DEEP_AGENT,
351
+ tools: ["list_tables_sql", "info_sql", "query_sql", "query_checker_sql"],
352
+ prompt: dataAgentPrompt,
353
+ subAgents: ["sql-builder-agent", "data-analysis-agent"],
354
+ schema: import_zod2.default.object({}),
355
+ /**
356
+ * Runtime configuration injected into tool execution context.
357
+ * databaseKey: The database key registered via sqlDatabaseManager.
358
+ * Tools will access this via config.configurable.runConfig.databaseKey
359
+ */
360
+ runConfig: {
361
+ databaseKey: "fulidb"
362
+ // Set this to the registered database key
363
+ }
364
+ },
365
+ {
366
+ key: "sql-builder-agent",
367
+ name: "sql-builder-agent",
368
+ type: import_core2.AgentType.REACT,
369
+ description: "A specialized sub-agent for building and validating SQL queries. Give this agent schema information and a data question, and it will return an optimized SQL query.",
370
+ prompt: sqlBuilderPrompt,
371
+ tools: ["info_sql", "query_checker_sql"]
372
+ // Sub-agents inherit runConfig from parent agent via the execution context
373
+ },
374
+ {
375
+ key: "data-analysis-agent",
376
+ name: "data-analysis-agent",
377
+ type: import_core2.AgentType.REACT,
378
+ description: "A specialized sub-agent for analyzing query results and providing insights. Give this agent query results and it will provide a structured analysis.",
379
+ prompt: dataAnalysisPrompt,
380
+ tools: []
381
+ }
382
+ ];
383
+ (0, import_core2.registerAgentLattices)(data_agents);
384
+ function initializeDataAgentDatabase(key, config) {
385
+ import_core2.sqlDatabaseManager.registerDatabase(key, config);
386
+ }
387
+ initializeDataAgentDatabase("fulidb", {
388
+ type: "postgres",
389
+ connectionString: process.env.DATABASE_URL,
390
+ database: "postgres"
391
+ });
392
+
235
393
  // src/index.ts
236
394
  var import_path = __toESM(require("path"));
237
395
  var PACKAGE_VERSION = require_package().version;
@@ -269,7 +427,7 @@ function parsePort() {
269
427
  }
270
428
  return 4001;
271
429
  }
272
- (0, import_core2.registerModelLattice)(
430
+ (0, import_core3.registerModelLattice)(
273
431
  "default",
274
432
  // {
275
433
  // model: "deepseek-chat",
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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,KAAK,MAAM,CAAC;AACjC,QAAM,YAAY,KAAK,UAAU,CAAC,QAAQ,QAAQ,YAAY,QAAQ,IAAI;AAE1E,MAAI,cAAc,MAAM,KAAK,YAAY,CAAC,GAAG;AAC3C,UAAMC,QAAO,SAAS,KAAK,YAAY,CAAC,GAAG,EAAE;AAC7C,QAAI,CAAC,MAAMA,KAAI,KAAKA,QAAO,KAAKA,QAAO,OAAO;AAC5C,aAAOA;AAAA,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"],"sourcesContent":["{\n \"name\": \"@axiom-lattice/examples-deep_research\",\n \"version\": \"1.0.14\",\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 { ScheduleType } 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\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","/**\n * Data Agent - NL2SQL Agent\n * An intelligent agent that converts natural language questions to SQL queries\n * and retrieves data from connected databases.\n */\n\nimport {\n registerAgentLattices,\n AgentType,\n AgentConfig,\n sqlDatabaseManager,\n DatabaseConfig,\n} from \"@axiom-lattice/core\";\nimport z from \"zod\";\n\n/**\n * System prompt for the main data agent\n * This agent orchestrates the NL2SQL process\n */\nconst dataAgentPrompt = `You are an expert Data Analyst AI assistant specialized in converting natural language questions into SQL queries and retrieving data from databases.\n\nYour primary responsibilities:\n1. Understand user questions about data\n2. Explore the database schema to understand available tables and their relationships\n3. Write accurate and efficient SQL queries to answer questions\n4. Present results in a clear and understandable format\n\n## Workflow\n\nWhen a user asks a question about data, follow these steps:\n\n### Step 1: Understand the Database Schema\n- First, use the \\`list_tables_sql\\` tool to see all available tables\n- Then, use the \\`info_sql\\` tool to get detailed schema information for relevant tables\n- Pay attention to:\n - Column names and data types\n - Primary keys and foreign keys (relationships between tables)\n - Sample data to understand the data format\n\n### Step 2: Plan Your Query\n- Think about which tables you need to query\n- Consider if you need to JOIN multiple tables\n- Think about filtering conditions (WHERE clauses)\n- Consider if you need aggregations (COUNT, SUM, AVG, etc.)\n- Consider sorting and limiting results\n\n### Step 3: Validate Your Query\n- Use the \\`query_checker_sql\\` tool to validate your SQL query before execution\n- Fix any issues found by the checker\n- Make sure the query is safe and efficient\n\n### Step 4: Execute and Present Results\n- Use the \\`query_sql\\` tool to execute your validated query\n- Present the results in a clear format\n- Explain what the data means in context of the user's question\n- If the results are unexpected, analyze and explain possible reasons\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\n\n## Communication Guidelines\n\n- Explain your thought process as you work\n- If you need clarification about the user's question, ask\n- If a query returns unexpected results, explain what might have happened\n- Suggest follow-up queries or analyses that might be helpful\n- Present data insights, not just raw results\n\n## Error Handling\n\n- If a query fails, analyze the error message\n- Try to fix the query and re-execute\n- If you cannot answer the question due to data limitations, explain clearly what is missing\n\nRemember: The goal is not just to write SQL, but to help users understand their data and make informed decisions.\n`;\n\n/**\n * System prompt for the SQL query builder sub-agent\n */\nconst sqlBuilderPrompt = `You are a SQL Expert sub-agent. Your job is to write precise, efficient SQL queries.\n\nWhen given a task:\n1. Analyze the schema information provided\n2. Write the most appropriate SQL query\n3. Validate the query using query_checker_sql\n4. Return the finalized query\n\nFocus on:\n- Query correctness\n- Query efficiency\n- Proper use of JOINs and subqueries\n- Appropriate use of aggregate functions\n- Clear column naming and aliasing\n\nIf you encounter issues:\n- Analyze the error\n- Modify the query accordingly\n- Re-validate before returning\n\nAlways return your final query in a clear format for execution.\n`;\n\n/**\n * System prompt for the data analysis sub-agent\n */\nconst dataAnalysisPrompt = `You are a Data Analysis Expert sub-agent. Your job is to interpret query results and provide insights.\n\nWhen given query results:\n1. Summarize the key findings\n2. Identify patterns or anomalies\n3. Provide context and interpretation\n4. Suggest potential follow-up analyses\n\nFocus on:\n- Clear, concise summaries\n- Statistical insights when appropriate\n- Business context interpretation\n- Visualization suggestions if applicable\n\nPresent your analysis in a structured format:\n- Summary\n- Key Findings\n- Insights\n- Recommendations (if any)\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 NL2SQL agent that converts natural language questions into SQL queries and retrieves data from databases. Use this agent for data analysis tasks, database queries, and data exploration.\",\n type: AgentType.DEEP_AGENT,\n tools: [\"list_tables_sql\", \"info_sql\", \"query_sql\", \"query_checker_sql\"],\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.REACT,\n description:\n \"A specialized sub-agent for building and validating SQL queries. Give this agent schema information and a data question, and it will return an optimized SQL query.\",\n prompt: sqlBuilderPrompt,\n tools: [\"info_sql\", \"query_checker_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.REACT,\n description:\n \"A specialized sub-agent for analyzing query results and providing insights. Give this agent query results and it will provide a structured analysis.\",\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"],"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,0BAA0B;AAAA,QAC1B,4B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","import_core","z","import_core","import_zod","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.13",
3
+ "version": "1.0.14",
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.13",
18
- "@axiom-lattice/gateway": "2.1.18"
17
+ "@axiom-lattice/core": "2.1.14",
18
+ "@axiom-lattice/gateway": "2.1.19",
19
+ "@axiom-lattice/protocols": "2.1.8",
20
+ "@axiom-lattice/pg-stores": "1.0.3"
19
21
  },
20
22
  "devDependencies": {
21
23
  "@types/jest": "^29.5.14",
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Data Agent - NL2SQL Agent
3
+ * An intelligent agent that converts natural language questions to SQL queries
4
+ * and retrieves data from connected databases.
5
+ */
6
+
7
+ import {
8
+ registerAgentLattices,
9
+ AgentType,
10
+ AgentConfig,
11
+ sqlDatabaseManager,
12
+ DatabaseConfig,
13
+ } from "@axiom-lattice/core";
14
+ import z from "zod";
15
+
16
+ /**
17
+ * System prompt for the main data agent
18
+ * This agent orchestrates the NL2SQL process
19
+ */
20
+ const dataAgentPrompt = `You are an expert Data Analyst AI assistant specialized in converting natural language questions into SQL queries and retrieving data from databases.
21
+
22
+ Your primary responsibilities:
23
+ 1. Understand user questions about data
24
+ 2. Explore the database schema to understand available tables and their relationships
25
+ 3. Write accurate and efficient SQL queries to answer questions
26
+ 4. Present results in a clear and understandable format
27
+
28
+ ## Workflow
29
+
30
+ When a user asks a question about data, follow these steps:
31
+
32
+ ### Step 1: Understand the Database Schema
33
+ - First, use the \`list_tables_sql\` tool to see all available tables
34
+ - Then, use the \`info_sql\` tool to get detailed schema information for relevant tables
35
+ - Pay attention to:
36
+ - Column names and data types
37
+ - Primary keys and foreign keys (relationships between tables)
38
+ - Sample data to understand the data format
39
+
40
+ ### Step 2: Plan Your Query
41
+ - Think about which tables you need to query
42
+ - Consider if you need to JOIN multiple tables
43
+ - Think about filtering conditions (WHERE clauses)
44
+ - Consider if you need aggregations (COUNT, SUM, AVG, etc.)
45
+ - Consider sorting and limiting results
46
+
47
+ ### Step 3: Validate Your Query
48
+ - Use the \`query_checker_sql\` tool to validate your SQL query before execution
49
+ - Fix any issues found by the checker
50
+ - Make sure the query is safe and efficient
51
+
52
+ ### Step 4: Execute and Present Results
53
+ - Use the \`query_sql\` tool to execute your validated query
54
+ - Present the results in a clear format
55
+ - Explain what the data means in context of the user's question
56
+ - If the results are unexpected, analyze and explain possible reasons
57
+
58
+ ## SQL Best Practices
59
+
60
+ 1. **Be Specific**: Always specify column names instead of using SELECT *
61
+ 2. **Use Aliases**: Use meaningful table and column aliases for clarity
62
+ 3. **Handle NULLs**: Consider NULL values in your queries
63
+ 4. **Limit Results**: For exploratory queries, limit results to avoid overwhelming output
64
+ 5. **Optimize JOINs**: Use appropriate JOIN types (INNER, LEFT, etc.)
65
+ 6. **Use Indexes**: Structure queries to leverage indexes when possible
66
+
67
+ ## Communication Guidelines
68
+
69
+ - Explain your thought process as you work
70
+ - If you need clarification about the user's question, ask
71
+ - If a query returns unexpected results, explain what might have happened
72
+ - Suggest follow-up queries or analyses that might be helpful
73
+ - Present data insights, not just raw results
74
+
75
+ ## Error Handling
76
+
77
+ - If a query fails, analyze the error message
78
+ - Try to fix the query and re-execute
79
+ - If you cannot answer the question due to data limitations, explain clearly what is missing
80
+
81
+ Remember: The goal is not just to write SQL, but to help users understand their data and make informed decisions.
82
+ `;
83
+
84
+ /**
85
+ * System prompt for the SQL query builder sub-agent
86
+ */
87
+ const sqlBuilderPrompt = `You are a SQL Expert sub-agent. Your job is to write precise, efficient SQL queries.
88
+
89
+ When given a task:
90
+ 1. Analyze the schema information provided
91
+ 2. Write the most appropriate SQL query
92
+ 3. Validate the query using query_checker_sql
93
+ 4. Return the finalized query
94
+
95
+ Focus on:
96
+ - Query correctness
97
+ - Query efficiency
98
+ - Proper use of JOINs and subqueries
99
+ - Appropriate use of aggregate functions
100
+ - Clear column naming and aliasing
101
+
102
+ If you encounter issues:
103
+ - Analyze the error
104
+ - Modify the query accordingly
105
+ - Re-validate before returning
106
+
107
+ Always return your final query in a clear format for execution.
108
+ `;
109
+
110
+ /**
111
+ * System prompt for the data analysis sub-agent
112
+ */
113
+ const dataAnalysisPrompt = `You are a Data Analysis Expert sub-agent. Your job is to interpret query results and provide insights.
114
+
115
+ When given query results:
116
+ 1. Summarize the key findings
117
+ 2. Identify patterns or anomalies
118
+ 3. Provide context and interpretation
119
+ 4. Suggest potential follow-up analyses
120
+
121
+ Focus on:
122
+ - Clear, concise summaries
123
+ - Statistical insights when appropriate
124
+ - Business context interpretation
125
+ - Visualization suggestions if applicable
126
+
127
+ Present your analysis in a structured format:
128
+ - Summary
129
+ - Key Findings
130
+ - Insights
131
+ - Recommendations (if any)
132
+ `;
133
+
134
+ /**
135
+ * Data Agent configurations
136
+ */
137
+ const data_agents: AgentConfig[] = [
138
+ {
139
+ key: "data_agent",
140
+ name: "Data Agent",
141
+ description:
142
+ "An intelligent NL2SQL agent that converts natural language questions into SQL queries and retrieves data from databases. Use this agent for data analysis tasks, database queries, and data exploration.",
143
+ type: AgentType.DEEP_AGENT,
144
+ tools: ["list_tables_sql", "info_sql", "query_sql", "query_checker_sql"],
145
+ prompt: dataAgentPrompt,
146
+ subAgents: ["sql-builder-agent", "data-analysis-agent"],
147
+ schema: z.object({}),
148
+ /**
149
+ * Runtime configuration injected into tool execution context.
150
+ * databaseKey: The database key registered via sqlDatabaseManager.
151
+ * Tools will access this via config.configurable.runConfig.databaseKey
152
+ */
153
+ runConfig: {
154
+ databaseKey: "fulidb", // Set this to the registered database key
155
+ },
156
+ },
157
+ {
158
+ key: "sql-builder-agent",
159
+ name: "sql-builder-agent",
160
+ type: AgentType.REACT,
161
+ description:
162
+ "A specialized sub-agent for building and validating SQL queries. Give this agent schema information and a data question, and it will return an optimized SQL query.",
163
+ prompt: sqlBuilderPrompt,
164
+ tools: ["info_sql", "query_checker_sql"],
165
+ // Sub-agents inherit runConfig from parent agent via the execution context
166
+ },
167
+ {
168
+ key: "data-analysis-agent",
169
+ name: "data-analysis-agent",
170
+ type: AgentType.REACT,
171
+ description:
172
+ "A specialized sub-agent for analyzing query results and providing insights. Give this agent query results and it will provide a structured analysis.",
173
+ prompt: dataAnalysisPrompt,
174
+ tools: [],
175
+ },
176
+ ];
177
+
178
+ // Register the agents
179
+ registerAgentLattices(data_agents);
180
+
181
+ /**
182
+ * Helper function to initialize database connection for the data agent
183
+ * Call this before using the data agent
184
+ *
185
+ * @param key - Unique identifier for the database connection
186
+ * @param config - Database configuration
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * import { initializeDataAgentDatabase } from "@axiom-lattice/examples-deep_research/agents/data_agent";
191
+ *
192
+ * // Using connection string
193
+ * initializeDataAgentDatabase("mydb", {
194
+ * type: "postgres",
195
+ * connectionString: process.env.DATABASE_URL
196
+ * });
197
+ *
198
+ * // Or using individual parameters
199
+ * initializeDataAgentDatabase("mydb", {
200
+ * type: "postgres",
201
+ * host: "localhost",
202
+ * port: 5432,
203
+ * database: "mydb",
204
+ * user: "user",
205
+ * password: "password"
206
+ * });
207
+ * ```
208
+ */
209
+ export function initializeDataAgentDatabase(
210
+ key: string,
211
+ config: DatabaseConfig
212
+ ): void {
213
+ sqlDatabaseManager.registerDatabase(key, config);
214
+ }
215
+
216
+ /**
217
+ * Helper function to set the default database for the data agent
218
+ *
219
+ * @param key - Database key to set as default
220
+ */
221
+ export function setDefaultDatabase(key: string): void {
222
+ sqlDatabaseManager.setDefaultDatabase(key);
223
+ }
224
+
225
+ /**
226
+ * Export types for external use
227
+ */
228
+ export type { DatabaseConfig };
229
+
230
+ initializeDataAgentDatabase("fulidb", {
231
+ type: "postgres",
232
+ connectionString: process.env.DATABASE_URL,
233
+ database: "postgres",
234
+ });
@@ -1,4 +1,3 @@
1
1
  //import "./todo";
2
2
  import "./research";
3
-
4
- // import "./property_viewing";
3
+ import "./data_agent";
package/src/index.ts CHANGED
@@ -2,11 +2,16 @@ 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 { ScheduleType } from "@axiom-lattice/protocols";
14
+ import { PostgreSQLScheduleStorage } from "@axiom-lattice/pg-stores";
10
15
  // 在文件开头添加
11
16
  const PACKAGE_VERSION = require("../package.json").version;
12
17
  const BUILD_TIME = new Date().toISOString();
@@ -96,6 +101,31 @@ registerModelLattice(
96
101
  );
97
102
  LatticeGateway.registerLatticeRoutes(LatticeGateway.app);
98
103
 
104
+ // // 注册 Schedule Lattice(使用 PostgreSQL 持久化)
105
+ // registerScheduleLattice("default", {
106
+ // name: "Default Scheduler",
107
+ // description: "Production scheduler with PostgreSQL",
108
+ // type: ScheduleType.POSTGRES,
109
+ // storage: new PostgreSQLScheduleStorage({
110
+ // poolConfig: process.env.DATABASE_URL || "",
111
+ // }),
112
+ // });
113
+
114
+ // const scheduler = getScheduleLattice("default");
115
+ // // 注册 Handler(每次服务启动时都需要注册)
116
+ // scheduler.registerHandler("send-email", async (payload, taskInfo) => {
117
+ // console.log("send-email", payload, taskInfo);
118
+ // });
119
+ // scheduler.restore();
120
+
121
+ // // 一次性延迟任务
122
+ // scheduler.scheduleOnce(
123
+ // "email-123",
124
+ // "send-email",
125
+ // { to: "user@example.com", subject: "Welcome!" },
126
+ // { delayMs: 60000 } // 1分钟后执行
127
+ // );
128
+
99
129
  const port = parsePort();
100
130
  console.log(`Starting server on port ${port}`);
101
131