Building AI Agents With Your Enterprise Data: A Developer’s Guide

Cover Image for Building AI Agents With Your Enterprise Data: A Developer’s Guide

The era of intelligent applications is here. AI agents are no longer a futuristic dream—they are reshaping how businesses interact with data, automate processes, and deliver insights.

Yet, LLMs are only as useful as the knowledge and data they have access to, and for most developers, building AI agents over enterprise data remains challenging. Legacy systems, scattered datasets, and complex queries often stand in the way. So how can companies build intelligent agents that efficiently work with enterprise data and tools?

This blog explores the "why" and "how" of building AI agents over enterprise data, and introduces MindsDB—an open-source platform that simplifies the process, enabling developers to create smarter, more transparent, and reliable AI solutions.

The Challenges of Leveraging Enterprise Data for AI Agents

Enterprise data is a goldmine of insights, but it comes with challenges:

  1. Complex Data Structures: Enterprise data often resides in structured databases, unstructured documents, or a mix of both.

  2. Scalability Concerns: Running AI queries on vast datasets can slow down performance without optimized systems.

  3. Integration Hurdles: AI systems must integrate seamlessly into existing workflows and tools.

  4. Transparency Needs: Developers and users need to understand how AI reaches conclusions to build trust.

These challenges demand solutions that simplify workflows, maintain scalability, and offer transparency.

Why MindsDB for Building AI Agents Over Enterprise Data?

MindsDB offers a unique approach to building AI agents, designed with developers in mind:

  • Model Flexibility: Access and adapt any LLM freely for your specific needs.

  • Built for Developers: It integrates effortlessly with almost 200 popular data platforms, enabling natural language querying over your existing data.

  • Transparent AI Reasoning: MindsDB doesn’t just provide answers; it shows how those answers are derived, empowering developers to refine and trust their systems.

  • Advanced Querying Capabilities: Use parametric and semantic search to fetch precise, contextually relevant data.

  • Ease of Use: Set up AI agents quickly without needing extensive AI expertise.

Whether you’re building a customer support bot or a data analytics tool, MindsDB simplifies the process of turning raw data into actionable AI.

Step-by-Step: Building Your First AI Agent with MindsDB

Let’s get hands-on! This tutorial will guide you through building a simple AI agent that queries enterprise data (both structured and unstructured).

Objective

Create an AI agent to answer questions related to house sales data contained in a Postgres database and PDF files.

Overview

With MindsDB, you can create and deploy AI agents that comprise AI models and customizable skills such as knowledge bases and text-to-SQL.

AI agents use a conversational Large Language Model (like OpenAI) and LangChain utilizing its tools as skills to respond to user input. Users can customize AI agents with their own prompt templates to fit their use cases.

MindsDB agents have two main skills:

  • Knowledge Base: This is a batteries-included RAG system that you can create and insert data into, as well as query as if it were a database table. Internally, MindsDB knowledge bases use an embedding model to embed data into vectors and a vector store to store embedded data.

  • Text-to-SQL: This is a retrieval system that turns users’ queries provided in natural language into SQL queries that fetch relevant data from underlying data sources.

Both types of skills provide insights into how an agent arrives at an answer (more in Step 6).

After the agent is successfully created and validated, you can build it into your application using MindsDB APIs and SDKs for Python or Javascript. Or you can use MindsDB’s integrations with messaging systems like Slack or MS Teams.

Step 1: Setup MindsDB

  1. Install MindsDB locally using Docker or get it from AWS marketplace.

  2. Follow this guide to adjust MindsDB configuration for your own environment.

MindsDB works through SQL interface by enhancing standard commands with AI building blocks, following the conventions of MySQL and PostgreSQL syntax. It also has an API for MongoDB, Python and Javascript.

This tutorial presents how to build and deploy AI agents using MindsDB’s SQL API. MindsDB provides a SQL Editor, so you don’t need to download additional SQL clients to connect to MindsDB - however, it is also possible.

