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 model (like OpenAI) from LangChain utilizing tools as skills to respond to user input. Users can customize AI agents with their own prompts to fit their use cases.A chatbot can be thought of as an agent connected to some messaging interface.
Start by setting up the skills. Here is how you can create and manage skills using SQL API.
Creating, inserting into, updating, and deleting a knowledge base:
Copy
Ask AI
CREATE KNOWLEDGE BASE my_knowledge_baseUSING model = embedding_model_name, -- this parameter is optional; if not provided, a suitable embedding model is chosen for the task storage = vector_database.storage_table; -- this parameter is optional; if not provided, the default ChromaDB is used for storage-- inserts new data rows and generates id for each row if id is not providedINSERT INTO my_knowledge_base SELECT text AS content FROM datasource.data_table;-- inserts new data rows and updates existing ones if id value matchesINSERT INTO my_knowledge_base SELECT id, text AS content FROM datasource.data_table;-- view content of a knowledge base (for example, to look up the generated id values)SELECT * FROM my_knowledge_base;DROP KNOWLEDGE BASE my_knowledge_base;
Creating, updating, and deleting a skill that utilizes a knowledge base:
Copy
Ask AI
CREATE SKILL kb_skillUSING type = 'knowledge_base', source = 'my_knowledge_base', -- this must be created with CREATE KNOWLEDGE BASE description = 'My data'; -- data description to help the agent know when to use the knowledge baseUPDATE SKILL kb_skillSET source = 'new_knowledge_base'; -- this must be created with CREATE KNOWLEDGE BASEDROP SKILL kb_skill;
Creating, updating, and deleting a text-to-SQL skill:
Copy
Ask AI
CREATE SKILL text_to_sql_skillUSING type = 'text_to_sql', database = 'example_db', -- this must be created with CREATE DATABASE tables = ['sales_data']; -- this is a list of tables passed to this skillUPDATE SKILL text_to_sql_skillSET database = 'new_example_db', -- this must be created with CREATE DATABASE tables = ['sales_data']; -- this is a list of tables passed to this skillDROP SKILL text_to_sql_skill;
An agent can be created, deleted, queried, and updated. Here is how you can do that using SQL API.
Creating an AI agent:
Copy
Ask AI
CREATE AGENT my_agentUSING model = 'chatbot_agent', -- this must be a conversational model created with CREATE MODEL (as in the Example section) skills = ['test_skill']; -- this must be created with CREATE SKILL
Updating an AI agent:
Copy
Ask AI
UPDATE AGENT my_agentSET model = 'new_chatbot_agent', -- this must be a conversational model created with CREATE MODEL skills_to_remove = ['test_skill'], skills_to_add = ['production_skill']; -- this must be created with CREATE SKILL
Querying an AI agent:
Copy
Ask AI
SELECT *FROM my_agentWHERE question = "insert your question"; -- this is the user_column parameter as defined when creating a conversational model for the agent (as in the Example section)
Deleting an AI agent:
Copy
Ask AI
DROP AGENT my_agent;
You can query all agents using this command:
Copy
Ask AI
SHOW AGENTS [FROM project_name];SELECT * FROM agents;
Now that we have a model and a skill, let’s create an agent.
Copy
Ask AI
CREATE AGENT text_to_sql_agentUSING model = 'my_model', skills = ['text_to_sql_skill'];
Query the agent as below:
Copy
Ask AI
SELECT *FROM text_to_sql_agentWHERE question = "how many cars were sold in 2017?"; -- this column is defined in the user_column parameter in CREATE MODEL
The next step would be to connect a chat app, like Slack, to MindsDB and create a chatbot utilizing this agent.
In this example, let’s create an embedding model (you can choose one from OpenAI, Hugging Face, or LangChain) for the knowledge base. Note that this step is optional, as knowledge bases provide default embedding model.
Now let’s create a knowledge base that uses this embedding model and the default storage vector database (that is, ChromaDB).
Copy
Ask AI
CREATE KNOWLEDGE BASE my_knowledge_baseUSING model = embedding_model; -- this is optional
This is how you can insert data into the knowledge base and select it.
Copy
Ask AI
INSERT INTO my_knowledge_base (content)VALUES ('I drink tea.');SELECT * FROM my_knowledge_base;
Use this knowledge base to create a skill for an agent:
Copy
Ask AI
CREATE SKILL kb_skillUSING type = 'knowledge_base', source = 'my_knowledge_base', -- this must be created with CREATE KNOWLEDGE BASE description = 'My data'; -- data description to help the agent know when to use the knowledge base
Now you can assign this skill to the agent ( that was created in the example above) and query it again:
Copy
Ask AI
UPDATE AGENT text_to_sql_agentSET skills_to_add = ['kb_skill'];SELECT *FROM text_to_sql_agentWHERE questions = "what is your data?";