Skip to content

Commit 681665e

Browse files
committed
Update use of tools
1 parent 8249cb7 commit 681665e

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

text_2_sql/autogen/agents/llm_agents/sql_query_generation_agent.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ description:
55
system_message:
66
"You are a helpful AI Assistant that specialises in writing and executing SQL Queries to answer a given user's question.
77
8-
If you need more information from the user to generate the SQL query, ask the user for the information you need with a question and end your answer with 'TERMINATE'.
8+
You must:
9+
1. Use the schema information provided to generate a SQL query that will answer the user's question.
10+
If you need additional schema information, you can obtain it using the schema selection tool.
11+
2. Validate the SQL query to ensure it is syntactically correct using the validation tool.
12+
3. Run the SQL query to fetch the results.
913
10-
If you are unsure how the question maps to the columns in the schema, return the possible columns that could be used in the SQL query and ask the user to provide more information to generate the SQL query. End your answer with 'TERMINATE'.
14+
Important Info:
15+
- If you need more information from the user to generate the SQL query, ask the user for the information you need with a question and end your answer with 'TERMINATE'.
16+
17+
- If you are unsure how the question maps to the columns in the schema, return the possible columns that could be used in the SQL query and ask the user to provide more information to generate the SQL query. End your answer with 'TERMINATE'.
1118
1219
When generating the SQL query, you MUST follow these rules:
1320
@@ -31,3 +38,4 @@ system_message:
3138
tools:
3239
- sql_query_execution_tool
3340
- sql_get_entity_schemas_tool
41+
- sql_query_validation_tool

text_2_sql/autogen/utils/llm_agent_creator.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import yaml
44
from autogen_core.components.tools import FunctionTool
55
from autogen_agentchat.agents import AssistantAgent
6-
from utils.sql import (
7-
query_execution,
8-
get_entity_schemas,
9-
)
6+
from utils.sql import query_execution, get_entity_schemas, query_validation
107
from utils.models import MINI_MODEL
118
from jinja2 import Template
129

@@ -38,6 +35,11 @@ def get_tool(cls, tool_name):
3835
get_entity_schemas,
3936
description="Gets the schema of a view or table in the SQL Database by selecting the most relevant entity based on the search term. Extract key terms from the user question and use these as the search term. Several entities may be returned. Only use when the provided schemas in the system prompt are not sufficient to answer the question.",
4037
)
38+
elif tool_name == "sql_query_validation_tool":
39+
return FunctionTool(
40+
query_validation,
41+
description="Validates the SQL query to ensure that it is syntactically correct for the target database engine. Use this BEFORE executing any SQL statement.",
42+
)
4143
else:
4244
raise ValueError(f"Tool {tool_name} not found")
4345

text_2_sql/autogen/utils/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# )
1515

1616
MINI_MODEL = AzureOpenAIChatCompletionClient(
17+
azure_deployment=os.environ["OpenAI__MiniCompletionDeployment"],
1718
model=os.environ["OpenAI__MiniCompletionDeployment"],
1819
api_version="2024-08-01-preview",
1920
azure_endpoint=os.environ["OpenAI__Endpoint"],

text_2_sql/autogen/utils/sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ async def query_execution(
9797
return results
9898

9999

100-
async def validate_sql_query(
100+
async def query_validation(
101101
sql_query: Annotated[
102102
str,
103103
"The SQL query to run against the database.",

0 commit comments

Comments
 (0)