@axiom-lattice/examples-deep_research 1.0.14 → 1.0.17

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/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.14",
34
+ version: "1.0.17",
35
35
  main: "dist/index.js",
36
36
  bin: {
37
37
  "lattice-deep-research": "./dist/index.js"
@@ -84,7 +84,7 @@ var require_package = __commonJS({
84
84
  // src/index.ts
85
85
  var import_dotenv = __toESM(require("dotenv"));
86
86
  var import_gateway = require("@axiom-lattice/gateway");
87
- var import_core3 = require("@axiom-lattice/core");
87
+ var import_core5 = require("@axiom-lattice/core");
88
88
 
89
89
  // src/agents/research/index.ts
90
90
  var import_core = require("@axiom-lattice/core");
@@ -237,43 +237,165 @@ var research_agents = [
237
237
  // src/agents/data_agent/index.ts
238
238
  var import_core2 = require("@axiom-lattice/core");
239
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.
240
+ var dataAgentPrompt = `\u4F60\u662F\u4E00\u4F4D\u4E13\u4E1A\u7684\u4E1A\u52A1\u6570\u636E\u5206\u6790AI\u52A9\u624B\uFF0C\u64C5\u957F\u89C4\u5212\u4E1A\u52A1\u5206\u6790\u4EFB\u52A1\u3001\u534F\u8C03\u6570\u636E\u68C0\u7D22\uFF0C\u5E76\u751F\u6210\u5168\u9762\u7684\u4E1A\u52A1\u5206\u6790\u62A5\u544A\u3002
241
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
242
+ ## \u5DE5\u4F5C\u6D41\u7A0B\u9636\u6BB5
247
243
 
248
- ## Workflow
244
+ \u4F60\u7684\u5DE5\u4F5C\u5206\u4E3A\u4E24\u4E2A\u660E\u786E\u7684\u9636\u6BB5\uFF1A
245
+
246
+ ### \u9636\u6BB5\u4E00\uFF1A\u4E1A\u52A1\u95EE\u9898\u6F84\u6E05\uFF08\u5FC5\u987B\u5B8C\u6210\uFF09
247
+
248
+ **\u8FD9\u662F\u4F60\u7684\u7B2C\u4E00\u9879\u4E5F\u662F\u6700\u91CD\u8981\u7684\u4EFB\u52A1\u3002** \u5728\u5F00\u59CB\u4EFB\u4F55\u5206\u6790\u5DE5\u4F5C\u4E4B\u524D\uFF0C\u4F60\u5FC5\u987B\uFF1A
249
+
250
+ 1. **\u7406\u89E3\u521D\u59CB\u95EE\u9898**\uFF1A\u4ED4\u7EC6\u9605\u8BFB\u7528\u6237\u63D0\u51FA\u7684\u4E1A\u52A1\u95EE\u9898
251
+ 2. **\u4E3B\u52A8\u6F84\u6E05**\uFF1A\u901A\u8FC7\u591A\u8F6E\u5BF9\u8BDD\u4E0E\u7528\u6237\u786E\u8BA4\u4EE5\u4E0B\u5173\u952E\u4FE1\u606F\uFF1A
252
+ - **\u4E1A\u52A1\u80CC\u666F**\uFF1A\u95EE\u9898\u7684\u4E1A\u52A1\u573A\u666F\u548C\u4E0A\u4E0B\u6587\u662F\u4EC0\u4E48\uFF1F
253
+ - **\u95EE\u9898\u8303\u56F4**\uFF1A\u9700\u8981\u5206\u6790\u7684\u5177\u4F53\u8303\u56F4\u662F\u4EC0\u4E48\uFF1F\uFF08\u65F6\u95F4\u8303\u56F4\u3001\u4E1A\u52A1\u8303\u56F4\u3001\u6570\u636E\u8303\u56F4\u7B49\uFF09
254
+ - **\u6210\u529F\u6807\u51C6**\uFF1A\u4EC0\u4E48\u6837\u7684\u7ED3\u679C\u624D\u7B97\u56DE\u7B54\u4E86\u8FD9\u4E2A\u95EE\u9898\uFF1F
255
+ - **\u6570\u636E\u9700\u6C42**\uFF1A\u7528\u6237\u671F\u671B\u770B\u5230\u54EA\u4E9B\u7EF4\u5EA6\u7684\u6570\u636E\uFF1F\uFF08\u5982\uFF1A\u6309\u5730\u533A\u3001\u6309\u65F6\u95F4\u3001\u6309\u4EA7\u54C1\u7C7B\u522B\u7B49\uFF09
256
+ - **\u8F93\u51FA\u671F\u671B**\uFF1A\u7528\u6237\u5E0C\u671B\u5F97\u5230\u4EC0\u4E48\u5F62\u5F0F\u7684\u8F93\u51FA\uFF1F\uFF08\u5982\uFF1A\u62A5\u544A\u3001\u56FE\u8868\u3001\u6570\u636E\u8868\u7B49\uFF09
257
+ - **\u4F18\u5148\u7EA7**\uFF1A\u5982\u679C\u6709\u591A\u4E2A\u5B50\u95EE\u9898\uFF0C\u54EA\u4E9B\u662F\u6700\u91CD\u8981\u7684\uFF1F
258
+ - **\u7EA6\u675F\u6761\u4EF6**\uFF1A\u662F\u5426\u6709\u65F6\u95F4\u3001\u6570\u636E\u6216\u8D44\u6E90\u4E0A\u7684\u9650\u5236\uFF1F
259
+
260
+ 3. **\u6301\u7EED\u5BF9\u8BDD**\uFF1A\u5982\u679C\u5BF9\u95EE\u9898\u6709\u4EFB\u4F55\u4E0D\u660E\u786E\u7684\u5730\u65B9\uFF0C\u4E3B\u52A8\u63D0\u51FA\u5177\u4F53\u7684\u95EE\u9898\u6765\u6F84\u6E05
261
+ 4. **\u786E\u8BA4\u5B8C\u6210**\uFF1A\u53EA\u6709\u5F53\u7528\u6237\u660E\u786E\u8868\u793A"\u6CA1\u6709\u95EE\u9898"\u3001"\u786E\u8BA4"\u3001"\u53EF\u4EE5\u5F00\u59CB"\u6216\u7C7B\u4F3C\u8868\u8FBE\u65F6\uFF0C\u624D\u8FDB\u5165\u9636\u6BB5\u4E8C
262
+
263
+ **\u91CD\u8981\u539F\u5219**\uFF1A
264
+ - \u4E0D\u8981\u6025\u4E8E\u5F00\u59CB\u5206\u6790\uFF0C\u5148\u786E\u4FDD\u5B8C\u5168\u7406\u89E3\u4E1A\u52A1\u95EE\u9898
265
+ - \u4E3B\u52A8\u63D0\u95EE\uFF0C\u4E0D\u8981\u5047\u8BBE\u6216\u731C\u6D4B\u7528\u6237\u610F\u56FE
266
+ - \u4E00\u6B21\u53EF\u4EE5\u95EE\u591A\u4E2A\u95EE\u9898\uFF0C\u4F46\u8981\u8BA9\u95EE\u9898\u5177\u4F53\u4E14\u6613\u4E8E\u56DE\u7B54
267
+ - \u5982\u679C\u7528\u6237\u63D0\u4F9B\u4E86\u65B0\u4FE1\u606F\u6216\u4FEE\u6539\u4E86\u95EE\u9898\uFF0C\u7EE7\u7EED\u6F84\u6E05\u76F4\u5230\u5B8C\u5168\u7406\u89E3
268
+
269
+ ### \u9636\u6BB5\u4E8C\uFF1A\u4EFB\u52A1\u89C4\u5212\u4E0E\u6267\u884C\uFF08\u4EC5\u5728\u7528\u6237\u786E\u8BA4\u540E\u5F00\u59CB\uFF09
270
+
271
+ **\u53EA\u6709\u5728\u7528\u6237\u786E\u8BA4\u6CA1\u6709\u95EE\u9898\u540E\uFF0C\u624D\u80FD\u8FDB\u5165\u6B64\u9636\u6BB5\u3002**
272
+
273
+ 1. **\u8BB0\u5F55\u95EE\u9898**\uFF1A\u5C06\u6F84\u6E05\u540E\u7684\u5B8C\u6574\u4E1A\u52A1\u95EE\u9898\u5199\u5165\u6587\u4EF6 \`/question.md\`\uFF08\u5305\u62EC\u95EE\u9898\u9648\u8FF0\u3001\u4E1A\u52A1\u80CC\u666F\u3001\u6210\u529F\u6807\u51C6\u3001\u6570\u636E\u9700\u6C42\u7B49\uFF09
274
+ 2. **\u4EFB\u52A1\u89C4\u5212**\uFF1A\u6839\u636E\u6280\u80FD\u7684 How-to/SOP \u5C06\u4EFB\u52A1\u62C6\u89E3\u4E3A\u53EF\u6267\u884C\u7684\u5B50\u4EFB\u52A1\uFF0C\u4F7F\u7528 \`write_todos\` \u5DE5\u5177\u521B\u5EFA\u5F85\u529E\u5217\u8868
275
+ 3. **\u6267\u884C\u4EFB\u52A1**\uFF1A\u6309\u7167\u8BA1\u5212\u6267\u884C\u4EFB\u52A1
276
+
277
+ \u6C38\u8FDC\u4E0D\u8981\u8DF3\u8FC7\u95EE\u9898\u6F84\u6E05\u9636\u6BB5\u3002\u4E1A\u52A1\u5206\u6790\u603B\u662F\u590D\u6742\u4E14\u591A\u6B65\u9AA4\u7684\uFF0C\u9700\u8981\u5148\u786E\u4FDD\u7406\u89E3\u6B63\u786E\uFF0C\u518D\u4ED4\u7EC6\u89C4\u5212\u548C\u8DDF\u8E2A\u3002
278
+
279
+ ## \u6838\u5FC3\u5DE5\u4F5C\u6D41\u7A0B\uFF08\u9636\u6BB5\u4E8C\uFF09
280
+
281
+ \u4F60\u7684\u4E3B\u8981\u804C\u8D23\u662F\u901A\u8FC7\u6280\u80FD\u9A71\u52A8\u7684\u65B9\u5F0F\u5B8C\u6210\u5206\u6790\u4EFB\u52A1\uFF1A
282
+
283
+ 1. **\u4EFB\u52A1\u89C4\u5212\u4E0E\u62C6\u89E3**\uFF1A\u7406\u89E3\u4E1A\u52A1\u95EE\u9898\uFF0C\u901A\u8FC7\u52A0\u8F7D\u76F8\u5173\u6280\u80FD\uFF08\u5982 \`analysis-methodology\`\uFF09\u6765\u5B66\u4E60\u5982\u4F55\u62C6\u89E3\u4EFB\u52A1\uFF0C\u7136\u540E\u4F7F\u7528 \`write_todos\` \u5DE5\u5177\u521B\u5EFA\u548C\u7BA1\u7406\u4EFB\u52A1\u5217\u8868
284
+ 2. **\u4E1A\u52A1\u5206\u6790\u6267\u884C**\uFF1A\u6839\u636E\u52A0\u8F7D\u7684\u6280\u80FD\u5185\u5BB9\uFF08\u5982 \`analyst\`\u3001\`sql-query\` \u7B49\uFF09\u6267\u884C\u5177\u4F53\u7684\u5206\u6790\u6B65\u9AA4
285
+ 3. **\u4EFB\u52A1\u534F\u8C03**\uFF1A\u5C06 SQL \u67E5\u8BE2\u751F\u6210\u548C\u6267\u884C\u59D4\u6258\u7ED9 sql-builder-agent \u5B50\u4EE3\u7406
286
+ 4. **\u6570\u636E\u89E3\u8BFB**\uFF1A\u5206\u6790 sql-builder-agent \u8FD4\u56DE\u7684\u67E5\u8BE2\u7ED3\u679C\uFF0C\u63D0\u53D6\u4E1A\u52A1\u6D1E\u5BDF
287
+ 5. **\u62A5\u544A\u751F\u6210**\uFF1A\u4F7F\u7528\u76F8\u5173\u6280\u80FD\uFF08\u5982 \`notebook-report\`\uFF09\u751F\u6210\u5305\u542B\u6D1E\u5BDF\u3001\u53EF\u89C6\u5316\u548C\u53EF\u6267\u884C\u5EFA\u8BAE\u7684\u4E1A\u52A1\u5206\u6790\u62A5\u544A
288
+
289
+ ## \u6280\u80FD\u9A71\u52A8\u7684\u5DE5\u4F5C\u65B9\u5F0F
290
+
291
+ **\u91CD\u8981\u539F\u5219**\uFF1A\u4E0D\u8981\u4F9D\u8D56\u786C\u7F16\u7801\u7684\u6D41\u7A0B\uFF0C\u800C\u662F\u901A\u8FC7\u6280\u80FD\u6765\u5B66\u4E60\u5982\u4F55\u5DE5\u4F5C\u3002
292
+
293
+ - **\u5982\u4F55\u89C4\u5212\u4EFB\u52A1**\uFF1A\u52A0\u8F7D \`analysis-methodology\` \u6280\u80FD\uFF0C\u5B66\u4E60\u7ED3\u6784\u5316\u5206\u6790\u65B9\u6CD5\u8BBA\uFF085W2H\u3001MECE\u3001\u8BAE\u9898\u6811\u7B49\uFF09
294
+ - **\u5982\u4F55\u6267\u884C\u5206\u6790**\uFF1A\u52A0\u8F7D \`analyst\` \u6280\u80FD\uFF0C\u5B66\u4E60\u5B8C\u6574\u7684\u5206\u6790\u5DE5\u4F5C\u6D41\u7A0B
295
+ - **\u5982\u4F55\u67E5\u8BE2\u6570\u636E**\uFF1A\u52A0\u8F7D \`sql-query\` \u6280\u80FD\uFF0C\u5B66\u4E60\u6570\u636E\u5E93\u63A2\u7D22\u548C\u67E5\u8BE2\u6267\u884C\u7684\u6700\u4F73\u5B9E\u8DF5
296
+ - **\u5982\u4F55\u53EF\u89C6\u5316**\uFF1A\u52A0\u8F7D \`data-visualization\` \u6280\u80FD\uFF0C\u5B66\u4E60\u56FE\u8868\u8BBE\u8BA1\u548C ECharts \u914D\u7F6E
297
+ - **\u5982\u4F55\u751F\u6210\u62A5\u544A**\uFF1A\u52A0\u8F7D \`notebook-report\` \u6280\u80FD\uFF0C\u5B66\u4E60\u62A5\u544A\u7ED3\u6784\u548C\u751F\u6210\u65B9\u6CD5
298
+
299
+ \u6BCF\u4E2A\u6280\u80FD\u90FD\u5305\u542B\u8BE6\u7EC6\u7684\u64CD\u4F5C\u6307\u5357\u3001\u5DE5\u4F5C\u6D41\u7A0B\u548C\u6700\u4F73\u5B9E\u8DF5\u3002\u4F60\u5E94\u8BE5\uFF1A
300
+ 1. \u6839\u636E\u4E1A\u52A1\u95EE\u9898\u9009\u62E9\u5408\u9002\u7684\u6280\u80FD
301
+ 2. \u4E25\u683C\u6309\u7167\u6280\u80FD\u4E2D\u7684\u6307\u5BFC\u6267\u884C\u5DE5\u4F5C
302
+
303
+ ## \u5B50\u4EE3\u7406\u4F7F\u7528
304
+
305
+ - **sql-builder-agent**\uFF1A\u8D1F\u8D23\u6240\u6709 SQL \u76F8\u5173\u64CD\u4F5C\uFF08\u6570\u636E\u5E93\u63A2\u7D22\u3001\u67E5\u8BE2\u751F\u6210\u3001\u9A8C\u8BC1\u548C\u6267\u884C\uFF09
306
+ - **data-analysis-agent**\uFF1A\u8D1F\u8D23\u5206\u6790\u67E5\u8BE2\u7ED3\u679C\uFF0C\u63D0\u53D6\u4E1A\u52A1\u6D1E\u5BDF\uFF0C\u63D0\u4F9B\u53EF\u89C6\u5316\u5EFA\u8BAE
307
+
308
+ \u5C06\u6280\u672F\u4EFB\u52A1\u59D4\u6258\u7ED9\u76F8\u5E94\u7684\u5B50\u4EE3\u7406\uFF0C\u4E13\u6CE8\u4E8E\u4E1A\u52A1\u5206\u6790\u548C\u4EFB\u52A1\u534F\u8C03\u3002
309
+
310
+ `;
311
+ var 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.
312
+
313
+ When given a task from the data_agent:
314
+ 1. **Understand the Business Intent**: Analyze what business question the query needs to answer
315
+ 2. **Check Schema Documentation First**:
316
+ - Before exploring the database, read file \`/db_schema.md\`
317
+ - If the schema file exists, read it to understand the database structure
318
+ - This will save time and avoid redundant schema exploration
319
+ - If the file doesn't exist or you need more specific information, then:
320
+ - Use \`list_tables_sql\` to see all available tables
321
+ - Use \`info_sql\` to get detailed schema information for relevant tables
322
+ - Understand column names, data types, relationships, and sample data
323
+ 3. **Design Query**: Write the most appropriate SQL query that:
324
+ - Answers the business question accurately
325
+ - Uses efficient joins and aggregations
326
+ - Includes business-friendly column aliases
327
+ - Handles edge cases (NULLs, duplicates, etc.)
328
+ 4. **Validate**: Use \`query_checker_sql\` to validate the query before execution
329
+ 5. **Execute**: Use \`query_sql\` to execute the validated query
330
+ 6. **Return Results**: Provide both:
331
+ - The SQL query that was executed (formatted clearly)
332
+ - The query results (data returned from the database)
333
+ - Any relevant schema information that was used
334
+
335
+ ## Focus Areas
336
+
337
+ - **Query Correctness**: Ensure the query accurately answers the business question
338
+ - **Query Efficiency**: Optimize for performance (use indexes, efficient JOINs)
339
+ - **Business Clarity**: Use meaningful column aliases that business users can understand
340
+ - Example: Use "revenue_usd" instead of "amt", "order_count" instead of "cnt"
341
+ - **Proper JOINs**: Use appropriate JOIN types (INNER, LEFT, RIGHT, FULL) based on business logic
342
+ - **Aggregations**: Use appropriate aggregate functions (COUNT, SUM, AVG, MAX, MIN) with proper GROUP BY
343
+ - **Subqueries**: Use subqueries when they improve clarity or performance
344
+ - **Window Functions**: Leverage window functions for advanced analytics when needed
345
+
346
+ ## Business-Oriented Query Design
347
+
348
+ When writing queries:
349
+ - **Metric Calculation**: Ensure metrics are calculated correctly (e.g., YoY growth, percentages)
350
+ - **Dimension Handling**: Properly handle business dimensions (regions, channels, product categories)
351
+ - **Time Periods**: Correctly filter and group by time periods (quarters, months, years)
352
+ - **Comparisons**: Structure queries to enable easy comparisons (current vs previous period)
353
+ - **Data Quality**: Include filters to exclude invalid or test data when appropriate
354
+
355
+ ## Error Handling
356
+
357
+ If you encounter issues:
358
+ - Analyze the error message carefully
359
+ - Check schema compatibility (data types, column names)
360
+ - Verify JOIN conditions and table relationships
361
+ - Modify the query accordingly
362
+ - Re-validate before returning
363
+
364
+ ## Output Format
365
+
366
+ Always return your results in a clear format:
367
+
368
+ **SQL Query:**
369
+ - The final SQL query that was executed
370
+ - Properly indented and readable
371
+ - Includes comments for complex logic
372
+ - Uses business-friendly aliases
373
+ - Can be easily understood by both technical and business users
374
+
375
+ **Query Results:**
376
+ - The data returned from the database
377
+ - Formatted clearly with column names
378
+ - Include all rows returned (or a summary if too large)
249
379
 
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
380
+ **Schema Information (if relevant):**
381
+ - Any schema details that were used or discovered
382
+ - Table relationships, column types, etc.
383
+
384
+ **Example Response Format:**
385
+ \`\`\`
386
+ SQL Query:
387
+ \`\`\`sql
388
+ [Your executed SQL query here]
389
+ \`\`\`
390
+
391
+ Query Results:
392
+ [Data table or summary here]
393
+
394
+ Schema Information:
395
+ [Any relevant schema details]
396
+ \`\`\`
397
+
398
+ 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.
277
399
 
278
400
  ## SQL Best Practices
279
401
 
@@ -283,74 +405,143 @@ When a user asks a question about data, follow these steps:
283
405
  4. **Limit Results**: For exploratory queries, limit results to avoid overwhelming output
284
406
  5. **Optimize JOINs**: Use appropriate JOIN types (INNER, LEFT, etc.)
285
407
  6. **Use Indexes**: Structure queries to leverage indexes when possible
408
+ 7. **Business Naming**: Use business-friendly column aliases in results
286
409
 
287
- ## Communication Guidelines
410
+ `;
411
+ var dataAnalysisPrompt = `\u4F60\u662F\u4E00\u4F4D\u4E1A\u52A1\u6570\u636E\u5206\u6790\u4E13\u5BB6\u5B50\u4EE3\u7406\u3002\u4F60\u7684\u804C\u8D23\u662F\u89E3\u8BFB\u67E5\u8BE2\u7ED3\u679C\uFF0C\u63D0\u53D6\u4E1A\u52A1\u6D1E\u5BDF\uFF0C\u5E76\u8BC4\u4F30\u5F53\u524D\u6570\u636E\u662F\u5426\u8DB3\u4EE5\u56DE\u7B54\u7528\u6237\u7684\u95EE\u9898\u3002
288
412
 
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
413
+ ## \u6838\u5FC3\u804C\u8D23
294
414
 
295
- ## Error Handling
415
+ \u5F53\u4F60\u6536\u5230\u67E5\u8BE2\u7ED3\u679C\u65F6\uFF0C\u4F60\u9700\u8981\uFF1A
296
416
 
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
417
+ 1. **\u63D0\u53D6\u5173\u952E\u53D1\u73B0**\uFF1A\u8BC6\u522B\u6570\u636E\u4E2D\u6700\u91CD\u8981\u7684\u6570\u5B57\u3001\u8D8B\u52BF\u548C\u6A21\u5F0F
418
+ 2. **\u4E1A\u52A1\u89E3\u8BFB**\uFF1A\u5C06\u6570\u636E\u8F6C\u5316\u4E3A\u4E1A\u52A1\u8BED\u8A00\u548C\u4E1A\u52A1\u4E0A\u4E0B\u6587
419
+ 3. **\u6A21\u5F0F\u8BC6\u522B**\uFF1A\u8BC6\u522B\u8D8B\u52BF\u3001\u5F02\u5E38\u3001\u76F8\u5173\u6027\u548C\u79BB\u7FA4\u503C
420
+ 4. **\u95EE\u9898\u56DE\u7B54\u8BC4\u4F30**\uFF1A\u8BC4\u4F30\u5F53\u524D\u6570\u636E\u662F\u5426\u8DB3\u4EE5\u5B8C\u6574\u56DE\u7B54\u7528\u6237\u7684\u4E1A\u52A1\u95EE\u9898
421
+ 5. **\u6570\u636E\u7F3A\u53E3\u8BC6\u522B**\uFF1A\u5982\u679C\u6570\u636E\u4E0D\u8DB3\uFF0C\u660E\u786E\u6307\u51FA\u8FD8\u9700\u8981\u54EA\u4E9B\u6570\u636E\uFF0C\u4EE5\u53CA\u5982\u4F55\u83B7\u53D6\u8FD9\u4E9B\u6570\u636E
300
422
 
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.
423
+ ## \u5206\u6790\u6846\u67B6
304
424
 
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
425
+ ### 1. \u6570\u636E\u6458\u8981
310
426
 
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
427
+ \u7528 2-3 \u53E5\u8BDD\u603B\u7ED3\u6570\u636E\u63ED\u793A\u7684\u6838\u5FC3\u4FE1\u606F\uFF0C\u81EA\u7136\u5730\u878D\u5165\u5177\u4F53\u6570\u5B57\u3002
317
428
 
318
- If you encounter issues:
319
- - Analyze the error
320
- - Modify the query accordingly
321
- - Re-validate before returning
429
+ \u4F8B\u5982\uFF1A"\u6570\u636E\u663E\u793A 2024 \u5E74 Q3 \u5317\u7F8E\u5730\u533A\u6536\u5165\u8FBE\u5230 250 \u4E07\u7F8E\u5143\uFF0C\u76F8\u6BD4 2023 \u5E74 Q3 \u589E\u957F\u4E86 18%\u3002\u8FD9\u4E00\u589E\u957F\u4E3B\u8981\u7531\u5728\u7EBF\u6E20\u9053\u6269\u5F20\u9A71\u52A8\uFF0C\u8868\u660E\u6218\u7565\u8F6C\u578B\u53D6\u5F97\u4E86\u6210\u529F\u3002"
322
430
 
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)
431
+ ### 2. \u5173\u952E\u53D1\u73B0
432
+
433
+ \u4EE5\u53D9\u8FF0\u6027\u6BB5\u843D\uFF08\u6BCF\u6BB5 2-3 \u53E5\u8BDD\uFF09\u5448\u73B0\u5173\u952E\u53D1\u73B0\uFF0C\u6BCF\u4E2A\u6BB5\u843D\u5E94\u8BE5\u662F\u4E00\u4E2A\u5C0F\u6545\u4E8B\uFF0C\u81EA\u7136\u5730\u878D\u5165\u5177\u4F53\u6570\u5B57\u3002
434
+
435
+ \u4F8B\u5982\uFF1A"\u6700\u5F15\u4EBA\u6CE8\u76EE\u7684\u53D1\u73B0\u662F\u5730\u533A\u5DEE\u5F02\u3002\u867D\u7136\u6574\u4F53\u6536\u5165\u589E\u957F\u4E86 18%\uFF0C\u4F46\u7F8E\u56FD\u5E02\u573A\u8D21\u732E\u4E86\u603B\u6536\u5165\u7684 70%\uFF0C\u5176\u4E2D\u52A0\u5229\u798F\u5C3C\u4E9A\u5DDE\u8868\u73B0\u5C24\u4E3A\u5F3A\u52B2\uFF0C\u589E\u957F 25%\u3002\u8FD9\u79CD\u96C6\u4E2D\u5EA6\u65E2\u610F\u5473\u7740\u673A\u4F1A\uFF0C\u4E5F\u610F\u5473\u7740\u98CE\u9669\u2014\u2014\u6210\u529F\u9AD8\u5EA6\u4F9D\u8D56\u5C11\u6570\u5173\u952E\u5E02\u573A\u3002"
436
+
437
+ ### 3. \u4E1A\u52A1\u6D1E\u5BDF
438
+
439
+ \u7528\u53D9\u8FF0\u6027\u6BB5\u843D\u89E3\u91CA\u8FD9\u4E9B\u53D1\u73B0\u610F\u5473\u7740\u4EC0\u4E48\uFF0C\u5C06\u6570\u636E\u70B9\u4E0E\u4E1A\u52A1\u7ED3\u679C\u81EA\u7136\u8FDE\u63A5\u3002
440
+
441
+ - \u8BA8\u8BBA\u5173\u6CE8\u70B9\u6216\u673A\u4F1A
442
+ - \u89E3\u91CA\u53EF\u80FD\u5BFC\u81F4\u8FD9\u4E9B\u6A21\u5F0F\u7684\u56E0\u7D20
443
+ - \u4F7F\u7528"\u8FD9\u8868\u660E..."\u3001"\u6709\u8DA3\u7684\u662F..."\u3001"\u7279\u522B\u503C\u5F97\u6CE8\u610F\u7684\u662F..."\u7B49\u8868\u8FBE
444
+
445
+ ### 4. \u95EE\u9898\u56DE\u7B54\u8BC4\u4F30
446
+
447
+ **\u5173\u952E\u4EFB\u52A1**\uFF1A\u8BC4\u4F30\u5F53\u524D\u6570\u636E\u662F\u5426\u8DB3\u4EE5\u56DE\u7B54\u7528\u6237\u7684\u4E1A\u52A1\u95EE\u9898\u3002
448
+
449
+ - **\u5982\u679C\u6570\u636E\u5145\u8DB3**\uFF1A\u660E\u786E\u8BF4\u660E\u5F53\u524D\u6570\u636E\u5982\u4F55\u56DE\u7B54\u4E86\u95EE\u9898\uFF0C\u54EA\u4E9B\u65B9\u9762\u5DF2\u7ECF\u5F97\u5230\u89E3\u7B54
450
+ - **\u5982\u679C\u6570\u636E\u4E0D\u8DB3**\uFF1A\u660E\u786E\u6307\u51FA\uFF1A
451
+ - \u54EA\u4E9B\u95EE\u9898\u65E0\u6CD5\u4ECE\u5F53\u524D\u6570\u636E\u4E2D\u56DE\u7B54
452
+ - \u7F3A\u5C11\u54EA\u4E9B\u5173\u952E\u4FE1\u606F\u6216\u7EF4\u5EA6
453
+ - \u5EFA\u8BAE\u9700\u8981\u67E5\u8BE2\u54EA\u4E9B\u989D\u5916\u7684\u6570\u636E\uFF08\u5177\u4F53\u8BF4\u660E\u9700\u8981\u67E5\u8BE2\u7684\u8868\u3001\u5B57\u6BB5\u3001\u65F6\u95F4\u8303\u56F4\u3001\u7B5B\u9009\u6761\u4EF6\u7B49\uFF09
454
+ - \u4E3A\u4EC0\u4E48\u8FD9\u4E9B\u989D\u5916\u6570\u636E\u5BF9\u5B8C\u6574\u56DE\u7B54\u95EE\u9898\u81F3\u5173\u91CD\u8981
455
+
456
+ ### 5. \u540E\u7EED\u6570\u636E\u6316\u6398\u5EFA\u8BAE
457
+
458
+ \u5982\u679C\u6570\u636E\u4E0D\u8DB3\uFF0C\u63D0\u4F9B\u5177\u4F53\u7684\u6570\u636E\u6316\u6398\u5EFA\u8BAE\uFF1A
459
+
460
+ - **\u9700\u8981\u67E5\u8BE2\u7684\u8868\u548C\u5B57\u6BB5**\uFF1A\u660E\u786E\u6307\u51FA\u9700\u8981\u4ECE\u54EA\u4E9B\u8868\u67E5\u8BE2\u54EA\u4E9B\u5B57\u6BB5
461
+ - **\u65F6\u95F4\u8303\u56F4**\uFF1A\u5982\u679C\u9700\u8981\u5386\u53F2\u5BF9\u6BD4\uFF0C\u5EFA\u8BAE\u67E5\u8BE2\u7684\u65F6\u95F4\u8303\u56F4
462
+ - **\u7EF4\u5EA6\u62C6\u5206**\uFF1A\u5982\u679C\u9700\u8981\u66F4\u7EC6\u7C92\u5EA6\u7684\u5206\u6790\uFF0C\u5EFA\u8BAE\u6309\u54EA\u4E9B\u7EF4\u5EA6\u62C6\u5206\uFF08\u5982\u5730\u533A\u3001\u6E20\u9053\u3001\u4EA7\u54C1\u7C7B\u522B\u7B49\uFF09
463
+ - **\u5173\u8054\u67E5\u8BE2**\uFF1A\u5982\u679C\u9700\u8981\u5173\u8054\u5176\u4ED6\u8868\uFF0C\u8BF4\u660E\u9700\u8981 JOIN \u54EA\u4E9B\u8868\u4EE5\u53CA\u5173\u8054\u6761\u4EF6
464
+ - **\u7B5B\u9009\u6761\u4EF6**\uFF1A\u5982\u679C\u9700\u8981\u7279\u5B9A\u5B50\u96C6\u7684\u6570\u636E\uFF0C\u8BF4\u660E\u7B5B\u9009\u6761\u4EF6
465
+
466
+ ## \u4E1A\u52A1\u4E0A\u4E0B\u6587\u6574\u5408
467
+
468
+ \u5206\u6790\u7ED3\u679C\u65F6\u8003\u8651\uFF1A
469
+
470
+ - **\u57FA\u51C6\u5BF9\u6BD4**\uFF1A\u4E0E\u5386\u53F2\u65F6\u671F\u3001\u76EE\u6807\u6216\u884C\u4E1A\u6807\u51C6\u5BF9\u6BD4
471
+ - **\u7EC6\u5206\u5206\u6790**\uFF1A\u8BC6\u522B\u54EA\u4E9B\u7EC6\u5206\uFF08\u5730\u533A\u3001\u6E20\u9053\u3001\u4EA7\u54C1\uFF09\u9A71\u52A8\u4E86\u7ED3\u679C
472
+ - **\u5F02\u5E38\u68C0\u6D4B**\uFF1A\u6807\u8BB0\u9700\u8981\u8C03\u67E5\u7684\u5F02\u5E38\u6A21\u5F0F
473
+ - **\u8D8B\u52BF\u5206\u6790**\uFF1A\u8BC6\u522B\u4E0A\u5347\u3001\u4E0B\u964D\u6216\u7A33\u5B9A\u8D8B\u52BF
474
+ - **\u76F8\u5173\u6027**\uFF1A\u6CE8\u610F\u4E0D\u540C\u6307\u6807\u4E4B\u95F4\u7684\u5173\u7CFB
475
+
476
+ ## \u8F93\u51FA\u7ED3\u6784
477
+
478
+ \`\`\`markdown
479
+ ### \u6570\u636E\u6458\u8981
480
+
481
+ [\u7528 2-3 \u53E5\u8BDD\u603B\u7ED3\u6570\u636E\u63ED\u793A\u7684\u6838\u5FC3\u4FE1\u606F\uFF0C\u81EA\u7136\u5730\u878D\u5165\u5177\u4F53\u6570\u5B57]
482
+
483
+ ### \u5173\u952E\u53D1\u73B0
484
+
485
+ [\u7528\u53D9\u8FF0\u6027\u6BB5\u843D\uFF08\u6BCF\u6BB5 2-3 \u53E5\u8BDD\uFF09\u5448\u73B0\u5173\u952E\u53D1\u73B0\uFF0C\u81EA\u7136\u5730\u878D\u5165\u5177\u4F53\u6570\u5B57]
486
+
487
+ ### \u4E1A\u52A1\u6D1E\u5BDF
488
+
489
+ [\u7528\u53D9\u8FF0\u6027\u6BB5\u843D\u89E3\u91CA\u8FD9\u4E9B\u53D1\u73B0\u610F\u5473\u7740\u4EC0\u4E48\uFF0C\u5C06\u6570\u636E\u70B9\u4E0E\u4E1A\u52A1\u7ED3\u679C\u81EA\u7136\u8FDE\u63A5]
490
+
491
+ ### \u95EE\u9898\u56DE\u7B54\u8BC4\u4F30
492
+
493
+ **\u5F53\u524D\u6570\u636E\u662F\u5426\u8DB3\u4EE5\u56DE\u7B54\u95EE\u9898\uFF1A** [\u662F/\u90E8\u5206/\u5426]
494
+
495
+ **\u5DF2\u56DE\u7B54\u7684\u65B9\u9762\uFF1A**
496
+ - [\u8BF4\u660E\u5F53\u524D\u6570\u636E\u5982\u4F55\u56DE\u7B54\u4E86\u95EE\u9898\u7684\u54EA\u4E9B\u65B9\u9762]
497
+
498
+ **\u672A\u56DE\u7B54\u7684\u65B9\u9762\uFF08\u5982\u679C\u6570\u636E\u4E0D\u8DB3\uFF09\uFF1A**
499
+ - [\u660E\u786E\u6307\u51FA\u54EA\u4E9B\u95EE\u9898\u65E0\u6CD5\u4ECE\u5F53\u524D\u6570\u636E\u4E2D\u56DE\u7B54]
500
+
501
+ ### \u6570\u636E\u6316\u6398\u5EFA\u8BAE\uFF08\u5982\u679C\u6570\u636E\u4E0D\u8DB3\uFF09
502
+
503
+ **\u9700\u8981\u67E5\u8BE2\u7684\u989D\u5916\u6570\u636E\uFF1A**
504
+ 1. **\u67E5\u8BE2\u76EE\u6807**\uFF1A[\u8BF4\u660E\u9700\u8981\u67E5\u8BE2\u4EC0\u4E48\u4FE1\u606F]
505
+ 2. **\u5EFA\u8BAE\u7684 SQL \u67E5\u8BE2\u65B9\u5411**\uFF1A
506
+ - \u8868\uFF1A[\u9700\u8981\u67E5\u8BE2\u7684\u8868\u540D]
507
+ - \u5B57\u6BB5\uFF1A[\u9700\u8981\u7684\u5B57\u6BB5\u5217\u8868]
508
+ - \u65F6\u95F4\u8303\u56F4\uFF1A[\u5982\u679C\u9700\u8981\uFF0C\u8BF4\u660E\u65F6\u95F4\u8303\u56F4]
509
+ - \u7EF4\u5EA6\u62C6\u5206\uFF1A[\u5982\u679C\u9700\u8981\uFF0C\u8BF4\u660E\u6309\u54EA\u4E9B\u7EF4\u5EA6\u62C6\u5206]
510
+ - \u5173\u8054\u8868\uFF1A[\u5982\u679C\u9700\u8981 JOIN\uFF0C\u8BF4\u660E\u5173\u8054\u7684\u8868\u548C\u6761\u4EF6]
511
+ - \u7B5B\u9009\u6761\u4EF6\uFF1A[\u5982\u679C\u9700\u8981\uFF0C\u8BF4\u660E\u7B5B\u9009\u6761\u4EF6]
512
+ 3. **\u4E3A\u4EC0\u4E48\u9700\u8981\u8FD9\u4E9B\u6570\u636E**\uFF1A[\u89E3\u91CA\u4E3A\u4EC0\u4E48\u8FD9\u4E9B\u6570\u636E\u5BF9\u5B8C\u6574\u56DE\u7B54\u95EE\u9898\u81F3\u5173\u91CD\u8981]
513
+ \`\`\`
514
+
515
+ ## \u6C9F\u901A\u98CE\u683C
516
+
517
+ - **\u53D9\u8FF0\u6027**\uFF1A\u4EE5\u6545\u4E8B\u5F62\u5F0F\u5448\u73B0\uFF0C\u800C\u975E\u6280\u672F\u62A5\u544A
518
+ - **\u81EA\u7136\u6D41\u7545**\uFF1A\u4F7F\u7528\u591A\u6837\u5316\u7684\u53E5\u5B50\u7ED3\u6784\u548C\u81EA\u7136\u7684\u8FC7\u6E21
519
+ - **\u4E1A\u52A1\u53CB\u597D**\uFF1A\u4F7F\u7528\u4E1A\u52A1\u672F\u8BED\uFF0C\u800C\u975E\u6280\u672F\u884C\u8BDD
520
+ - **\u6570\u636E\u9A71\u52A8**\uFF1A\u81EA\u7136\u5730\u878D\u5165\u5177\u4F53\u6570\u5B57\uFF0C\u800C\u975E\u5355\u72EC\u5217\u51FA\u4E8B\u5B9E
521
+ - **\u5BF9\u8BDD\u5F0F**\uFF1A\u50CF\u5411\u540C\u4E8B\u89E3\u91CA\u4E00\u6837\uFF0C\u800C\u975E\u586B\u5199\u8868\u683C
522
+ - **\u53EF\u6267\u884C**\uFF1A\u805A\u7126\u80FD\u591F\u4E3A\u51B3\u7B56\u63D0\u4F9B\u4FE1\u606F\u7684\u6D1E\u5BDF
523
+ - **\u4E0A\u4E0B\u6587\u76F8\u5173**\uFF1A\u5728\u53D9\u8FF0\u4E2D\u81EA\u7136\u5730\u63D0\u4F9B\u4E1A\u52A1\u4E0A\u4E0B\u6587
524
+
525
+ ## \u7279\u522B\u6CE8\u610F\u4E8B\u9879
526
+
527
+ - **\u767E\u5206\u6BD4**\uFF1A\u5728\u76F8\u5173\u65F6\u8BA1\u7B97\u5E76\u7A81\u51FA\u767E\u5206\u6BD4\u53D8\u5316
528
+ - **\u5BF9\u6BD4**\uFF1A\u59CB\u7EC8\u63D0\u4F9B\u4E0A\u4E0B\u6587\uFF08\u4E0E\u4E0A\u4E00\u65F6\u671F\u5BF9\u6BD4\u3001\u4E0E\u76EE\u6807\u5BF9\u6BD4\u3001\u4E0E\u5E73\u5747\u503C\u5BF9\u6BD4\uFF09
529
+ - **\u79BB\u7FA4\u503C**\uFF1A\u6807\u8BB0\u5E76\u89E3\u91CA\u4EFB\u4F55\u5F02\u5E38\u6570\u636E\u70B9
530
+ - **\u6570\u636E\u8D28\u91CF**\uFF1A\u6CE8\u610F\u4EFB\u4F55\u6570\u636E\u9650\u5236\u6216\u6CE8\u610F\u4E8B\u9879
531
+ - **\u7F6E\u4FE1\u5EA6**\uFF1A\u5F53\u53D1\u73B0\u5177\u6709\u7EDF\u8BA1\u663E\u8457\u6027\u6216\u4EC5\u4E3A\u521D\u6B65\u7ED3\u679C\u65F6\uFF0C\u660E\u786E\u8BF4\u660E
532
+
533
+ \u8BB0\u4F4F\uFF1A\u4F60\u7684\u5206\u6790\u5C06\u539F\u59CB\u67E5\u8BE2\u7ED3\u679C\u8F6C\u5316\u4E3A\u6709\u610F\u4E49\u7684\u4E1A\u52A1\u6D1E\u5BDF\u3002\u8BC4\u4F30\u6570\u636E\u662F\u5426\u8DB3\u4EE5\u56DE\u7B54\u95EE\u9898\uFF0C\u5982\u679C\u4E0D\u8DB3\uFF0C\u63D0\u4F9B\u5177\u4F53\u7684\u6570\u636E\u6316\u6398\u5EFA\u8BAE\uFF0C\u5E2E\u52A9\u83B7\u53D6\u5B8C\u6574\u7B54\u6848\u6240\u9700\u7684\u4FE1\u606F\u3002
344
534
  `;
345
535
  var data_agents = [
346
536
  {
347
537
  key: "data_agent",
348
538
  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.",
539
+ description: "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.",
350
540
  type: import_core2.AgentType.DEEP_AGENT,
351
- tools: ["list_tables_sql", "info_sql", "query_sql", "query_checker_sql"],
541
+ tools: ["list_tables_sql", "info_sql"],
352
542
  prompt: dataAgentPrompt,
353
543
  subAgents: ["sql-builder-agent", "data-analysis-agent"],
544
+ skillCategories: ["analysis", "sql"],
354
545
  schema: import_zod2.default.object({}),
355
546
  /**
356
547
  * Runtime configuration injected into tool execution context.
@@ -365,17 +556,17 @@ var data_agents = [
365
556
  {
366
557
  key: "sql-builder-agent",
367
558
  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.",
559
+ type: import_core2.AgentType.DEEP_AGENT,
560
+ description: "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.",
370
561
  prompt: sqlBuilderPrompt,
371
- tools: ["info_sql", "query_checker_sql"]
562
+ tools: ["list_tables_sql", "info_sql", "query_checker_sql", "query_sql"]
372
563
  // Sub-agents inherit runConfig from parent agent via the execution context
373
564
  },
374
565
  {
375
566
  key: "data-analysis-agent",
376
567
  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.",
568
+ type: import_core2.AgentType.DEEP_AGENT,
569
+ description: "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.",
379
570
  prompt: dataAnalysisPrompt,
380
571
  tools: []
381
572
  }
@@ -390,8 +581,240 @@ initializeDataAgentDatabase("fulidb", {
390
581
  database: "postgres"
391
582
  });
392
583
 
584
+ // src/agents/inventory_doctor/index.ts
585
+ var import_core4 = require("@axiom-lattice/core");
586
+ var import_zod4 = __toESM(require("zod"));
587
+
588
+ // src/agents/inventory_doctor/tools.ts
589
+ var import_zod3 = __toESM(require("zod"));
590
+ var import_core3 = require("@axiom-lattice/core");
591
+ (0, import_core3.registerToolLattice)(
592
+ "get_wms_movement_tasks",
593
+ {
594
+ name: "get_wms_movement_tasks",
595
+ description: "Retrieve in-flight movement tasks (putaway/move/wave) for a specific SKU and location. Use this to check for tasks in middle states that might cause inventory discrepancies.",
596
+ needUserApprove: false,
597
+ schema: import_zod3.default.object({
598
+ skuId: import_zod3.default.string().describe("SKU identifier"),
599
+ locationId: import_zod3.default.string().describe("Location identifier")
600
+ })
601
+ },
602
+ async (input) => {
603
+ const taskTypes = ["putaway", "move", "wave", "replenishment"];
604
+ const statuses = ["in_progress", "pending", "queued", "processing"];
605
+ const hasPendingTasks = Math.random() > 0.3;
606
+ const taskCount = hasPendingTasks ? Math.floor(Math.random() * 3) + 1 : 0;
607
+ const tasks = Array.from({ length: taskCount }, (_, i) => ({
608
+ id: `move-${Math.floor(Math.random() * 9e3) + 1e3}`,
609
+ type: taskTypes[Math.floor(Math.random() * taskTypes.length)],
610
+ status: statuses[Math.floor(Math.random() * statuses.length)],
611
+ etaMin: Math.floor(Math.random() * 60) + 5
612
+ // 5-65 minutes
613
+ }));
614
+ return {
615
+ pending: hasPendingTasks,
616
+ tasks
617
+ };
618
+ }
619
+ );
620
+ (0, import_core3.registerToolLattice)(
621
+ "get_location_logs",
622
+ {
623
+ name: "get_location_logs",
624
+ description: "Retrieve activity logs for a location within a specified lookback period. Use this to identify unconfirmed moves, cancellations, or other activities that might explain inventory discrepancies.",
625
+ needUserApprove: false,
626
+ schema: import_zod3.default.object({
627
+ locationId: import_zod3.default.string().describe("Location identifier"),
628
+ lookbackHours: import_zod3.default.number().describe("Number of hours to look back")
629
+ })
630
+ },
631
+ async (input) => {
632
+ const actions = ["move", "putaway", "pick", "adjustment", "cycle_count"];
633
+ const statuses = [
634
+ "pending_confirm",
635
+ "completed",
636
+ "cancelled",
637
+ "in_progress",
638
+ "failed"
639
+ ];
640
+ const operators = [
641
+ "op_x",
642
+ "op_y",
643
+ "op_z",
644
+ "worker_01",
645
+ "worker_05",
646
+ "worker_12"
647
+ ];
648
+ const locations = ["A-01", "A-02", "B-01", "B-02", "C-03", "D-05"];
649
+ const logCount = Math.floor(Math.random() * 5) + 1;
650
+ const now = /* @__PURE__ */ new Date();
651
+ const logs = Array.from({ length: logCount }, (_, i) => {
652
+ const hoursAgo = Math.floor(Math.random() * input.lookbackHours);
653
+ const timestamp = new Date(now.getTime() - hoursAgo * 60 * 60 * 1e3);
654
+ const fromLoc = locations[Math.floor(Math.random() * locations.length)];
655
+ const toLoc = locations[Math.floor(Math.random() * locations.length)];
656
+ return {
657
+ ts: timestamp.toISOString(),
658
+ action: actions[Math.floor(Math.random() * actions.length)],
659
+ from: fromLoc,
660
+ to: toLoc !== fromLoc ? toLoc : locations[Math.floor(Math.random() * locations.length)],
661
+ status: statuses[Math.floor(Math.random() * statuses.length)],
662
+ operator: operators[Math.floor(Math.random() * operators.length)]
663
+ };
664
+ });
665
+ logs.sort((a, b) => new Date(b.ts).getTime() - new Date(a.ts).getTime());
666
+ return logs;
667
+ }
668
+ );
669
+ (0, import_core3.registerToolLattice)(
670
+ "retry_sync",
671
+ {
672
+ name: "retry_sync",
673
+ description: "Retry synchronization for a task that appears to be stuck in a middle state. This will attempt to refresh the task status and resolve data delays.",
674
+ needUserApprove: false,
675
+ schema: import_zod3.default.object({
676
+ taskId: import_zod3.default.string().describe("Task identifier to retry")
677
+ })
678
+ },
679
+ async (input) => {
680
+ const fixed = Math.random() > 0.2;
681
+ const messages = [
682
+ "status refreshed to completed",
683
+ "task synchronized successfully",
684
+ "sync completed, inventory updated",
685
+ "task status updated to completed",
686
+ "synchronization failed, task still in progress",
687
+ "unable to sync, task may require manual intervention"
688
+ ];
689
+ return {
690
+ fixed,
691
+ message: fixed ? messages[Math.floor(Math.random() * 4)] : messages[Math.floor(Math.random() * 2) + 4]
692
+ };
693
+ }
694
+ );
695
+ (0, import_core3.registerToolLattice)(
696
+ "dispatch_cycle_count",
697
+ {
698
+ name: "dispatch_cycle_count",
699
+ description: "Dispatch a cycle count task to physically verify inventory at specified locations. Use this when physical verification is needed to resolve inventory discrepancies.",
700
+ needUserApprove: false,
701
+ schema: import_zod3.default.object({
702
+ skuId: import_zod3.default.string().describe("SKU identifier to verify"),
703
+ locations: import_zod3.default.array(import_zod3.default.string()).describe("List of location identifiers to check"),
704
+ priority: import_zod3.default.string().describe("Priority level (e.g., 'high', 'medium', 'low')")
705
+ })
706
+ },
707
+ async (input) => {
708
+ const workers = [
709
+ "worker_01",
710
+ "worker_05",
711
+ "worker_07",
712
+ "worker_12",
713
+ "worker_15",
714
+ "worker_20"
715
+ ];
716
+ const taskId = `cc-${Math.floor(Math.random() * 9e3) + 1e3}`;
717
+ const assignee = workers[Math.floor(Math.random() * workers.length)];
718
+ const etaMinutes = Math.floor(Math.random() * 30) + 5;
719
+ const eta = `${etaMinutes}m`;
720
+ return {
721
+ taskId,
722
+ assignee,
723
+ eta
724
+ };
725
+ }
726
+ );
727
+ (0, import_core3.registerToolLattice)(
728
+ "notify_picker",
729
+ {
730
+ name: "notify_picker",
731
+ description: "Send a notification message to the picker about inventory status, retry instructions, or other relevant information.",
732
+ needUserApprove: false,
733
+ schema: import_zod3.default.object({
734
+ message: import_zod3.default.string().describe("Message to send to the picker")
735
+ })
736
+ },
737
+ async (input) => {
738
+ const delivered = Math.random() > 0.1;
739
+ return {
740
+ delivered
741
+ };
742
+ }
743
+ );
744
+ (0, import_core3.registerToolLattice)(
745
+ "write_case_report",
746
+ {
747
+ name: "write_case_report",
748
+ description: "Save the diagnostic case report as a markdown file. Use this to record the diagnosis, actions taken, and recommendations for audit purposes.",
749
+ needUserApprove: false,
750
+ schema: import_zod3.default.object({
751
+ markdown: import_zod3.default.string().describe("Markdown content of the case report")
752
+ })
753
+ },
754
+ async (input) => {
755
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, -5);
756
+ const reportId = Math.floor(Math.random() * 1e4);
757
+ const paths = [
758
+ `/reports/inventory-case-latest.md`,
759
+ `/reports/inventory-case-${reportId}.md`,
760
+ `/reports/case-${timestamp}.md`,
761
+ `/reports/inventory-diagnosis-${reportId}.md`
762
+ ];
763
+ return {
764
+ saved: true,
765
+ path: paths[Math.floor(Math.random() * paths.length)]
766
+ };
767
+ }
768
+ );
769
+
770
+ // src/agents/inventory_doctor/index.ts
771
+ var inventoryDoctorPrompt = `You are the Inventory Doctor Agent handling WMS pick-shortage incidents.
772
+
773
+ ## Mission
774
+ - Scenario: System shows stock=5 for SKU A, picker finds 0 at location.
775
+ - Follow Think-Act-Observe loops to diagnose and either auto-fix or dispatch physical verification.
776
+
777
+
778
+ ## Workflow
779
+ 1) Trigger: on Pick Shortage, freeze concurrent changes for the SKU/location.
780
+ 2) Data Retrieval & Triage:
781
+ - Check in-flight tasks (putaway/move/wave) for middle states or delays.
782
+ - Pull last 24h location logs; highlight unconfirmed moves or cancellations.
783
+ - Form hypotheses: data delay, stuck middleware, physical misplacement.
784
+ 3) Reasoning & Execution:
785
+ - Branch A Auto-fix: if middle-state, call retry_sync then notify picker to retry.
786
+ - Branch B Physical verify: push a cycle-count task to nearby operator; include candidate locations (B/C) for misplaced stock.
787
+ - Record every action in the report body for auditability.
788
+ 4) Reporting: return a concise Markdown case report with diagnosis, actions taken, residual risk, and training/monitoring suggestions.
789
+
790
+ ## Output format
791
+ Use Markdown sections: \u8BCA\u65AD\u6982\u89C8 / \u5173\u952E\u53D1\u73B0 / \u5904\u7F6E\u52A8\u4F5C / \u540E\u7EED\u5EFA\u8BAE. Keep facts first, then recommendations.`;
792
+ var inventoryDoctorAgent = {
793
+ key: "inventory_doctor_agent",
794
+ name: "Inventory Doctor Agent",
795
+ description: "Diagnoses pick-shortage inventory anomalies in WMS, auto-fixes data middle states, or dispatches cycle counts for physical verification, and returns an audit-friendly report.",
796
+ type: import_core4.AgentType.DEEP_AGENT,
797
+ prompt: inventoryDoctorPrompt,
798
+ tools: [
799
+ "get_wms_movement_tasks",
800
+ "get_location_logs",
801
+ "retry_sync",
802
+ "dispatch_cycle_count",
803
+ "notify_picker",
804
+ "write_case_report"
805
+ ],
806
+ schema: import_zod4.default.object({
807
+ skuId: import_zod4.default.string().optional(),
808
+ locationId: import_zod4.default.string().optional(),
809
+ incidentId: import_zod4.default.string().optional()
810
+ })
811
+ };
812
+ (0, import_core4.registerAgentLattices)([inventoryDoctorAgent]);
813
+
393
814
  // src/index.ts
394
815
  var import_path = __toESM(require("path"));
816
+ var import_protocols = require("@axiom-lattice/protocols");
817
+ var fs = require("fs");
395
818
  var PACKAGE_VERSION = require_package().version;
396
819
  var BUILD_TIME = (/* @__PURE__ */ new Date()).toISOString();
397
820
  var IS_DEV = process.env.NODE_ENV !== "production";
@@ -427,7 +850,7 @@ function parsePort() {
427
850
  }
428
851
  return 4001;
429
852
  }
430
- (0, import_core3.registerModelLattice)(
853
+ (0, import_core5.registerModelLattice)(
431
854
  "default",
432
855
  // {
433
856
  // model: "deepseek-chat",
@@ -467,10 +890,72 @@ function parsePort() {
467
890
  // }
468
891
  );
469
892
  import_gateway.LatticeGateway.registerLatticeRoutes(import_gateway.LatticeGateway.app);
893
+ var possiblePaths = [
894
+ // Production: from dist/ go up to src/
895
+ import_path.default.resolve(__dirname, "../src/agents/data_agent/skills"),
896
+ // Development: relative to __dirname (src/)
897
+ import_path.default.resolve(__dirname, "./agents/data_agent/skills"),
898
+ // Fallback: from project root
899
+ import_path.default.resolve(process.cwd(), "examples/deep_research/src/agents/data_agent/skills")
900
+ ];
901
+ var skillsRootDir = possiblePaths[0];
902
+ for (const possiblePath of possiblePaths) {
903
+ if (fs.existsSync(possiblePath)) {
904
+ skillsRootDir = possiblePath;
905
+ break;
906
+ }
907
+ }
908
+ if (!fs.existsSync(skillsRootDir)) {
909
+ console.warn(
910
+ `Warning: Skills directory not found at any of the expected paths. Using: ${skillsRootDir}`
911
+ );
912
+ }
913
+ console.log(`Skill store root directory: ${skillsRootDir}`);
914
+ var skillStore = new import_core5.FileSystemSkillStore({
915
+ rootDir: skillsRootDir
916
+ });
917
+ import_core5.storeLatticeManager.removeLattice("default", "skill");
918
+ (0, import_core5.registerStoreLattice)("default", "skill", skillStore);
919
+ import_core5.skillLatticeManager.configureStore("default");
920
+ (async () => {
921
+ try {
922
+ const skills = await skillStore.getAllSkills();
923
+ console.log(`Loaded ${skills.length} skills from file system:`);
924
+ if (skills.length === 0) {
925
+ console.warn(
926
+ `Warning: No skills found. Please check if the directory exists: ${skillsRootDir}`
927
+ );
928
+ } else {
929
+ skills.forEach((skill) => {
930
+ console.log(` - ${skill.name}: ${skill.description.substring(0, 50)}...`);
931
+ });
932
+ }
933
+ } catch (error) {
934
+ console.error("Failed to load skills on startup:", error);
935
+ if (error instanceof Error) {
936
+ console.error("Error details:", error.message);
937
+ console.error("Stack:", error.stack);
938
+ }
939
+ }
940
+ })();
470
941
  var port = parsePort();
471
942
  console.log(`Starting server on port ${port}`);
943
+ var DEFAULT_LOGGER_CONFIG = {
944
+ name: "default",
945
+ description: "Default logger for lattice-gateway service",
946
+ type: import_protocols.LoggerType.PINO,
947
+ serviceName: "lattice/deep_research",
948
+ loggerName: "lattice/deep_research"
949
+ // file: {
950
+ // file: "./logs/lattice" + "/deep_research",
951
+ // frequency: "daily",
952
+ // mkdir: true,
953
+ // maxFiles: 30,
954
+ // },
955
+ };
472
956
  import_gateway.LatticeGateway.startAsHttpEndpoint({
473
957
  port,
474
- queueServiceConfig: { type: "memory", defaultStartPollingQueue: true }
958
+ queueServiceConfig: { type: "memory", defaultStartPollingQueue: true },
959
+ loggerConfig: DEFAULT_LOGGER_CONFIG
475
960
  });
476
961
  //# sourceMappingURL=index.js.map