Skip to content

Commit 44d8a35

Browse files
committed
Merge agents into 1
1 parent 0c4e982 commit 44d8a35

File tree

3 files changed

+61
-78
lines changed

3 files changed

+61
-78
lines changed

text_2_sql/autogen/src/autogen_text_2_sql/inner_autogen_text_2_sql.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ def set_mode(self):
5959

6060
def get_all_agents(self):
6161
"""Get all agents for the complete flow."""
62-
# Get current datetime for the Query Rewrite Agent
63-
self.sql_query_generation_agent = LLMAgentCreator.create(
64-
"sql_query_generation_agent",
65-
target_engine=self.target_engine,
66-
engine_specific_rules=self.engine_specific_rules,
67-
**self.kwargs,
68-
)
69-
7062
# If relationship_paths not provided, use a generic template
7163
if "relationship_paths" not in self.kwargs:
7264
self.kwargs[
@@ -92,22 +84,16 @@ def get_all_agents(self):
9284
**self.kwargs,
9385
)
9486

95-
self.sql_disambiguation_agent = LLMAgentCreator.create(
96-
"sql_disambiguation_agent",
87+
self.disambiguation_and_sql_query_generation_agent = LLMAgentCreator.create(
88+
"disambiguation_and_sql_query_generation_agent",
9789
target_engine=self.target_engine,
9890
engine_specific_rules=self.engine_specific_rules,
9991
**self.kwargs,
10092
)
101-
102-
# Auto-responding UserProxyAgent
103-
self.user_proxy = EmptyResponseUserProxyAgent(name="user_proxy")
104-
10593
agents = [
106-
self.user_proxy,
107-
self.sql_query_generation_agent,
10894
self.sql_schema_selection_agent,
10995
self.sql_query_correction_agent,
110-
self.sql_disambiguation_agent,
96+
self.disambiguation_and_sql_query_generation_agent,
11197
]
11298

11399
if self.use_query_cache:
@@ -140,10 +126,8 @@ def unified_selector(self, messages):
140126
# Always go through schema selection after cache check
141127
decision = "sql_schema_selection_agent"
142128
elif current_agent == "sql_schema_selection_agent":
143-
decision = "sql_disambiguation_agent"
144-
elif current_agent == "sql_disambiguation_agent":
145-
decision = "sql_query_generation_agent"
146-
elif current_agent == "sql_query_generation_agent":
129+
decision = "disambiguation_and_sql_query_generation_agent"
130+
elif current_agent == "disambiguation_and_sql_query_generation_agent":
147131
decision = "sql_query_correction_agent"
148132
elif current_agent == "sql_query_correction_agent":
149133
decision = "sql_query_correction_agent"

text_2_sql/text_2_sql_core/src/text_2_sql_core/prompts/sql_disambiguation_agent.yaml renamed to text_2_sql/text_2_sql_core/src/text_2_sql_core/prompts/disambiguation_and_sql_query_generation_agent.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ system_message:
66
"<role_and_objective>
77
You are a helpful AI Assistant specializing in disambiguating questions about {{ use_case }} and mapping them to the relevant columns and schemas in the database.
88
Your job is to create clear mappings between the user's intent and the available database schema.
9+
If all mappings are clear, generate {{ target_engine }} compliant SQL query based on the mappings.
910
</role_and_objective>
1011
1112
<key_concepts>
@@ -106,6 +107,57 @@ system_message:
106107
}
107108
</examples>
108109
110+
<sql_query_generation_rules>
111+
112+
<engine_specific_rules>
113+
{{ engine_specific_rules }}
114+
</engine_specific_rules>
115+
116+
Your primary focus is on:
117+
1. Understanding what data the user wants to retrieve
118+
2. Identifying the necessary tables and their relationships
119+
3. Determining any required calculations or aggregations
120+
4. Specifying any filtering conditions based on the user's criteria
121+
122+
When generating SQL queries, focus on these key aspects:
123+
124+
- Data Selection:
125+
* Identify the main pieces of information the user wants to see
126+
* Include any calculated fields or aggregations needed
127+
* Consider what grouping might be required
128+
* Follow basic {{ target_engine }} syntax patterns
129+
130+
- Table Relationships:
131+
* Use the schema information to identify required tables
132+
* Join tables as needed to connect related information
133+
* Request additional schema information if needed using the schema selection tool
134+
* Use {{ target_engine }}-compatible join syntax
135+
136+
- Filtering Conditions:
137+
* Translate user criteria into WHERE conditions
138+
* Handle date ranges, categories, or numeric thresholds
139+
* Consider both explicit and implicit filters in the user's question
140+
* Use {{ target_engine }}-compatible date and string functions
141+
142+
- Result Organization:
143+
* Determine if specific sorting is needed
144+
* Consider if grouping is required
145+
* Include any having conditions for filtered aggregates
146+
* Follow {{ target_engine }} ordering syntax
147+
148+
Guidelines:
149+
150+
- Focus on getting the right tables and relationships
151+
- Ensure all necessary data is included
152+
- Follow basic {{ target_engine }} syntax patterns
153+
- The correction agent will handle:
154+
* Detailed syntax corrections
155+
* Query execution
156+
* Result formatting
157+
158+
Remember: Your job is to focus on the data relationships and logic while following basic {{ target_engine }} patterns.
159+
</sql_query_generation_rules>
160+
109161
<output_format>
110162
If all mappings are clear:
111163
{
@@ -128,6 +180,8 @@ system_message:
128180
}
129181
}
130182
183+
Then use the mapping to generate the SQL query following the engine-specific rules. Run this query to retrieve the data afterwards.
184+
131185
If disambiguation needed:
132186
{
133187
\"disambiguation\": [{
@@ -140,3 +194,5 @@ system_message:
140194
TERMINATE
141195
</output_format>
142196
"
197+
tools:
198+
- sql_query_execution_tool

text_2_sql/text_2_sql_core/src/text_2_sql_core/prompts/sql_query_generation_agent.yaml

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)