jashdoshi77 commited on
Commit
c35deb5
Β·
1 Parent(s): 8550923

few fixes in prompts

Browse files
Files changed (2) hide show
  1. backend/graph.py +43 -12
  2. backend/prompts.py +18 -12
backend/graph.py CHANGED
@@ -251,6 +251,9 @@ SELF_SOLVING_PATTERNS = [
251
  r"you think.+\?",
252
  r"(?:reason|cause)\s+you\s+think",
253
  r"what role (?:do you think |does |)",
 
 
 
254
  ]
255
 
256
  # Patterns that suggest causes disguised as questions
@@ -278,7 +281,14 @@ FILLER_SENTENCES = [
278
  r"i'd like to (?:learn|help|explore|understand|hear|know|dig)",
279
  # Restating the problem robotically
280
  r"a slow[- ]moving inventory (?:of|can be)",
281
- r"(?:can be|is) a (?:challenging|significant|difficult|tough|particularly challenging) (?:issue|problem|situation|challenge) to (?:tackle|address|deal with)",
 
 
 
 
 
 
 
282
  r"it's likely that this is affecting",
283
  r"this (?:can|may|might) (?:be|also be) (?:affecting|impacting|taking)",
284
  # Robotic transitions
@@ -854,17 +864,38 @@ async def run_consultation(session_state: SessionState, user_message: str) -> Gr
854
  reply_text = parsed["reply"]
855
  non_q_lines = [line for line in reply_text.split("\n") if "?" not in line]
856
  non_q_content = "\n".join(non_q_lines).strip()
857
- if len(non_q_content) < 200:
858
- expand_msg = SystemMessage(content=(
859
- "⚠️ Your response is TOO SHORT. The client is paying for expert analysis.\n"
860
- "EXPAND your response to include:\n"
861
- "- 1-2 opening sentences reacting to what they said\n"
862
- "- A **bold header** like '**Key Observations**' followed by 3-4 bullet points\n"
863
- " with specific insights, industry knowledge, or patterns you've noticed\n"
864
- "- 1-2 sentences of concrete recommendation or context\n"
865
- "- THEN your question(s)\n"
866
- "Total response before questions should be at least 5-8 sentences."
867
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
868
  messages.insert(-1, expand_msg)
869
  response = await llm.ainvoke(messages)
870
  parsed = _parse_llm_output(response.content)
 
251
  r"you think.+\?",
252
  r"(?:reason|cause)\s+you\s+think",
253
  r"what role (?:do you think |does |)",
254
+ # "What are your thoughts/take/opinion on" patterns
255
+ r"what (?:are |)your (?:thoughts|take|opinion) on",
256
+ r"your thoughts on .+\?",
257
  ]
258
 
259
  # Patterns that suggest causes disguised as questions
 
281
  r"i'd like to (?:learn|help|explore|understand|hear|know|dig)",
282
  # Restating the problem robotically
283
  r"a slow[- ]moving inventory (?:of|can be)",
284
+ r"(?:can be|is) a (?:challenging|significant|difficult|tough|particularly challenging|common) (?:issue|problem|situation|challenge)",
285
+ r"(?:this|it) can be a (?:common|challenging|significant) (?:issue|problem|situation)",
286
+ r"especially (?:given|with) the (?:high value|constantly changing|luxury|competitive)",
287
+ r"especially given the high value and luxury nature",
288
+ r"(?:diamond|jewelry) (?:rings? (?:are|is)|market can be) (?:often |)(?:purchased|subject to|a high)",
289
+ r"are often purchased for special occasions",
290
+ r"the quality and characteristics of the diamonds",
291
+ r"the diamond (?:market|ring market|industry) can be",
292
  r"it's likely that this is affecting",
293
  r"this (?:can|may|might) (?:be|also be) (?:affecting|impacting|taking)",
294
  # Robotic transitions
 
864
  reply_text = parsed["reply"]
865
  non_q_lines = [line for line in reply_text.split("\n") if "?" not in line]
866
  non_q_content = "\n".join(non_q_lines).strip()
867
+
868
+ # SOLUTION/REFINEMENT phases need MUCH longer responses (detailed action plans)
869
+ is_final_phase = session_state.phase in (Phase.SOLUTION, Phase.REFINEMENT)
870
+ min_length = 500 if is_final_phase else 200
871
+
872
+ if len(non_q_content) < min_length:
873
+ if is_final_phase:
874
+ expand_msg = SystemMessage(content=(
875
+ "⚠️ Your response is FAR TOO SHORT for a final recommendation.\n"
876
+ "The client has been answering your questions β€” now DELIVER VALUE.\n"
877
+ "Your response MUST include ALL of these:\n"
878
+ "1. **Problem Summary** β€” 2-3 sentences about their specific situation\n"
879
+ "2. **Root Cause Analysis** β€” what you believe is causing the problem\n"
880
+ "3. **Step-by-Step Action Plan** with NUMBERED steps organized by timeline:\n"
881
+ " - **Immediate (This Week):** 2-3 quick wins\n"
882
+ " - **Short-Term (Next 2-4 Weeks):** 3-4 tactical changes\n"
883
+ " - **Medium-Term (1-3 Months):** 2-3 strategic initiatives\n"
884
+ "4. **Expected Outcomes** β€” what results they can expect\n"
885
+ "Each step must name SPECIFIC tools, methods, platforms. NOT vague advice.\n"
886
+ "This response should be LONG and DETAILED β€” at least 300 words."
887
+ ))
888
+ else:
889
+ expand_msg = SystemMessage(content=(
890
+ "⚠️ Your response is TOO SHORT. The client is paying for expert analysis.\n"
891
+ "EXPAND your response to include:\n"
892
+ "- 1-2 opening sentences reacting to what they said\n"
893
+ "- A **bold header** like '**Key Observations**' followed by 3-4 bullet points\n"
894
+ " with specific insights, industry knowledge, or patterns you've noticed\n"
895
+ "- 1-2 sentences of concrete recommendation or context\n"
896
+ "- THEN your question(s)\n"
897
+ "Total response before questions should be at least 5-8 sentences."
898
+ ))
899
  messages.insert(-1, expand_msg)
900
  response = await llm.ainvoke(messages)
901
  parsed = _parse_llm_output(response.content)
backend/prompts.py CHANGED
@@ -122,14 +122,20 @@ TURN_1_PROMPT = (
122
  + """
123
  THIS IS THE USER'S VERY FIRST MESSAGE.
124
 
125
- YOUR RESPONSE MUST:
 
 
 
 
126
  1. Start with a short, warm reaction to what they said (1 sentence)
127
  2. Ask 2 natural follow-up questions about their situation β€” one about their
128
- business/domain and one about the problem. Keep them simple and conversational.
 
129
 
130
- THAT'S IT. Only 2 questions. Both must be **bolded** and on their own line.
131
  Do NOT lecture. Do NOT list possible causes. Do NOT assume anything.
132
  Do NOT create any "Key Points" or "Summary" sections.
 
133
  """
134
  + _OUTPUT_FORMAT
135
  )
@@ -165,17 +171,17 @@ EXPLORATION_PROMPT = (
165
  + """
166
  PHASE: Exploration | Confidence: {confidence:.0%}
167
 
168
- You understand the basics. Now dig into the ROOT CAUSE and their DATA.
169
 
170
- Two things you MUST learn during exploration:
171
- 1. ROOT CAUSE β€” Which specific parts are affected, what's changed, what
172
- they've already tried. Narrow it down.
173
- 2. DATA β€” Where do they keep track of their business information? Do they
174
- use Excel, a notebook, software, or nothing at all? This is critical
175
- because your recommendations depend on what data they have access to.
176
 
177
- If you haven't asked about their data yet, make ONE of your questions
178
- about how they track or record their business information.
179
 
180
  Give brief insights where you can. 1-2 questions max.
181
  """
 
122
  + """
123
  THIS IS THE USER'S VERY FIRST MESSAGE.
124
 
125
+ IMPORTANT: If the user just says "hi" or "hello" or a simple greeting WITHOUT
126
+ describing any problem, give a SHORT warm greeting (1-2 sentences max) and ask
127
+ what they'd like help with. Do NOT generate generic observations or filler.
128
+
129
+ If they DO describe a problem, respond with:
130
  1. Start with a short, warm reaction to what they said (1 sentence)
131
  2. Ask 2 natural follow-up questions about their situation β€” one about their
132
+ business/domain and one about the SPECIFIC details of the problem.
133
+ For example: "Which products are affected?" or "How long has this been happening?"
134
 
135
+ Keep it to 2 questions max. Both must be **bolded** and on their own line.
136
  Do NOT lecture. Do NOT list possible causes. Do NOT assume anything.
137
  Do NOT create any "Key Points" or "Summary" sections.
138
+ Do NOT generate generic observations like "every business challenge is unique".
139
  """
140
  + _OUTPUT_FORMAT
141
  )
 
171
  + """
172
  PHASE: Exploration | Confidence: {confidence:.0%}
173
 
174
+ You understand the basics. Now dig into the ROOT CAUSE.
175
 
176
+ Your priority order:
177
+ 1. ROOT CAUSE β€” What specifically is causing the problem? Narrow it down.
178
+ Ask about: what changed, what they've already tried, which specific
179
+ parts of the business are most affected and why.
180
+ 2. PAST ATTEMPTS β€” What have they tried to fix it? What happened?
181
+ 3. DATA (only if not asked yet) β€” How do they track their business info?
182
 
183
+ Do NOT ask generic questions about team size, goals, or sales channels.
184
+ Stay focused on understanding WHY the problem exists.
185
 
186
  Give brief insights where you can. 1-2 questions max.
187
  """