Rajan Sharma commited on
Commit
c7867b9
·
verified ·
1 Parent(s): da1ed24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -18
app.py CHANGED
@@ -1,5 +1,4 @@
1
  # app.py
2
- # app.py
3
  from __future__ import annotations
4
  import os
5
  import traceback
@@ -108,25 +107,20 @@ def handle(user_msg: str, history_messages: List[Dict[str, str]], files: list) -
108
  # --- AGGRESSIVE PROMPT ENGINEERING FIX ---
109
  # This new prefix explicitly forbids the LLM from outputting an Action and a Final Answer simultaneously.
110
  AGENT_PREFIX = """
111
- You are a data analysis agent working with a pandas dataframe named `df`.
112
- You must answer the user's query by executing Python code one step at a time.
113
-
114
- Your response MUST strictly follow one of two formats:
115
-
116
- FORMAT 1: To think and execute code.
117
- Thought: Your reasoning for the next step. This is mandatory.
118
- Action: The tool to use, which is always `python_repl_ast`.
119
- Action Input: The single-line Python code to execute.
120
 
121
- FORMAT 2: To give the final answer.
122
- Thought: I have now gathered all the information needed to answer the user's request.
123
- Final Answer: The final, comprehensive answer.
 
124
 
125
- CRITICAL RULE: Your response must contain EITHER an "Action" OR a "Final Answer", but NEVER BOTH.
126
- If you need to run code, use FORMAT 1. If you are finished, use FORMAT 2.
127
- Do not combine them. Start by thinking about the first step.
128
 
129
- Begin!
 
130
  """
131
 
132
  # Create the pandas DataFrame agent with our new, stricter prefix
@@ -137,7 +131,7 @@ Begin!
137
  verbose=True,
138
  allow_dangerous_code=True,
139
  handle_parsing_errors=True,
140
- prefix=AGENT_PREFIX # Applying the new aggressive prompt
141
  )
142
 
143
  # Run the agent with the user's scenario text.
 
1
  # app.py
 
2
  from __future__ import annotations
3
  import os
4
  import traceback
 
107
  # --- AGGRESSIVE PROMPT ENGINEERING FIX ---
108
  # This new prefix explicitly forbids the LLM from outputting an Action and a Final Answer simultaneously.
109
  AGENT_PREFIX = """
110
+ You are a data analysis agent. You have a pandas dataframe named `df`.
111
+ You MUST respond in one of two formats.
 
 
 
 
 
 
 
112
 
113
+ FORMAT 1: To perform a task. Your response must be a single block of text with ONLY these three sections:
114
+ Thought: Your step-by-step reasoning.
115
+ Action: python_repl_ast
116
+ Action Input: The Python code to run.
117
 
118
+ FORMAT 2: To give the final answer. Your response must be a single block of text with ONLY these two sections:
119
+ Thought: I can now answer the user's query.
120
+ Final Answer: The complete answer.
121
 
122
+ CRITICAL RULE: NEVER, EVER, combine `Action` and `Final Answer` in the same response. Choose one format.
123
+ Begin by analyzing the user's query and provide your first thought and action using FORMAT 1.
124
  """
125
 
126
  # Create the pandas DataFrame agent with our new, stricter prefix
 
131
  verbose=True,
132
  allow_dangerous_code=True,
133
  handle_parsing_errors=True,
134
+ prefix=AGENT_PREFIX
135
  )
136
 
137
  # Run the agent with the user's scenario text.