|
| 1 | +import type { Agent, NLQModelConfig, QueryTemplate } from '@objectstack/spec'; |
| 2 | + |
| 3 | +/** |
| 4 | + * AI Data Analyst Agent |
| 5 | + */ |
| 6 | +export const DataAnalystAgent: Agent = { |
| 7 | + name: 'data_analyst_ai', |
| 8 | + label: 'AI Data Analyst', |
| 9 | + role: 'Business Intelligence Analyst', |
| 10 | + |
| 11 | + instructions: `You are a data analyst helping users understand their business metrics. |
| 12 | +
|
| 13 | +Skills: |
| 14 | +- Interpret natural language questions about data |
| 15 | +- Generate ObjectQL queries |
| 16 | +- Create visualizations |
| 17 | +- Provide actionable insights |
| 18 | +
|
| 19 | +Be precise, data-driven, and clear in explanations.`, |
| 20 | + |
| 21 | + model: { |
| 22 | + provider: 'openai', |
| 23 | + model: 'gpt-4', |
| 24 | + temperature: 0.3, |
| 25 | + maxTokens: 4096, |
| 26 | + }, |
| 27 | + |
| 28 | + tools: [ |
| 29 | + { |
| 30 | + type: 'query', |
| 31 | + name: 'execute_objectql', |
| 32 | + description: 'Execute ObjectQL queries on data', |
| 33 | + }, |
| 34 | + { |
| 35 | + type: 'action', |
| 36 | + name: 'create_dashboard', |
| 37 | + description: 'Generate dashboard from metrics', |
| 38 | + }, |
| 39 | + { |
| 40 | + type: 'action', |
| 41 | + name: 'generate_chart', |
| 42 | + description: 'Create charts and visualizations', |
| 43 | + }, |
| 44 | + { |
| 45 | + type: 'query', |
| 46 | + name: 'get_schema', |
| 47 | + description: 'Get object schema information', |
| 48 | + }, |
| 49 | + ], |
| 50 | + |
| 51 | + access: ['analysts', 'executives', 'managers'], |
| 52 | + active: true, |
| 53 | +}; |
| 54 | + |
| 55 | +/** |
| 56 | + * NLQ Configuration for Business Intelligence |
| 57 | + */ |
| 58 | +export const AnalystNLQConfig: NLQModelConfig = { |
| 59 | + modelId: 'gpt-4', |
| 60 | + systemPrompt: `You are an expert at converting business questions into ObjectQL queries. |
| 61 | + |
| 62 | +Available objects: account, opportunity, task, product, order |
| 63 | +Be precise with field names and support timeframes like "last quarter", "this year".`, |
| 64 | + |
| 65 | + includeSchema: true, |
| 66 | + includeExamples: true, |
| 67 | + enableIntentDetection: true, |
| 68 | + intentThreshold: 0.75, |
| 69 | + enableEntityRecognition: true, |
| 70 | + enableFuzzyMatching: true, |
| 71 | + fuzzyMatchThreshold: 0.85, |
| 72 | + enableTimeframeDetection: true, |
| 73 | + defaultTimeframe: 'current_month', |
| 74 | + enableCaching: true, |
| 75 | + cacheTTL: 3600, |
| 76 | +}; |
| 77 | + |
| 78 | +/** |
| 79 | + * Common Query Templates |
| 80 | + */ |
| 81 | +export const AnalystQueryTemplates: QueryTemplate[] = [ |
| 82 | + { |
| 83 | + id: 'top-n-by-field', |
| 84 | + name: 'top_n_by_field', |
| 85 | + label: 'Top N Records by Field', |
| 86 | + pattern: 'top {n} {object} by {field}', |
| 87 | + variables: [ |
| 88 | + { name: 'n', type: 'value', required: true }, |
| 89 | + { name: 'object', type: 'object', required: true }, |
| 90 | + { name: 'field', type: 'field', required: true }, |
| 91 | + ], |
| 92 | + astTemplate: { |
| 93 | + object: '{object}', |
| 94 | + sort: [{ field: '{field}', order: 'desc' }], |
| 95 | + limit: '{n}', |
| 96 | + }, |
| 97 | + category: 'ranking', |
| 98 | + examples: [ |
| 99 | + 'top 10 accounts by revenue', |
| 100 | + 'top 5 products by sales', |
| 101 | + ], |
| 102 | + }, |
| 103 | + |
| 104 | + { |
| 105 | + id: 'aggregate-by-group', |
| 106 | + name: 'aggregate_by_group', |
| 107 | + label: 'Aggregate by Group', |
| 108 | + pattern: 'total {field} by {group_field}', |
| 109 | + variables: [ |
| 110 | + { name: 'field', type: 'field', required: true }, |
| 111 | + { name: 'group_field', type: 'field', required: true }, |
| 112 | + ], |
| 113 | + astTemplate: { |
| 114 | + fields: [ |
| 115 | + '{group_field}', |
| 116 | + { function: 'sum', field: '{field}', alias: 'total' }, |
| 117 | + ], |
| 118 | + groupBy: ['{group_field}'], |
| 119 | + }, |
| 120 | + category: 'aggregation', |
| 121 | + examples: [ |
| 122 | + 'total revenue by region', |
| 123 | + 'total orders by product', |
| 124 | + ], |
| 125 | + }, |
| 126 | + |
| 127 | + { |
| 128 | + id: 'time-comparison', |
| 129 | + name: 'time_comparison', |
| 130 | + label: 'Time Period Comparison', |
| 131 | + pattern: 'compare {metric} for {period1} vs {period2}', |
| 132 | + variables: [ |
| 133 | + { name: 'metric', type: 'field', required: true }, |
| 134 | + { name: 'period1', type: 'timeframe', required: true }, |
| 135 | + { name: 'period2', type: 'timeframe', required: true }, |
| 136 | + ], |
| 137 | + astTemplate: { |
| 138 | + // Complex comparison logic |
| 139 | + }, |
| 140 | + category: 'comparison', |
| 141 | + examples: [ |
| 142 | + 'compare revenue for this month vs last month', |
| 143 | + 'compare sales for Q1 vs Q2', |
| 144 | + ], |
| 145 | + }, |
| 146 | +]; |
0 commit comments