PHPackages                             gtstudio/module-ai-data-query - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. gtstudio/module-ai-data-query

ActiveMagento2-module[Utility &amp; Helpers](/categories/utility)

gtstudio/module-ai-data-query
=============================

Natural-language data query interface for Magento 2. Lets admin users ask questions in plain English; the AI extracts intent and queries Magento entities locally — no raw store data sent to the LLM.

1.0.3(4mo ago)0921BUSL-1.1PHPPHP &gt;=8.1

Since Mar 9Pushed 4mo agoCompare

[ Source](https://github.com/gabrielgts/module-ai-data-query)[ Packagist](https://packagist.org/packages/gtstudio/module-ai-data-query)[ RSS](/packages/gtstudio-module-ai-data-query/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (1)Dependencies (3)Versions (4)Used By (1)

Gtstudio\_AiDataQuery
=====================

[](#gtstudio_aidataquery)

Natural-language data query interface for Magento 2. Ask questions in plain English — the AI figures out what to query, the query runs locally, and results are returned directly to the browser. **No store data is ever sent to the LLM.**

Preview
-------

[](#preview)

[![AiDataQuery — asking plain-English questions and getting store analytics results](docs/images/aidataquery-preview.gif)](docs/images/aidataquery-preview.gif)

AI Studio Ecosystem
-------------------

[](#ai-studio-ecosystem)

Part of the **AI Studio** suite for Magento 2. See all modules:

ModuleRepositoryDescription**Gtstudio\_AiConnector**[module-aiconnector](https://github.com/gabrielgts/module-aiconnector)Core AI provider abstraction**Gtstudio\_AiAgents**[module-ai-agents](https://github.com/gabrielgts/module-ai-agents)Agent &amp; tool orchestration, cron scheduling, execution log**Gtstudio\_AiWidgets**[module-ai-widgets](https://github.com/gabrielgts/module-ai-widgets)Floating admin chat widget + PageBuilder AI generator**Gtstudio\_AiDataQuery***(this module)*Natural-language store analytics (privacy-first)**Gtstudio\_AiKnowledgeBase**[module-ai-knowledge-base](https://github.com/gabrielgts/module-ai-knowledge-base)Document upload &amp; RAG retrieval for agents**Gtstudio\_AiDashboard**[module-ai-dashboard](https://github.com/gabrielgts/module-ai-dashboard)AI-powered KPI dashboard with ML insightsWhat It Does
------------

[](#what-it-does)

- Admin chat page where users type questions like *"Show me the top 10 orders from last month"* or *"Which products have less than 5 units in stock?"*
- Two-phase privacy-first architecture:
    - **Phase 1** — LLM receives only the user's question and returns a structured intent (which tool to call, which parameters)
    - **Phase 2** — the server executes the query locally using the resolved intent and returns results directly to the browser
- Built-in query tools: order analytics, customer lifetime value, product performance, and a general entity query
- Token cost display in the chat interface

Privacy Architecture
--------------------

[](#privacy-architecture)

The LLM sees **nothing** about your store data. It only:

- Receives the user's natural-language question
- Returns a JSON object describing which analytical tool to call and with what parameters

All actual database queries run on your server. Results are displayed to the user without routing back through the AI provider.

Requirements
------------

[](#requirements)

- Magento 2.4.4+
- PHP 8.1+
- `Gtstudio_AiConnector` enabled and configured
- `Gtstudio_AiAgents` enabled

Installation
------------

[](#installation)

```
composer require gtstudio/module-ai-data-query
php bin/magento module:enable Gtstudio_AiDataQuery
php bin/magento setup:upgrade
```

A database agent record with code `data_query` is created automatically via a data patch.

Usage
-----

[](#usage)

Navigate to *AI Studio → Data Query*.

**Example questions:**

- *"Show total sales for the last 30 days"*
- *"What are my top 5 customers by revenue?"*
- *"List orders with status Pending from this week"*
- *"Show products with inventory below 10 units"*
- *"What is the average order value for this month?"*

Built-in Query Tools
--------------------

[](#built-in-query-tools)

Tool CodeDescription`order_analytics`Sales totals, order status distribution, average order value, top customers`customer_lifetime_value`LTV ranking, RFM analysis, acquisition trends`product_performance`Top sellers, low performers, revenue by category, inventory alerts`query_entity`General-purpose query against any Magento entityExtensibility
-------------

[](#extensibility)

### Registering a Custom Query Tool

[](#registering-a-custom-query-tool)

1. Implement `Gtstudio\AiAgents\Api\ToolExecutorInterface`:

```
namespace Vendor\Module\Model\Tool;

use Gtstudio\AiAgents\Api\ToolExecutorInterface;

class StoreRevenueExecutor implements ToolExecutorInterface
{
    public function execute(array $parameters): string|array
    {
        $storeId = (int) ($parameters['store_id'] ?? 0);
        // ... query DB, return formatted results
        return "Revenue for store #{$storeId}: $12,500.00";
    }
}
```

2. Create a tool record in *AI Studio → Tools* with matching code (e.g. `store_revenue`).
3. Register the executor via `di.xml`:

```

                Vendor\Module\Model\Tool\StoreRevenueExecutor

```

4. Update the `data_query` agent's Background or Steps in the admin to describe your new tool so the LLM knows when to choose it.

### Registering a Queryable Entity

[](#registering-a-queryable-entity)

The `query_entity` tool dispatches to registered entity handlers. Add a new entity:

```

                Vendor\Module\Model\Tool\MyEntityHandler

```

Implement the handler to return a collection, field list, and filter map.

### Customising the Planner Prompt

[](#customising-the-planner-prompt)

The system prompt that instructs the LLM is built in `DataQueryChatService::buildPlannerPrompt()`. Override the service:

```

```

ACL Resources
-------------

[](#acl-resources)

ResourceControls`Gtstudio_AiDataQuery::management`Access to the Data Query page and its API endpoints

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance74

Regular maintenance activity

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

3

Last Release

149d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ab1f0030c21bebf4e87187df361e770ffaa2c0d3cdcd0cd45c77a79db5836156?d=identicon)[gtstudio](/maintainers/gtstudio)

---

Top Contributors

[![gabrielgts](https://avatars.githubusercontent.com/u/22245724?v=4)](https://github.com/gabrielgts "gabrielgts (1 commits)")

### Embed Badge

![Health badge](/badges/gtstudio-module-ai-data-query/health.svg)

```
[![Health](https://phpackages.com/badges/gtstudio-module-ai-data-query/health.svg)](https://phpackages.com/packages/gtstudio-module-ai-data-query)
```

###  Alternatives

[nosto/module-nostotagging

Increase your conversion rate and average order value by delivering your customers personalized product recommendations throughout their shopping journey.

28714.5k4](/packages/nosto-module-nostotagging)[fishpig/magento2-wordpress-integration

Securely integrate WordPress and Magento 2.

83374.7k7](/packages/fishpig-magento2-wordpress-integration)[run-as-root/magento2-prometheus-exporter

Magento2 Prometheus Exporter

69362.0k](/packages/run-as-root-magento2-prometheus-exporter)[myparcelnl/magento

A Magento 2 module that creates MyParcel labels

1861.2k](/packages/myparcelnl-magento)[loki/magento2-components

Core module for defining Alpine.js components with advanced AJAX features

1015.1k27](/packages/loki-magento2-components)[mage-os/module-llm-txt

AI-powered LLMs.txt generation for Magento 2 / Mage-OS stores. Help AI systems understand your store with OpenAI-generated content.

244.4k](/packages/mage-os-module-llm-txt)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
