Building an AI Data Agent Plugin: From a Side Project to 100+ GitHub Stars
This article shares a practical methodology for building an AI data agent that connects large language models to databases. Starting from a small plugin project that gained over 100 stars, it explains a four-layer decoupled architecture, metadata and context engineering techniques, multi-step tool orchestration with verification, six non-negotiable security baselines, and engineering practices for multi-host compatibility and long-term maintenance. Readers will learn how to design a reliable, read-only, auditable data agent rather than relying on longer prompts alone.
1. Origin: How a “Good Enough” Side Project Became a Sustainable Effort
The initial goal was simple: contribute code to a beta program in an AI coding tool ecosystem by building a plugin along the way. The idea was straightforward—connect a large language model to a database so it could inspect table structures, retrieve metadata, generate SQL, and return results. By the usual standard, such a tool only needed to get the main flow working to count as “done.”
After release, it picked up more than a hundred stars in a short time. Compared with trending projects that gain thousands of stars a day, the number is not remarkable, but it sent two clear signals: first, data access is a high-frequency, must-have requirement for LLM adoption; second, there is genuine demand for tools that can connect to a user’s own database—users were willing to install it, report issues, and put it to work.
That changed the nature of the project. It was no longer a one-off delivery; it needed to be built to the standard of sustainable engineering. This article centers on that shift and lays out a neutral, general methodology for building an intelligent data agent.
2. Requirement Abstraction: What a Data Agent Must Solve
Once the specific implementation is stripped away, a data agent has to close the loop on four kinds of problems:
- Natural language to query translation: Turning natural language intent into an executable query statement.
- Metadata discovery: Automatically learning about databases, tables, columns, types, primary and foreign keys, and indexes without prior knowledge.
- Explainable results: Returning not just data, but also the query logic, filter conditions, and metric assumptions.
- Security and control: Completing all of the above under read-only access, least privilege, and auditability.
These four points mean the architecture cannot be a single-layer “prompt directly against the database” structure. It must be a layered, pluggable, observable system.
3. Overall Architecture: A Four-Layer Decoupled Design
The recommended approach is to split the system into four layers that communicate through explicit contracts:
- Interaction layer: Connects to different host forms, such as desktop, web, and terminal interfaces. It only adapts input and output and contains no business logic.
- Orchestration layer: Manages session state, tool call ordering, failure retries, and termination conditions. This is the core of the “agent.”
- Capability layer: Provides atomic tools for reading metadata, executing SQL, sampling results, and explaining metrics.
- Data access layer: Encapsulates connection management, connection pooling, timeouts, read-only transactions, and audit logging.
An illustrative capability-layer interface (pseudocode that expresses only the contract and points to no specific product):
class Tool(Protocol):name: strdescription: strdef run(self, args: dict) -> ToolResult: ...class ListSchemas(Tool): # List visible databases and tables...class DescribeTable(Tool): # Read columns, types, primary/foreign keys, indexes...class QueryReadOnly(Tool): # Read-only execution with enforced timeout and row limit...class ExplainPlan(Tool): # Return the execution plan to help spot full table scans...
The key benefit of this design is that adding a new data source or a new interaction form keeps the change confined to a single layer, without triggering a global rewrite.
4. Helping the Model “Understand” the Database: Metadata and Context Engineering
The primary reason a model generates incorrect SQL is not a lack of reasoning ability but missing context. Practices that work well include:
- Expose metadata in layers: Start with a list of databases and tables, then drill down to specific table structures based on intent, avoiding an upfront dump that crowds the context window.
- Normalize names and comments: If the business meaning of table names, column names, and enum values is missing, fill it in on the metadata side. This is the highest-return governance action.
- Provide a few sample rows: A small amount of desensitized real data noticeably improves handling of enum filters, time formats, and null values.
- Maintain a metric dictionary: Give clear definitions for ambiguous metrics such as “active user” or “transaction amount” to reduce cases where the same name means different things.
5. Tool Orchestration: From One-Shot Generation to Multi-Step Verification
A single generation pass cannot be relied upon. Query construction should be treated as a verifiable, multi-step flow:
- Understand the intent and clarify ambiguity (ask back when necessary rather than guessing).
- Retrieve metadata and lock down candidate tables and join paths.
- Generate candidate queries and run static checks first (whether tables and columns exist, whether types match).
- Assess cost through the execution plan and flag risks of full table scans and Cartesian products.
- Do a small-sample trial run to verify the result shape matches expectations.
- Return results with a metric explanation and keep reusable query templates.
The orchestration layer needs hard termination conditions, such as a maximum number of tool calls and a maximum execution time, to prevent infinite loops from consuming resources.
6. Security Boundaries: Six Non-Negotiable Baselines
A data agent is inherently a high-risk component. The following baselines should be defaults, not options:
- Read-only by default: Grant the connection account only the read permissions it needs; write operations require explicit enablement and a second confirmation.
- Statement allowlist with parsing validation: Determine statement type through syntax parsing rather than regex matching, to prevent bypasses such as comment obfuscation and stacked statements.
- Enforced rate limiting: Three constraints—row limit, execution timeout, and concurrency cap—prevent resource exhaustion.
- Parameterized inputs first: Pass all external input as bound parameters, never through string concatenation.
- Sensitive data protection: Desensitize or mask suspected sensitive fields, and never persist raw result sets in logs.
- End-to-end auditing: Record the caller, time, statement summary, affected rows, and duration for traceability.
7. Multi-Form Compatibility: Converging Interaction Differences in an Adapter Layer
User preferences vary widely: some prefer desktop apps, some prefer browser access, and some work in the terminal. The compatibility strategy is not to rewrite logic for each form, but to:
- Define a unified session and event model (input, incremental output, tool status, errors).
- Have each form implement a thin adapter responsible only for rendering and event forwarding.
- Declare capability differences explicitly—for example, if the terminal form has limited support for rich text tables, degrade to compact text output.
8. Evolving with the Host: Engineering Version Compatibility
A plugin host framework keeps updating, and passively chasing it easily leads to repeated patching. A more stable approach is to:
- Depend on the host’s public, stable extension contracts and avoid calling internal implementations that are not promised.
- Introduce a compatibility matrix that states the supported host version ranges, and perform capability detection and degradation at startup.
- Build host-independent unit tests for the core logic, and cover host-related parts with replaceable stub implementations.
- Keep a changelog and migration notes so users understand the impact of upgrades.
9. From 100 Stars to Long-Term Maintenance: Turning Community Feedback into a Roadmap
Real usage delivers more value than expected: users test the tool with their own databases, their own dialects, and their own metric definitions. A mechanism for turning feedback into iteration can be:
- Grade issues along three dimensions: reproducibility, impact scope, and fix cost.
- Distill high-frequency issues into built-in rules or default configurations rather than relying on manual user adjustment.
- Build a minimal evaluation set covering typical questions and edge cases, and run regression checks on every change.
- Publish known limitations and state clearly what the tool does not do; this builds more trust than vague promises.
10. Conclusion
A small project started on the side to grab some swag ultimately points to a general engineering lesson: for a large language model to truly enter the data production workflow, what matters is not a longer prompt but a reliable path built from layered architecture, context governance, multi-step verification, and security baselines. Once this foundation is solid enough, adapting to multiple interaction forms through plugins and evolving with host versions follow naturally.