Step 2: Create a conversational AI model

This is the first component of an AI agent. It uses LangChain handler, a framework for developing applications powered by language models. The integration provides models with access to data from various data sources.

Use the CREATE MODEL statement and a LangChain engine to connect to a conversational model. If required, adjust the parameters and prompts to fit your use case.

CREATE MODEL conversational_model
PREDICT answer
USING
    engine = 'langchain',
    openai_api_key = 'YOUR_OPENAI_API_KEY_HERE',
    model_name = 'gpt-4',
    mode = 'conversational',
    user_column = 'question' ,
    assistant_column = 'answer',
    max_tokens = 100,
    temperature = 0,
    verbose = True,
    prompt_template = 'Answer the user input in a helpful way';

The code above presents how to use one of the OpenAI models. However, you can use models from Anthropic, OpenAI, Anyscale, Ollama, and other models created within MindsDB.

Ensure the model status reads complete before proceeding by running this command.

DESCRIBE conversational_model;

Step 3: Create Skills

This is the second component of an AI agent. We will create two skills – “text-to-SQL” which translates users’ questions into SQL queries to fetch relevant data, and a “Knowledge Base” which stores data in the form of embeddings.

With MindsDB, users can connect both structured and unstructured data to an AI Agent in order to ask questions over users’ data.

  • The text-to-SQL skill works by translating users’ questions into SQL queries and using them to fetch relevant data from the connected data sources.

  • The knowledge base orchestrates a RAG solution. It stores users’ data in the form of embeddings to make retrieval more efficient and accurate.

Text-to-SQL skill

In this example, we will connect it to a “house sales” dataset that has historical data about sales of properties in one of the US regions from 2007 to 2015. See what data is available in our sample database, or you can connect your own data.

Firstly, connect to a database via the CREATE DATABASE statement. Use the following SQL query in MindsDB, if you want to connect our sample data:

CREATE DATABASE datasource --you can define your own name here
WITH ENGINE = "postgres",
PARAMETERS = {
    "user": "demo_user",
    "password": "demo_password",
    "host": "samples.mindsdb.com",
    "port": "5432",
    "database": "demo",
    "schema": "demo_data"
};

After the database is successfully connected, you can create a Skill using the CREATE SKILL command:

CREATE SKILL text2sql_skill
USING
    type = 'text2sql',
    database = 'datasource', -- a database name you created in the previous step
    tables = ['house_sales'], -- optionally, list table(s) to be made accessible by an agent
    description = 'this is house sales data'; -- provide data description

It is recommended to only include tables that are necessary to your agent and describe well data labels in the description parameter.

Knowledge base skill.

Follow our docs to see a comprehensive guide to knowledge bases within MindsDB.

In this example, we will connect a PDF file that stores an analysis report of the house prices. You can download it from here.

Creating a knowledge base starts by creating an embedding model to be used for embedding the ingested data.

-- option 1: Hugging Face embedding model
CREATE MODEL embedding_model_hf
PREDICT embedding
USING
         engine = 'langchain_embedding',
         class = 'HuggingFaceEmbeddings',
     input_columns = ["content"];

-- option 2: OpenAI embedding model
CREATE MODEL embedding_model_openai
PREDICT embeddings
USING
      engine = "embedding",
      class = "openai",
      openai_api_key = "your-openai-api-key",
      input_columns = ["content"];

Next, create a “Knowledge Base” object, providing this embedding model.

CREATE KNOWLEDGE BASE my_knowledge_base
USING
    model = embedding_model_hf;

At this point you can upload your PDF files to MindsDB in order to insert the content into the knowledge base.

Now, insert data into the Knowledge Base.

INSERT INTO my_knowledge_base
     SELECT *
     FROM files.my_file_name;

With that, you can create a Skill that uses this Knowledge Base.

