$npx -y skills add digoal/postgres_skill --skill postgresql-bi-agentBusiness intelligence analysis agent for PostgreSQL that discovers database metadata, generates SQL queries for revenue/customer/product metrics, and produces comprehensive analytical reports
| 1 | # PostgreSQL Business Intelligence Agent |
| 2 | |
| 3 | This skill guides the agent in conducting comprehensive business intelligence analysis on a PostgreSQL database. It automatically discovers database metadata, samples data to understand business context, generates business-relevant SQL queries, executes them, and produces deep analytical reports for business operations insights. |
| 4 | |
| 5 | ## Purpose |
| 6 | |
| 7 | The primary goal of this skill is to transform raw database data into actionable business intelligence. It serves as an automated data analyst that: |
| 8 | |
| 9 | - **Discovers** database structure and metadata automatically |
| 10 | - **Understands** business context through data sampling |
| 11 | - **Generates** relevant SQL queries for business metrics |
| 12 | - **Executes** queries efficiently and safely |
| 13 | - **Analyzes** results to provide strategic insights |
| 14 | - **Reports** findings with actionable recommendations |
| 15 | |
| 16 | ## Business Intelligence Framework |
| 17 | |
| 18 | The agent uses a multi-dimensional framework covering: |
| 19 | |
| 20 | ### 1. Business Scale Metrics |
| 21 | - Transaction volumes and values |
| 22 | - Customer base and distribution |
| 23 | - Product/service inventory and categorization |
| 24 | |
| 25 | ### 2. Growth Trends |
| 26 | - Year-over-year and month-over-month comparisons |
| 27 | - Daily/Monthly active user trends |
| 28 | - Revenue and order trends |
| 29 | |
| 30 | ### 3. User Behavior Analysis |
| 31 | - User engagement and activity levels |
| 32 | - Retention rates and cohort analysis |
| 33 | - Conversion funnel metrics |
| 34 | |
| 35 | ### 4. Financial Insights |
| 36 | - Revenue trends and patterns |
| 37 | - Average order value (AOV) |
| 38 | - Payment success rates and refund metrics |
| 39 | |
| 40 | ### 5. Inventory & Product Analysis |
| 41 | - Inventory turnover rates |
| 42 | - Product performance rankings |
| 43 | - Stock-out and overstock indicators |
| 44 | |
| 45 | ### 6. Operational Efficiency |
| 46 | - Order processing times |
| 47 | - Customer satisfaction indicators |
| 48 | - System performance metrics |
| 49 | |
| 50 | ## Workflow |
| 51 | |
| 52 | When activated, this skill executes a comprehensive analysis pipeline: |
| 53 | |
| 54 | 1. **Metadata Discovery** → Scan database structure, tables, columns, relationships |
| 55 | 2. **Data Sampling** → Analyze data patterns, value distributions, business context |
| 56 | 3. **SQL Generation** → Generate domain-specific business intelligence queries |
| 57 | 4. **Query Execution** → Run all queries with proper error handling |
| 58 | 5. **Deep Analysis** → Correlate results, identify patterns, calculate insights |
| 59 | 6. **Report Generation** → Produce comprehensive business report |
| 60 | |
| 61 | ## Available Skills |
| 62 | |
| 63 | Each skill represents a callable analysis module that returns structured JSON output. |
| 64 | |
| 65 | --- |
| 66 | |
| 67 | ## 1. Metadata Discovery |
| 68 | |
| 69 | ### Skill: `discover_database_metadata` |
| 70 | |
| 71 | - **Description**: Scans and collects comprehensive database metadata including schemas, tables, columns, data types, constraints, indexes, and relationships. |
| 72 | - **Usage**: `python3 business_intelligence_agent.py --skill discover_database_metadata` |
| 73 | - **Expected Output**: |
| 74 | ```json |
| 75 | { |
| 76 | "skill": "discover_database_metadata", |
| 77 | "status": "success", |
| 78 | "data": { |
| 79 | "database_name": "ecommerce_db", |
| 80 | "schemas": ["public", "analytics", "audit"], |
| 81 | "total_tables": 45, |
| 82 | "total_columns": 380, |
| 83 | "tables": [ |
| 84 | { |
| 85 | "schema_name": "public", |
| 86 | "table_name": "orders", |
| 87 | "row_count": 1500000, |
| 88 | "columns": [ |
| 89 | {"name": "order_id", "type": "bigint", "is_pk": true}, |
| 90 | {"name": "user_id", "type": "bigint", "is_fk": true}, |
| 91 | {"name": "order_amount", "type": "decimal(12,2)", "is_nullable": false}, |
| 92 | {"name": "created_at", "type": "timestamp", "is_nullable": false} |
| 93 | ], |
| 94 | "indexes": ["idx_orders_user_id", "idx_orders_created_at"] |
| 95 | } |
| 96 | ], |
| 97 | "relationships": [ |
| 98 | {"from": "orders.user_id", "to": "users.user_id", "type": "FK"} |
| 99 | ] |
| 100 | } |
| 101 | } |
| 102 | ``` |
| 103 | |
| 104 | ### Skill: `identify_business_tables` |
| 105 | |
| 106 | - **Description**: Identifies tables likely related to core business operations based on naming conventions, column patterns, and data characteristics. |
| 107 | - **Usage**: `python3 business_intelligence_agent.py --skill identify_business_tables` |
| 108 | - **Expected Output**: |
| 109 | ```json |
| 110 | { |
| 111 | "skill": "identify_business_tables", |
| 112 | "status": "success", |
| 113 | "data": { |
| 114 | "core_tables": [ |
| 115 | {"name": "orders", "category": "transactions", "confidence": 0.95}, |
| 116 | {"name": "users", "category": "customers", "confidence": 0.92}, |
| 117 | {"name": "products", "category": "inventory", "confidence": 0.88} |
| 118 | ], |
| 119 | "transaction_tables": ["orders", "payments", "refunds"], |
| 120 | "customer_tables": ["users", "customers", "accounts"], |
| 121 | "product_tables": ["products", "inventory", "categories"] |
| 122 | } |
| 123 | } |
| 124 | ``` |
| 125 | |
| 126 | ### Skill: `analyze_table_relationships` |
| 127 | |
| 128 | - **Description**: Maps foreign key relationships and infers |