Daksh Chaudhary
commited on
Updated nl_to_sql_agent: Improved system prompt
Browse files- src/agents/nl_sql_agent.py +17 -14
src/agents/nl_sql_agent.py
CHANGED
@@ -23,21 +23,24 @@ class NLSQLAgent:
|
|
23 |
"""
|
24 |
self.llm = get_finetuned_model()
|
25 |
self.system_prompt = (
|
26 |
-
"
|
27 |
-
"\
|
28 |
-
"\
|
29 |
-
"\
|
30 |
-
"\
|
31 |
-
"\
|
32 |
-
"\
|
33 |
-
"\n
|
34 |
-
"\n\n**
|
35 |
-
"\n- **
|
36 |
-
"\n-
|
37 |
-
"\n
|
38 |
-
"\
|
|
|
|
|
|
|
|
|
39 |
)
|
40 |
-
|
41 |
self.tools = [get_schema_retriever_tool(), get_sql_executor_tool()]
|
42 |
|
43 |
self.agent = ReActAgent.from_tools(
|
|
|
23 |
"""
|
24 |
self.llm = get_finetuned_model()
|
25 |
self.system_prompt = (
|
26 |
+
"<instructions>"
|
27 |
+
"\nYour task is to act as an expert SQL data analyst. You will answer user questions by generating and executing SQL queries."
|
28 |
+
"\n\n**CRITICAL RULE:** You MUST respond in the following format, without any preamble, conversational text, or explanation. Your entire response MUST start with 'Thought:'."
|
29 |
+
"\n```"
|
30 |
+
"\nThought: [Your step-by-step reasoning about the user's query and your plan.]"
|
31 |
+
"\nAction: [The name of the tool to use. Must be one of: retrieve_schema_context, execute_sql_query]"
|
32 |
+
"\nAction Input: [A valid JSON object with the parameters for the tool.]"
|
33 |
+
"\n```"
|
34 |
+
"\n\n**TOOL REFERENCE:**"
|
35 |
+
"\n- **retrieve_schema_context**: Use this first to understand the database schema for complex queries."
|
36 |
+
"\n- **execute_sql_query**: Use this to run a SQL SELECT query. Use SQLite date functions (e.g., `DATE('now', ...)`, `STRFTIME(...)`)."
|
37 |
+
"\n\n**PROCESS:**"
|
38 |
+
"\n1. Analyze the user's question."
|
39 |
+
"\n2. Use `retrieve_schema_context` if needed."
|
40 |
+
"\n3. Generate and execute the SQL query using `execute_sql_query`."
|
41 |
+
"\n4. Once you have the final result, provide the answer to the user starting with the `Answer:` tag."
|
42 |
+
"\n</instructions>"
|
43 |
)
|
|
|
44 |
self.tools = [get_schema_retriever_tool(), get_sql_executor_tool()]
|
45 |
|
46 |
self.agent = ReActAgent.from_tools(
|