CREATE SKILL kb_skill
USING
    type = 'knowledge_base',
    source = 'my_knowledge_base', -- this must be created with CREATE KNOWLEDGE_BASE
    description = 'Analysis on the house prices and trends; -- data description to help the agent know when to use the knowledge base

Step 4: Create an AI agent

Now that both the AI model and the skills are ready, let’s create an AI agent.

CREATE AGENT ai_agent
USING
    model = 'conversational_model',
    skills = ['text2sql_skill', 'kb_skill'];

Verify that the agent has been created successfully using this command:

SHOW AGENTS;

At this point, you can test the agent by asking questions using SQL commands. Simply provide the question in the WHERE clause.

SELECT question, answer
FROM ai_agent
WHERE question = 'how many houses were sold in 2015?';

Alternatively, you can connect this agent to popular messaging platforms like Slack or use MindsDB API to embed it into any custom application you might have.

Step 5: Create a Slack chatbot (optional)

Optionally, you can create a chatbot by connecting an AI agent to a chat interface. Here’s how to connect it to Slack.

First, connect a chat interface to MindsDB.

CREATE DATABASE mindsdb_slack
WITH
  ENGINE = 'slack',
  PARAMETERS = {
      "token": "xoxb-xxx",
      "app_token": "xapp-xxx"
    };

Follow detailed instructions on connecting Slack to MindsDB.

Now CREATE CHATBOT providing the “AI agent” and the “Slack connection” just created.

CREATE CHATBOT ai_chatbot
USING
    database = 'mindsdb_slack', -- connect a chat interface with CREATE DATABASE
    agent = 'ai_agent'; -- create an agent with with CREATE AGENT

Verify that the chatbot is running using this command:


SHOW CHATBOTS;

Now you can go ahead and chat with the AI agent via Slack.

Step 6: Test and optimize the AI agent

To validate the agent let’s ask it some questions about the data we have. We prefer using Slack as a more convenient chat interface, but you can also do it from the MindsDB console, as outlined at the end of Step 4.

Here are some examples:

Now that we connected both the house_sales table and the PDF file to the AI Agent, we can ask questions over this connected data.

  • Questions that utilize the text-to-sql skill to retrieve data from the house_sales table:

  • Questions that utilize the knowledge base skill to retrieve data from the PDF file on house prices:

Note that you can observe the steps taken by the AI Agent in the console where MindsDB is running.

Monitoring the behavior of an agent

You can follow the steps taken by the AI agent, which are logged in the MindsDB console at the time when the question is asked. These steps outline which data sources were used to create responses to users’ questions. This important information can help you understand how to improve the prompt templates used for the underlying model and skills.

Here is a sample console log generated upon asking the question “How many houses were sold in 2007?”.

Looking at the first four lines, we see that an agent is using a tool - here, the text-to-sql skill - and generated a SQL query to fetch relevant data.

We recommend keeping general instructions in the Model’s prompt template and dataset-specific instructions (like explaining data labels, etc.) in the skills.

Updating prompt templates for the model and skills

If you want to update the skills connected to an AI agent, you can use the below command, without the need to recreate an agent.

UPDATE text2sql_skill
SET
    database = 'new_db',
    tables = ['new_table'],
    description = 'new description';

UPDATE kb_skill
SET
    source = 'new_kb',
    description = 'new description';

The text2sql skill accesses data in real-time from the connected data sources. In the case of the knowledge base skill, you need to insert new data into the underlying knowledge base to make it available to an agent.

INSERT INTO my_knowledge_base
     SELECT *
     FROM data_source;

A Pro tip:
You can automate this process by setting up a job that will insert new data into the knowledge base every time new data becomes available.

CREATE JOB keep_knowledge_base_up_to_date AS (

    INSERT INTO my_knowledge_base (
        SELECT *
        FROM data_source
        WHERE id > LAST
    )

) EVERY hour;

