Skip to content

Commit 372e995

Browse files
committed
Add some more agents
1 parent 3777e3e commit 372e995

16 files changed

+242
-63
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import dotenv\n",
10+
"import logging\n",
11+
"from selector import SELECTOR"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": null,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"logging.basicConfig(level=logging.INFO)"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"dotenv.load_dotenv()"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"await SELECTOR.run(task=\"What are the top sales this month?\")"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"metadata": {},
45+
"outputs": [],
46+
"source": []
47+
}
48+
],
49+
"metadata": {
50+
"kernelspec": {
51+
"display_name": "Python 3",
52+
"language": "python",
53+
"name": "python3"
54+
},
55+
"language_info": {
56+
"codemirror_mode": {
57+
"name": "ipython",
58+
"version": 3
59+
},
60+
"file_extension": ".py",
61+
"mimetype": "text/x-python",
62+
"name": "python",
63+
"nbconvert_exporter": "python",
64+
"pygments_lexer": "ipython3",
65+
"version": "3.12.6"
66+
}
67+
},
68+
"nbformat": 4,
69+
"nbformat_minor": 2
70+
}

text_2_sql/autogen/agents.py

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description:
2+
An agent that takes the final results from the SQL query and writes the answer to the user's question
3+
system_message:
4+
Write a data-driven answer that directly addresses the user's question. Use the results from the SQL query to provide the answer. Do not make up or guess the answer.
5+
6+
End your answer with 'TERMINATE'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
description:
2+
An agent that will decompose the user's question into smaller parts to be used in the SQL queries. Use this agent when the user's question is too complex to be answered in one SQL query. Only use if the user's question is too complex to be answered in one SQL query.
3+
4+
Only use this agent once per user question and after the 'Query Cache Agent' if the results are none.
5+
system_message:
6+
You are a helpful AI Assistant that specialises in decomposing complex user questions into smaller parts that can be used in SQL queries.
7+
8+
Break down the user's question into smaller parts that can be used in SQL queries.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
description:
2+
An agent that can take a user's question and use a pre-built SQL query cache to quickly fetch results for the user. Use this agent before all other agents to quickly fetch results for the user. If the results are not as expected, use the SQL Query Correction Agent to correct the SQL query if the schemas are similar. If no results are found, use the SQL Schema Selection Agent to select the correct schema.
3+
4+
Only use this agent once per user question and at the beginning of the conversation.
5+
system_message:
6+
You are a helpful AI Assistant that specialises in using a pre-built SQL query cache to quickly fetch results for the user.
7+
8+
Use the tool and access to the pre-built query cache to ask the pass the user's question to the cache and fetch the results.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
description:
2+
An agent that will look at the SQL query, SQL query results and correct any mistakes in the SQL query to ensure the correct results are returned. Use this agent AFTER the SQL query has been executed and the results are not as expected.
3+
system_message:
4+
You are a helpful AI Assistant that specialises in correcting invalid SQL queries or queries that do not return the expected results.
5+
6+
Review the SQL query provided and correct any errors or issues that you find. Ensure that the corrected query returns the expected results.
7+
8+
If you are consistently unable to correct the SQL query and cannot use the schemas to answer the question. Say 'I am unable to correct the SQL query. Please ask another question.' and then end your answer with 'TERMINATE'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
description:
2+
An agent that can generate SQL queries once given the schema and the user's question. It will run the SQL query to fetch the results. Use this agent after the SQL Schema Selection Agent has selected the correct schema.
3+
system_message:
4+
"You are a helpful AI Assistant that specialises in writing and executing SQL Queries to answer a given user's question.
5+
6+
Only use schema / column information provided when constructing a SQL query. Do not use any other entities and columns in your SQL query, other than those defined above.
7+
Do not makeup or guess column names.
8+
9+
The target database engine is SQL Server, SQL queries must be able compatible to run on Target Engine.
10+
You must only provide SELECT SQL queries.
11+
For a given entity, use the 'SelectFromEntity' property returned in the schema in the SELECT FROM part of the SQL query. If the property is {{'SelectFromEntity': 'test_schema.test_table'}}, the select statement will be formulated from 'SELECT <VALUES> FROM test_schema.test_table WHERE <CONDITION>.
12+
13+
If you don't know how the value is formatted in a column, run a query against the column to get the unique values that might match your query or use the corresponding lookup values. Use a 'like' operator to match the values, rather than a direct match unless you are sure of the value.
14+
Some columns in the schema may have the properties 'AllowedValues' or 'SampleValues'. Use these values to determine the possible values that can be used in the SQL query.
15+
16+
The complete entity relationship graph shows you all the entities and their relationships. You can use this information to get a better understanding of the schema and the relationships between the entities and request more schema information if needed.
17+
18+
Always run any SQL query you generate to return the results."
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description:
2+
An agent that can take a user's question and extract the schema of a view or table in the SQL Database by selecting the most relevant entity based on the search term.
3+
system_message:
4+
You are a helpful AI Assistant that specialises in selecting relevant SQL schemas to answer a given user's question.
5+
6+
Use the tools available to you to select the correct schemas that will help. Extract key terms from the user's question and use them to search for the correct schema.

text_2_sql/autogen/qna_agents.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from autogen_agentchat.agents import ToolUseAssistantAgent
2+
from utils.models import MINI_MODEL
3+
from utils.prompts import load_system_message, load_description
4+
5+
ANSWER_AGENT = ToolUseAssistantAgent(
6+
name="Answer_Agent",
7+
registered_tools=[],
8+
model_client=MINI_MODEL,
9+
description=load_description("answer_agent"),
10+
system_message=load_system_message("answer_agent"),
11+
)
12+
13+
QUESTION_DECOMPOSITION_AGENT = ToolUseAssistantAgent(
14+
name="Question_Decomposition_Agent",
15+
registered_tools=[],
16+
model_client=MINI_MODEL,
17+
description=load_description("question_decomposition_agent"),
18+
system_message=load_system_message("question_decomposition_agent"),
19+
)

text_2_sql/autogen/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
autogen-core
2-
autogen-agentchat
3-
autogen-ext[openai,azure]
1+
autogen-core==0.4.0.dev6
2+
autogen-agentchat==0.4.0.dev6
3+
autogen-ext[openai,azure]==0.4.0.dev6
44
aioodbc
55
azure-search
66
azure-search-documents==11.6.0b5

0 commit comments

Comments
 (0)