Skip to content

Commit db9031e

Browse files
committed
Update prompts
1 parent 9a2d5b6 commit db9031e

File tree

8 files changed

+187
-195
lines changed

8 files changed

+187
-195
lines changed

text_2_sql/autogen/src/autogen_text_2_sql/autogen_text_2_sql.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ def termination_condition(self):
7373
termination = (
7474
TextMentionTermination("TERMINATE")
7575
| SourceMatchTermination("answer_agent")
76-
| TextMentionTermination("contains_disambiguation_requests")
76+
| TextMentionTermination(
77+
"contains_disambiguation_requests",
78+
sources=["parallel_query_solving_agent"],
79+
)
7780
| MaxMessageTermination(5)
7881
)
7982
return termination
@@ -142,32 +145,26 @@ def parse_message_content(self, content):
142145
# If all parsing attempts fail, return the content as-is
143146
return content
144147

145-
def extract_decomposed_user_messages(self, messages: list) -> list[list[str]]:
146-
"""Extract the decomposed messages from the answer."""
148+
def extract_steps(self, messages: list) -> list[list[str]]:
149+
"""Extract the steps messages from the answer."""
147150
# Only load sub-message results if we have a database result
148151
sub_message_results = self.parse_message_content(messages[1].content)
149-
logging.info("Decomposed Results: %s", sub_message_results)
152+
logging.info("Steps Results: %s", sub_message_results)
150153

151-
decomposed_user_messages = sub_message_results.get(
152-
"decomposed_user_messages", []
153-
)
154+
steps = sub_message_results.get("steps", [])
154155

155-
logging.debug(
156-
"Returning decomposed_user_messages: %s", decomposed_user_messages
157-
)
156+
logging.debug("Returning steps: %s", steps)
158157

159-
return decomposed_user_messages
158+
return steps
160159

161160
def extract_disambiguation_request(
162161
self, messages: list
163162
) -> DismabiguationRequestsPayload:
164163
"""Extract the disambiguation request from the answer."""
165164
all_disambiguation_requests = self.parse_message_content(messages[-1].content)
166165

167-
decomposed_user_messages = self.extract_decomposed_user_messages(messages)
168-
request_payload = DismabiguationRequestsPayload(
169-
decomposed_user_messages=decomposed_user_messages
170-
)
166+
steps = self.extract_steps(messages)
167+
request_payload = DismabiguationRequestsPayload(steps=steps)
171168