If you want to update the parameters of the underlying model of an AI agent, you need to (re)create the model as in Step 2, and then, (re)create an agent as in Step 4.

Real-World Use Cases and Applications

Developers across industries are finding innovative ways to use MindsDB to build AI agents that transform enterprise operations. Here are some real-world examples of what’s possible:

1. Customer Support Automation

Companies are using MindsDB to create AI-powered agents that provide instant answers to customer queries. These agents:

  • Pull information from FAQs, support documentation, and historical ticket data.

  • Enable natural language responses, such as: “When will my order arrive?”

  • Escalate complex issues to human agents only when necessary, reducing response time and workload.

2. Financial Analytics and Reporting

In the financial sector, accurate and timely data is critical. MindsDB-powered AI agents:

  • Query transactional data to answer questions like: “What were last quarter's top expenses?”

  • Generate real-time reports on revenue, expenditure, or customer trends.

  • Help financial analysts make decisions faster without writing complex SQL queries.

3. Operational Decision-Making

AI agents built with MindsDB enable operations teams to get insights without needing a data expert. For instance:

  • Factory managers ask questions like: “What caused the production delay last week?”

  • Logistics teams can track inventory trends, delivery times, or supply chain bottlenecks.

4. Sales and Marketing Insights

Sales teams often need quick access to performance data. MindsDB-powered agents can:

  • Answer questions like: “Which region had the highest sales growth this year?”

  • Predict future trends using historical data and machine learning models.

  • Help marketing teams analyze campaign performance in real-time.

5. Compliance and Regulatory Assistance

Navigating complex regulations is a challenge for many industries. MindsDB simplifies this by:

  • Ingesting compliance documentation and allowing teams to ask specific questions like: “Does this process comply with regulation X?”

  • Summarizing changes in laws or policies for relevant teams.

6. Customer Personalization

With customer data scattered across systems, creating personalized experiences is tough. MindsDB agents can:

  • Aggregate data from different sources (CRM, transaction logs, user behavior).

  • Answer queries like: “What’s the next best product recommendation for this customer?”

  • Enable tailored marketing campaigns and improve customer satisfaction.

7. Document Summarization and Knowledge Retrieval

For industries dealing with large document repositories, MindsDB helps AI agents:

  • Summarize lengthy documents in seconds.

  • Answer questions like: “What are the key findings from this report?”

  • Search and retrieve specific pieces of information with high accuracy.

Introducing Minds: a turnkey cloud solution for AI agents

While building AI agents from scratch can be rewarding, sometimes you need a faster path to results. That’s where Minds, MindsDB’s packaged cloud solution, comes in.

Minds is a ready-to-use system designed to deliver the same functionality as the AI agent built in this tutorial—but with significantly less time and effort. With Minds, you can:

  • Skip the setup and configuration and start querying your enterprise data immediately.

  • Leverage pre-built integrations and optimizations for seamless performance.

  • Focus on deploying AI where it matters most, instead of reinventing the wheel.

Minds is ideal for businesses that want the power of advanced AI without the complexity of building and maintaining custom systems.

With Minds, any developer can seamlessly incorporate Gen-AI features with enterprise data knowledge into your applications in 3 simple steps:

  1. Create a Mind.

  2. Plug-in data sources.

  3. Ask questions from your Application or Agent using our OpenAI-compatible API.

The Mind responds as an expert would. It orchestrates across multiple knowledge sources and reasons about how best to answer complex questions.

Next Steps

It’s time to decide how you want to harness the power of AI over your enterprise data:

  • DIY with open source: Build your own AI agent and explore its flexibility. Follow this tutorial, and dive into the MindsDB documentation. Join our Developer Community for tips, troubleshooting, and ideas.

  • Get it on your terms: Save time and effort by choosing Minds, a turnkey enterprise-ready solution. Our team offers implementation support and reference architectures to accelerate your AI journey. Contact us to learn more about how we can help.