CaffeinatedCoding commited on
Commit
c299edd
·
verified ·
1 Parent(s): edf1fb5

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. src/agent_v2.py +11 -1
  2. src/system_prompt.py +69 -2
src/agent_v2.py CHANGED
@@ -358,10 +358,20 @@ def run_query_v2(user_message: str, session_id: str) -> Dict[str, Any]:
358
  entities = extract_entities(user_message)
359
  augmented_message = augment_query(user_message, entities)
360
 
361
- # Pass 2
362
  search_queries = analysis.get("search_queries", [augmented_message])
363
  if not search_queries:
364
  search_queries = [augmented_message]
 
 
 
 
 
 
 
 
 
 
365
  if augmented_message not in search_queries:
366
  search_queries.append(augmented_message)
367
 
 
358
  entities = extract_entities(user_message)
359
  augmented_message = augment_query(user_message, entities)
360
 
361
+ # Pass 2 — build search queries from analysis + legal issues
362
  search_queries = analysis.get("search_queries", [augmented_message])
363
  if not search_queries:
364
  search_queries = [augmented_message]
365
+
366
+ # Add queries from issue spotter legal_issues
367
+ for issue in analysis.get("legal_issues", []):
368
+ statutes = issue.get("relevant_statutes", [])
369
+ specific = issue.get("specific_issue", "")
370
+ if specific:
371
+ issue_query = f"{specific} {' '.join(statutes[:2])}".strip()
372
+ if issue_query not in search_queries:
373
+ search_queries.append(issue_query)
374
+
375
  if augmented_message not in search_queries:
376
  search_queries.append(augmented_message)
377
 
src/system_prompt.py CHANGED
@@ -134,6 +134,35 @@ Tell them what to do TODAY not just eventually.""",
134
  5. What to watch out for
135
  Be specific. Cite sections and procedures. Give a real plan.""",
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  "explanation": """Explain the legal concept clearly.
138
  Start with plain language meaning.
139
  Then apply to this specific situation.
@@ -211,7 +240,7 @@ Output this exact structure:
211
  "tone": "panicked|analytical|aggressive|casual|defeated",
212
  "format_requested": "bullets|numbered|table|prose|none",
213
  "subject": "brief description of main legal subject",
214
- "action_needed": "question|reflection|partial_finding|advice|strategy|explanation|observation|reassurance",
215
  "urgency": "immediate|medium|low",
216
  "hypotheses": [
217
  {"claim": "legal hypothesis 1", "confidence": "high|medium|low", "evidence": ["evidence supporting this"]},
@@ -227,8 +256,21 @@ Output this exact structure:
227
  "timeline_events": ["event with approximate time if mentioned"]
228
  },
229
  "facts_missing": ["critical fact 1 that would change strategy", "critical fact 2"],
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  "stage": "intake|understanding|analysis|strategy|followup",
231
- "last_response_type": "question|reflection|partial_finding|advice|strategy|explanation|observation|reassurance|none",
232
  "updated_summary": "3-4 line compressed summary of ENTIRE conversation including this new message. Must capture all key facts, legal issues identified, and current stage.",
233
  "search_queries": ["specific legal question for FAISS search 1", "specific legal question 2", "specific legal question 3"],
234
  "should_interpret_context": true,
@@ -243,4 +285,29 @@ Rules:
243
  - updated_summary must be a complete brief of everything known so far
244
  - should_interpret_context: true if agent should reflect its understanding back to user (useful every 3-4 turns)
245
  - format_decision: choose the format that best fits what this specific response needs to communicate
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  - Output ONLY the JSON. No explanation. No preamble. No markdown fences."""
 
134
  5. What to watch out for
135
  Be specific. Cite sections and procedures. Give a real plan.""",
136
 
137
+ "strategy_synthesis": """User has triggered a full strategy synthesis.
138
+ Generate a complete structured legal strategy document using ALL facts established across the conversation.
139
+
140
+ ## Legal Strategy Summary
141
+
142
+ **Your Situation:** [2-3 sentence summary of all established facts from conversation history]
143
+
144
+ **Strongest Arguments In Your Favour:**
145
+ 1. [argument + supporting judgment or statute]
146
+ 2. [argument + supporting judgment or statute]
147
+ 3. [argument + supporting judgment or statute if applicable]
148
+
149
+ **Counterarguments You Will Face:**
150
+ 1. [counterargument + how to address it specifically]
151
+ 2. [counterargument + how to address it specifically]
152
+
153
+ **Recommended Next Steps:**
154
+ 1. [immediate action — do today]
155
+ 2. [legal filing if applicable — with realistic timeline]
156
+ 3. [evidence to gather — be specific]
157
+ 4. [follow-up actions]
158
+
159
+ **Relevant Statutes and Sections:** [list all applicable acts and specific sections]
160
+ **Approximate Timeline:** [realistic estimate for this type of matter in Indian courts]
161
+ **Weak Points To Address:** [honest assessment of gaps or vulnerabilities in the case]
162
+
163
+ This is the culmination of everything established in this conversation.
164
+ Pull ALL facts, hypotheses, and evidence from the case state.""",
165
+
166
  "explanation": """Explain the legal concept clearly.
