Spaces:
Sleeping
Sleeping
Commit ·
7f34cf9
1
Parent(s): 9c22892
Fix: Pass user query to LLM context in Fast Lane and Deep Dive stages
Browse files- prompts.py +17 -4
- reasoning_engine.py +8 -7
prompts.py
CHANGED
|
@@ -988,16 +988,19 @@ def format_minimal_diagnosis(result) -> str:
|
|
| 988 |
# =============================================================================
|
| 989 |
|
| 990 |
FAST_LANE_PROMPT = """You are Agrow-AI.
|
| 991 |
-
TASK:
|
| 992 |
PRIORITY: SPEED & ACCURACY.
|
| 993 |
|
|
|
|
|
|
|
|
|
|
| 994 |
CONTEXT:
|
| 995 |
{context}
|
| 996 |
|
| 997 |
INSTRUCTIONS:
|
| 998 |
1. [Hypothesis]: Briefly state what the primary signals (NDVI, NDRE, etc.) suggest.
|
| 999 |
2. [Check]: Verify if supporting data (Moisture, Weather) aligns or contradicts.
|
| 1000 |
-
3. [Diagnosis]: State the final conclusion.
|
| 1001 |
4. [Action]: One specific corrective action.
|
| 1002 |
|
| 1003 |
OUTPUT JSON ONLY:
|
|
@@ -1012,11 +1015,14 @@ OUTPUT JSON ONLY:
|
|
| 1012 |
DEEP_DIVE_HYPOTHESIS_PROMPT = """You are Agrow-AI, conducting a DEEP DIVE diagnosis.
|
| 1013 |
STAGE A: HYPOTHESIS GENERATION
|
| 1014 |
|
|
|
|
|
|
|
|
|
|
| 1015 |
CONTEXT:
|
| 1016 |
{context}
|
| 1017 |
|
| 1018 |
TASK:
|
| 1019 |
-
Identify top 3 possible causes
|
| 1020 |
Think broadly (Nutrients, Pests, Water, Soil, Disease).
|
| 1021 |
|
| 1022 |
OUTPUT JSON ONLY:
|
|
@@ -1032,6 +1038,9 @@ OUTPUT JSON ONLY:
|
|
| 1032 |
DEEP_DIVE_ADVERSARY_PROMPT = """You are Agrow-AI.
|
| 1033 |
STAGE B: ADVERSARIAL CHECK
|
| 1034 |
|
|
|
|
|
|
|
|
|
|
| 1035 |
HYPOTHESES:
|
| 1036 |
{hypotheses}
|
| 1037 |
|
|
@@ -1041,6 +1050,7 @@ NEW EVIDENCE (Adversarial Data):
|
|
| 1041 |
TASK:
|
| 1042 |
Actively try to DISPROVE each hypothesis using the new evidence (SAR, Soil, Pests).
|
| 1043 |
If evidence contradicts a hypothesis, mark it as INVALID.
|
|
|
|
| 1044 |
|
| 1045 |
OUTPUT JSON ONLY:
|
| 1046 |
{{
|
|
@@ -1056,6 +1066,9 @@ OUTPUT JSON ONLY:
|
|
| 1056 |
DEEP_DIVE_JUDGE_PROMPT = """You are Agrow-AI.
|
| 1057 |
STAGE C: FINAL VERDICT
|
| 1058 |
|
|
|
|
|
|
|
|
|
|
| 1059 |
WINNING HYPOTHESIS:
|
| 1060 |
{hypothesis}
|
| 1061 |
|
|
@@ -1063,7 +1076,7 @@ CONSTRAINTS & HISTORY:
|
|
| 1063 |
{context}
|
| 1064 |
|
| 1065 |
TASK:
|
| 1066 |
-
Provide the final diagnostic report and a detailed action plan.
|
| 1067 |
Consider farmer constraints (budget, machinery) and historical trends.
|
| 1068 |
|
| 1069 |
OUTPUT JSON ONLY:
|
|
|
|
| 988 |
# =============================================================================
|
| 989 |
|
| 990 |
FAST_LANE_PROMPT = """You are Agrow-AI.
|
| 991 |
+
TASK: Answer the user's question and diagnose any crop issues based on the provided context.
|
| 992 |
PRIORITY: SPEED & ACCURACY.
|
| 993 |
|
| 994 |
+
USER QUESTION:
|
| 995 |
+
{query}
|
| 996 |
+
|
| 997 |
CONTEXT:
|
| 998 |
{context}
|
| 999 |
|
| 1000 |
INSTRUCTIONS:
|
| 1001 |
1. [Hypothesis]: Briefly state what the primary signals (NDVI, NDRE, etc.) suggest.
|
| 1002 |
2. [Check]: Verify if supporting data (Moisture, Weather) aligns or contradicts.
|
| 1003 |
+
3. [Diagnosis]: State the final conclusion that ANSWERS THE USER'S QUESTION.
|
| 1004 |
4. [Action]: One specific corrective action.
|
| 1005 |
|
| 1006 |
OUTPUT JSON ONLY:
|
|
|
|
| 1015 |
DEEP_DIVE_HYPOTHESIS_PROMPT = """You are Agrow-AI, conducting a DEEP DIVE diagnosis.
|
| 1016 |
STAGE A: HYPOTHESIS GENERATION
|
| 1017 |
|
| 1018 |
+
USER QUESTION:
|
| 1019 |
+
{query}
|
| 1020 |
+
|
| 1021 |
CONTEXT:
|
| 1022 |
{context}
|
| 1023 |
|
| 1024 |
TASK:
|
| 1025 |
+
Identify top 3 possible causes that could answer the user's question. Do not conclude yet.
|
| 1026 |
Think broadly (Nutrients, Pests, Water, Soil, Disease).
|
| 1027 |
|
| 1028 |
OUTPUT JSON ONLY:
|
|
|
|
| 1038 |
DEEP_DIVE_ADVERSARY_PROMPT = """You are Agrow-AI.
|
| 1039 |
STAGE B: ADVERSARIAL CHECK
|
| 1040 |
|
| 1041 |
+
USER QUESTION:
|
| 1042 |
+
{query}
|
| 1043 |
+
|
| 1044 |
HYPOTHESES:
|
| 1045 |
{hypotheses}
|
| 1046 |
|
|
|
|
| 1050 |
TASK:
|
| 1051 |
Actively try to DISPROVE each hypothesis using the new evidence (SAR, Soil, Pests).
|
| 1052 |
If evidence contradicts a hypothesis, mark it as INVALID.
|
| 1053 |
+
Remember to focus on answering the user's question.
|
| 1054 |
|
| 1055 |
OUTPUT JSON ONLY:
|
| 1056 |
{{
|
|
|
|
| 1066 |
DEEP_DIVE_JUDGE_PROMPT = """You are Agrow-AI.
|
| 1067 |
STAGE C: FINAL VERDICT
|
| 1068 |
|
| 1069 |
+
USER QUESTION:
|
| 1070 |
+
{query}
|
| 1071 |
+
|
| 1072 |
WINNING HYPOTHESIS:
|
| 1073 |
{hypothesis}
|
| 1074 |
|
|
|
|
| 1076 |
{context}
|
| 1077 |
|
| 1078 |
TASK:
|
| 1079 |
+
Provide the final diagnostic report and a detailed action plan that DIRECTLY ANSWERS the user's question.
|
| 1080 |
Consider farmer constraints (budget, machinery) and historical trends.
|
| 1081 |
|
| 1082 |
OUTPUT JSON ONLY:
|
reasoning_engine.py
CHANGED
|
@@ -148,7 +148,8 @@ class ReasoningEngine:
|
|
| 148 |
# Build ultra-compact context
|
| 149 |
compact_ctx = self.aggregator.build_ultra_compact_context(context)
|
| 150 |
|
| 151 |
-
|
|
|
|
| 152 |
full_prompt = f"{SYSTEM_PROMPT}\n\n{prompt}"
|
| 153 |
|
| 154 |
response = self.llm(full_prompt)
|
|
@@ -181,21 +182,21 @@ class ReasoningEngine:
|
|
| 181 |
"""Execute 3-Stage Deep Dive."""
|
| 182 |
logger.info("Executing DEEP DIVE (3-Call)...")
|
| 183 |
|
| 184 |
-
# 1. Hypothesis Generation
|
| 185 |
ctx_hyp = self.aggregator.build_deep_dive_context(context, "hypothesis")
|
| 186 |
-
resp_hyp = self.llm(f"{SYSTEM_PROMPT}\n{DEEP_DIVE_HYPOTHESIS_PROMPT.format(context=ctx_hyp)}")
|
| 187 |
out_hyp = self._parse_json_safe(resp_hyp, {"hypotheses": []})
|
| 188 |
|
| 189 |
-
# 2. Adversarial Check
|
| 190 |
ctx_adv = self.aggregator.build_deep_dive_context(context, "adversary")
|
| 191 |
hyp_str = json.dumps(out_hyp, indent=2)
|
| 192 |
-
resp_adv = self.llm(f"{SYSTEM_PROMPT}\n{DEEP_DIVE_ADVERSARY_PROMPT.format(hypotheses=hyp_str, context=ctx_adv)}")
|
| 193 |
out_adv = self._parse_json_safe(resp_adv, {"surviving_hypothesis": "Unknown"})
|
| 194 |
|
| 195 |
-
# 3. Final Verdict
|
| 196 |
ctx_judge = self.aggregator.build_deep_dive_context(context, "judge")
|
| 197 |
winner = out_adv.get("surviving_hypothesis", "Unknown")
|
| 198 |
-
resp_judge = self.llm(f"{SYSTEM_PROMPT}\n{DEEP_DIVE_JUDGE_PROMPT.format(hypothesis=winner, context=ctx_judge)}")
|
| 199 |
out_judge = self._parse_json_safe(resp_judge, {"final_diagnosis": winner, "action_plan": {}})
|
| 200 |
|
| 201 |
# Map to ReasoningResult
|
|
|
|
| 148 |
# Build ultra-compact context
|
| 149 |
compact_ctx = self.aggregator.build_ultra_compact_context(context)
|
| 150 |
|
| 151 |
+
# Include user query in prompt
|
| 152 |
+
prompt = FAST_LANE_PROMPT.format(query=query, context=compact_ctx)
|
| 153 |
full_prompt = f"{SYSTEM_PROMPT}\n\n{prompt}"
|
| 154 |
|
| 155 |
response = self.llm(full_prompt)
|
|
|
|
| 182 |
"""Execute 3-Stage Deep Dive."""
|
| 183 |
logger.info("Executing DEEP DIVE (3-Call)...")
|
| 184 |
|
| 185 |
+
# 1. Hypothesis Generation - Include query
|
| 186 |
ctx_hyp = self.aggregator.build_deep_dive_context(context, "hypothesis")
|
| 187 |
+
resp_hyp = self.llm(f"{SYSTEM_PROMPT}\n\nUSER QUERY: {query}\n\n{DEEP_DIVE_HYPOTHESIS_PROMPT.format(query=query, context=ctx_hyp)}")
|
| 188 |
out_hyp = self._parse_json_safe(resp_hyp, {"hypotheses": []})
|
| 189 |
|
| 190 |
+
# 2. Adversarial Check - Include query context
|
| 191 |
ctx_adv = self.aggregator.build_deep_dive_context(context, "adversary")
|
| 192 |
hyp_str = json.dumps(out_hyp, indent=2)
|
| 193 |
+
resp_adv = self.llm(f"{SYSTEM_PROMPT}\n\nUSER QUERY: {query}\n\n{DEEP_DIVE_ADVERSARY_PROMPT.format(query=query, hypotheses=hyp_str, context=ctx_adv)}")
|
| 194 |
out_adv = self._parse_json_safe(resp_adv, {"surviving_hypothesis": "Unknown"})
|
| 195 |
|
| 196 |
+
# 3. Final Verdict - Include query
|
| 197 |
ctx_judge = self.aggregator.build_deep_dive_context(context, "judge")
|
| 198 |
winner = out_adv.get("surviving_hypothesis", "Unknown")
|
| 199 |
+
resp_judge = self.llm(f"{SYSTEM_PROMPT}\n\nUSER QUERY: {query}\n\n{DEEP_DIVE_JUDGE_PROMPT.format(query=query, hypothesis=winner, context=ctx_judge)}")
|
| 200 |
out_judge = self._parse_json_safe(resp_judge, {"final_diagnosis": winner, "action_plan": {}})
|
| 201 |
|
| 202 |
# Map to ReasoningResult
|