Agents enable conversation with data, including structured and unstructured data connected to MindsDB.

How Agents Work

Connect your data to MindsDB by connecting databases or applications or uploading files. Users can opt for using knowledge bases to store and retrieve data efficiently.

Create an agent, passing the connected data and defining the underlying model.

CREATE AGENT my_agent
USING
    model = 'gemini-2.0-flash',
    google_api_key = 'xyz123',
    include_knowledge_bases= ['mindsdb.sales_kb', 'mindsdb.orders_kb'],
    include_tables=['postgres_conn.customers', 'mysql_conn.products'],
    prompt_template='
        mindsdb.sales_kb stores sales analytics data
        mindsdb.orders_kb stores order data
        postgres_conn.customers stores customers data
        mysql_conn.products stores products data
    ';

Query an agent and ask question over the connected data.

SELECT answer
FROM my_agent 
WHERE question = 'What is the average number of orders per customers?';

CREATE AGENT Syntax

Here is the syntax for creating an agent:

CREATE AGENT my_agent
USING
    model = 'model-name',
    <provider>_api_key= 'abc123',
    include_knowledge_bases = ['project_name.kb_name', ...],
    include_tables = ['datasource_conn_name.table_name', ...],
    prompt_template = 'describe data';

It creates an agent that uses the defined model and has access to the connected data.

SHOW AGENTS
WHERE name = 'my_agent';

model

This parameter defines the underlying language model.

The available models and providers include the following.

<provider>_api_key

This parameter stores the API key for accessing models. Include the provider of the model in the parameter name, such as anthropic_api_key, google_api_key, openai_api_key.

For example, use google_api_key when using gemini-2.0-flash for a model, and analogically, use openai_api_key when using gpt-4o for a model.

include_knowledge_bases

This parameter stores the list of knowledge bases accessible by the agent for data retrieval.

Learn more about knowledge bases here.

include_tables

This parameter stores the list of data sources accessible by the agent.

Learn more about available data integrations here.

prompt_template

This parameter stores instructions for the agent.

It is recommended to provide data description of the data sources listed in the include_knowledge_bases and include_tables to help the agent locate relevant data for answering questions.

SELECT FROM AGENT Syntax

Query an agent to generate responses to questions.

SELECT answer
FROM my_agent 
WHERE question = 'What is the average number of orders per customers?';

Chat Interface

MindsDB provides a chat interface that enables users to chat with their data.

Select an agent from the list of existing agents, or create one if none exists yet.

Now the chat interface is connected to this agent via Agent2Agent Protocol and users can chat with the data connected to this agent.

DROP AGENT Syntax

Here is the syntax for deleting an agent:

DROP AGENT my_agent;