167
  Start with plain language meaning.
168
  Then apply to this specific situation.
 
240
  "tone": "panicked|analytical|aggressive|casual|defeated",
241
  "format_requested": "bullets|numbered|table|prose|none",
242
  "subject": "brief description of main legal subject",
243
+ "action_needed": "question|reflection|partial_finding|advice|strategy|strategy_synthesis|explanation|observation|reassurance",
244
  "urgency": "immediate|medium|low",
245
  "hypotheses": [
246
  {"claim": "legal hypothesis 1", "confidence": "high|medium|low", "evidence": ["evidence supporting this"]},
 
256
  "timeline_events": ["event with approximate time if mentioned"]
257
  },
258
  "facts_missing": ["critical fact 1 that would change strategy", "critical fact 2"],
259
+ "legal_issues": [
260
+ {
261
+ "domain": "labour law|criminal law|property law|family law|consumer law|constitutional law|contract law|cyber law|tax law|other",
262
+ "specific_issue": "brief description of specific issue",
263
+ "relevant_statutes": ["Act Name Section Number"],
264
+ "confidence": "high|medium|low"
265
+ }
266
+ ],
267
+ "clarifying_question": {
268
+ "question": "the single most important question to ask if action_needed is question",
269
+ "why_needed": "one sentence explanation of why this fact changes the legal strategy",
270
+ "already_known": ["fact 1 already established", "fact 2 already established"]
271
+ },
272
  "stage": "intake|understanding|analysis|strategy|followup",
273
+ "last_response_type": "question|reflection|partial_finding|advice|strategy|strategy_synthesis|explanation|observation|reassurance|none",
274
  "updated_summary": "3-4 line compressed summary of ENTIRE conversation including this new message. Must capture all key facts, legal issues identified, and current stage.",
275
  "search_queries": ["specific legal question for FAISS search 1", "specific legal question 2", "specific legal question 3"],
276
  "should_interpret_context": true,
 
285
  - updated_summary must be a complete brief of everything known so far
286
  - should_interpret_context: true if agent should reflect its understanding back to user (useful every 3-4 turns)
287
  - format_decision: choose the format that best fits what this specific response needs to communicate
288
+
289
+ ISSUE SPOTTER — critical rule:
290
+ legal_issues must extract ALL legal domains present in the facts, not just what the user explicitly mentioned.
291
+ Include issues the user may not know exist.
292
+ Example: User says "employer fired me after I reported safety violations" →
293
+ legal_issues should include: wrongful termination (Industrial Disputes Act 1947 Section 2ra), whistleblower protection (Factories Act), potential victimisation claim, and any applicable state labour laws.
294
+ Each identified legal_issue generates an additional specific search query in search_queries.
295
+ Always look for the non-obvious angle — the criminal complaint nobody thought of, the procedural protection that changes everything.
296
+
297
+ SOCRATIC CLARIFIER — critical rule:
298
+ When action_needed is "question":
299
+ - clarifying_question.question must be exactly ONE question — the single most important missing fact
300
+ - clarifying_question.why_needed must explain in one sentence why this specific fact changes the legal strategy
301
+ - clarifying_question.already_known must list facts already established so the question never repeats known information
302
+ - The question must be surgical: not "tell me more" but "Is this a government or private sector employer?"
303
+ - Never ask what is already captured in updated_summary or facts_extracted
304
+ - The question drives toward the most strategy-changing unknown fact
305
+
306
+ STRATEGY SYNTHESIS — trigger rule:
307
+ Set action_needed to "strategy_synthesis" when user message contains any of:
308
+ "summarise", "summary", "what should I do", "give me a plan", "next steps",
309
+ "strategy", "what do I do now", "give me advice", "what are my options",
310
+ "final advice", "wrap up", "conclude", "what have we established", "plan of action"
311
+ This triggers generation of the full structured strategy document using ALL accumulated case state.
312
+
313
  - Output ONLY the JSON. No explanation. No preamble. No markdown fences."""