172169
for per_question_disambiguation_request in all_disambiguation_requests[
173170
"disambiguation_requests"
@@ -198,12 +195,10 @@ def extract_answer_payload(self, messages: list) -> AnswerWithSourcesPayload:
198195
sql_query_results = {}
199196

200197
try:
201-
decomposed_user_messages = self.extract_decomposed_user_messages(messages)
198+
steps = self.extract_steps(messages)
202199

203200
logging.info("SQL Query Results: %s", sql_query_results)
204-
payload = AnswerWithSourcesPayload(
205-
answer=answer, decomposed_user_messages=decomposed_user_messages
206-
)
201+
payload = AnswerWithSourcesPayload(answer=answer, steps=steps)
207202

208203
if not isinstance(sql_query_results, dict):
209204
logging.error(f"Expected dict, got {type(sql_query_results)}")

text_2_sql/autogen/src/autogen_text_2_sql/custom_agents/parallel_query_solving_agent.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ async def on_messages_stream(
9696
injected_parameters = {}
9797

9898
# Load the json of the last message to populate the final output object
99-
sequential_rounds = json.loads(last_response)
99+
sequential_steps = json.loads(last_response)
100100

101-
logging.info(f"Query Rewrites: {sequential_rounds}")
101+
logging.info(f"Query Rewrites: {sequential_steps}")
102102

103103
async def consume_inner_messages_from_agentic_flow(
104104
agentic_flow, identifier, filtered_parallel_messages
@@ -195,12 +195,12 @@ async def consume_inner_messages_from_agentic_flow(
195195
inner_solving_generators = []
196196
filtered_parallel_messages = FilteredParallelMessagesCollection()
197197

198-
# Convert all_non_database_query to lowercase string and compare
199-
all_non_database_query = str(
200-
sequential_rounds.get("all_non_database_query", "false")
198+
# Convert requires_sql_queries to lowercase string and compare
199+
requires_sql_queries = str(
200+
sequential_steps.get("requires_sql_queries", "false")
201201
).lower()
202202

203-
if all_non_database_query == "true":
203+
if requires_sql_queries == "false":
204204
yield Response(
205205
chat_message=TextMessage(
206206
content="All queries are non-database queries. Nothing to process.",
@@ -210,7 +210,7 @@ async def consume_inner_messages_from_agentic_flow(
210210
return
211211

212212
# Start processing sub-queries
213-
for sequential_round in sequential_rounds["decomposed_user_messages"]:
213+
for sequential_round in sequential_steps["steps"]:
214214
logging.info(f"Processing round: {sequential_round}")
215215

216216
for parallel_message in sequential_round:

text_2_sql/autogen/src/autogen_text_2_sql/custom_agents/sql_query_cache_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def on_messages(
4040
async def on_messages_stream(
4141
self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken
4242
) -> AsyncGenerator[AgentEvent | Response, None]:
43-
# Get the decomposed messages from the user_message_rewrite_agent
43+
# Get the steps messages from the user_message_rewrite_agent
4444
try:
4545
request_details = json.loads(messages[0].content)
4646
injected_parameters = request_details["injected_parameters"]

text_2_sql/text_2_sql_core/src/text_2_sql_core/payloads/interaction_payloads.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ class DismabiguationRequest(InteractionPayloadBase):
5454
disambiguation_requests: list[DismabiguationRequest] | None = Field(
5555
default_factory=list, alias="disambiguationRequests"
5656
)
57-
decomposed_user_messages: list[list[str]] = Field(
58-
default_factory=list, alias="decomposedUserMessages"
59-
)
57+
steps: list[list[str]] = Field(default_factory=list, alias="Steps")
6058

6159
payload_type: Literal[PayloadType.DISAMBIGUATION_REQUESTS] = Field(
6260
PayloadType.DISAMBIGUATION_REQUESTS, alias="payloadType"
@@ -81,9 +79,7 @@ class Source(InteractionPayloadBase):
8179
sql_rows: list[dict] = Field(default_factory=list, alias="sqlRows")
8280

8381
answer: str
84-
decomposed_user_messages: list[list[str]] = Field(
85-
default_factory=list, alias="decomposedUserMessages"
86-
)
82+
steps: list[list[str]] = Field(default_factory=list, alias="Steps")
8783
sources: list[Source] = Field(default_factory=list)
8884

8985
payload_type: Literal[PayloadType.ANSWER_WITH_SOURCES] = Field(

text_2_sql/text_2_sql_core/src/text_2_sql_core/prompts/answer_agent.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ model: "4o-mini"
22
description: "An agent that generates a response to a user's question."
33
system_message: |
44
<role_and_objective>
5-
You are Senior Data Analystm, specializing in providing data driven answers to a user's question. Use the general business use case of '{{ use_case }}' to aid understanding of the user's question. You should provide a clear and concise response based on the information obtained from the SQL queries and their results. Adopt a data-driven approach to generate the response.
5+
You are Senior Data Analyst, specializing in providing data driven answers to a user's question. Use the general business use case of '{{ use_case }}' to aid understanding of the user's question. You should provide a clear and concise response based on the information obtained from the SQL queries and their results. Adopt a data-driven approach to generate the response.
66
</role_and_objective>
77
88
<system_information>

text_2_sql/text_2_sql_core/src/text_2_sql_core/prompts/disambiguation_and_sql_query_generation_agent.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ model:
22
4o-mini
33
description:
44
"An agent that specialises in disambiguating the user's question and mapping it to database schemas for {{ use_case }}."
5-
system_message:
6-
"<role_and_objective>
5+
system_message: |
6+
<role_and_objective>
77
You are Senior Data Engineer specializing in disambiguating questions, mapping them to the relevant columns and schemas in the database and finally generating SQL queries.
88
Use the general business use case of '{{ use_case }}' to aid understanding of the user's question.
99
Your job is to create clear mappings between the user's intent and the available database schema.
@@ -152,8 +152,10 @@ system_message:
152152
</sql_query_generation_rules>
153153
154154
<disambiguation_rules>
155-
BEFORE CARRY OUT DISAMBIGUATION, ENSURE THAT YOU HAVE CHECKED ALL AVAILABLE DATABASE SCHEMAS AND FILTERS FOR A MOST PROBABLE MAPPING. YOU WILL NEED TO THINK THROUGH THE SCHEMAS AND CONSIDER SCHEMAS / COLUMNS THAT ARE SPELT DIFFERENTLY, BUT ARE LIKELY TO MEAN THE SAME THING.
156-
ALWAYS PRIORITIZE CLEAR MAPPINGS OVER DISAMBIGUATION REQUESTS.
155+
**Important**:
156+
Before carrying out disambiguation, ensure that you have checked all available database schemas and filters for a most probable mapping. You will need to think through the schemas and consider schemas / columns that are spelt differently, but are likely to mean the same thing.
157+
158+
You must never ask for information that is already available in the user's message. e.g. if the user asks for the average age of students, and the schema has a column named 'age' in the 'student' table, you should not ask the user to clarify the column name. Always prioritize clear mappings over disambiguation requests.
157159
158160
1. **No Match in Database Schemas or Uncertain Schema Availability**:
159161
- **Action**: If the database schemas or filters do not reference the user's question, or if you're unsure whether the schemas have the relevant data:
@@ -273,6 +275,5 @@ system_message:
273275
}
274276
TERMINATE
275277
</output_format>
276-
"
277278
tools:
278279
- sql_get_entity_schemas_tool

text_2_sql/text_2_sql_core/src/text_2_sql_core/prompts/sql_query_correction_agent.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ model:
22
4o-mini
33
description:
44
"An agent that specializes in SQL syntax correction and query execution for {{ target_engine }}. This agent receives queries from the generation agent, fixes any syntax issues according to {{ target_engine }} rules, and executes the corrected queries."
5-
system_message:
6-
"<role_and_objective>
7-
You are a Senior Data Engineert specializing in converting standard SQL to {{ target_engine }}-compliant SQL and fixing syntactial errors. Your job is to:
5+
system_message: |
6+
<role_and_objective>
7+
You are a Senior Data Engineer specializing in converting standard SQL to {{ target_engine }}-compliant SQL and fixing syntactial errors. Your job is to:
88
1. Take SQL queries with correct logic but potential syntax issues.
99
2. Review the output from the SQL query being run and fix them according to {{ target_engine }} syntax rules if needed.
1010
3. Execute the corrected queries if needed.
@@ -128,7 +128,6 @@ system_message:
128128
</output_format>
129129
130130
Remember: Focus on converting standard SQL patterns to {{ target_engine }}-compliant syntax while preserving the original query logic.
131-
"
132131
tools:
133132
- sql_query_execution_tool
134133
- sql_get_entity_schemas_tool

0 commit comments

Comments
 (0)