avinash-rai commited on
Commit
667605e
·
1 Parent(s): 0524945

fix(guvi): Resolve Handshake Loop - Strict Schema (Data vs Reply) & Data Population

Browse files
app/agents/orchestrator.py CHANGED
@@ -202,6 +202,7 @@ class HoneypotOrchestrator:
202
  scammer_behavior = None
203
  escalation_rec = {}
204
  is_fast_path = False
 
205
 
206
  # [SCORING] Role-based logic: If sender is 'user', treat as non-scam or testing turn
207
  if sender_role == "user":
 
202
  scammer_behavior = None
203
  escalation_rec = {}
204
  is_fast_path = False
205
+ is_scammer_repeating = False # [BUG FIX] Initialize early for Fast Path safety
206
 
207
  # [SCORING] Role-based logic: If sender is 'user', treat as non-scam or testing turn
208
  if sender_role == "user":
app/config.py CHANGED
@@ -47,12 +47,13 @@ class Settings(BaseSettings):
47
  GROQ_MODEL: str = "llama-3.3-70b-versatile"
48
 
49
  # Per-task model routing (Production Grade)
50
- GROQ_FAST_MODEL: str = "meta-llama/llama-4-scout-17b-16e-instruct" # 10M Context ✅, 30K TPM
51
- GROQ_SMART_MODEL: str = "llama-3.3-70b-versatile" # High RPM Reasoning, JSON Schema ✅
52
- GROQ_NATURAL_MODEL: str = "meta-llama/llama-4-scout-17b-16e-instruct" # 10M Context ✅
53
- GROQ_STRUCTURED_MODEL: str = "llama-3.3-70b-versatile" # Official JSON Schema Support
54
- GROQ_SAFETY_MODEL: str = "meta-llama/llama-guard-4-12b" # 14.4K RPD, Production
55
- GROQ_SAFEGUARD_MODEL: str = "openai/gpt-oss-safeguard-20b" # Cache ✅, Policy-safe
 
56
 
57
  OPENROUTER_MODEL: str = "meta-llama/llama-3.1-70b-instruct"
58
 
 
47
  GROQ_MODEL: str = "llama-3.3-70b-versatile"
48
 
49
  # Per-task model routing (Production Grade)
50
+ # Per-task model routing (Production Grade)
51
+ GROQ_FAST_MODEL: str = "llama3-8b-8192" # Blazing fast (~300 tokens/sec)
52
+ GROQ_SMART_MODEL: str = "llama3-70b-8192" # Balanced reasoning
53
+ GROQ_NATURAL_MODEL: str = "llama3-8b-8192"
54
+ GROQ_STRUCTURED_MODEL: str = "llama3-70b-8192" # Reliable JSON
55
+ GROQ_SAFETY_MODEL: str = "llama-guard-3-8b"
56
+ GROQ_SAFEGUARD_MODEL: str = "llama-guard-3-8b"
57
 
58
  OPENROUTER_MODEL: str = "meta-llama/llama-3.1-70b-instruct"
59
 
app/utils/guvi_handler.py CHANGED
@@ -183,15 +183,34 @@ class GUVIHandler:
183
  is_finalizing_turn = (db_history_len + 2) >= 2
184
 
185
  logger.debug("🔥 Orchestrator reached") # [DEBUG] Verify flow
186
- result = await orchestrator.process_message(
187
- message=scammer_text,
188
- sender_id=sender, # [SCORING] Align with forensic audit recommendation
189
- sender_role=sender, # [BUG FIX] Restore role for fail-safe engagement
190
- conversation_id=session_id,
191
- auto_report=True,
192
- client_ip=client_ip,
193
- should_finalize=is_finalizing_turn # [RESTORED] Critical for callback trigger
194
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
  # [SCORING] Accurate message counting (Forensic Fix)
197
  # Orchestrator returns 'message_count', history list is not guaranteed in result
@@ -384,8 +403,8 @@ class GUVIHandler:
384
  bankAccounts=[], upiIds=[], phishingLinks=[], phoneNumbers=[], suspiciousKeywords=[]
385
  ),
386
  agentNotes=f"System Failover Triggered: {safe_error}",
387
- reply="System under high load. Please retry.",
388
- honeypotResponse="System under high load."
389
  )
390
 
391
 
 
183
  is_finalizing_turn = (db_history_len + 2) >= 2
184
 
185
  logger.debug("🔥 Orchestrator reached") # [DEBUG] Verify flow
186
+ try:
187
+ # [LATENCY] Strict 25s Timeout to satisfy GUVI's 30s limit
188
+ # If LLM hangs, we abort and return fallback immediately
189
+ result = await asyncio.wait_for(
190
+ orchestrator.process_message(
191
+ message=scammer_text,
192
+ sender_id=sender, # [SCORING] Align with forensic audit recommendation
193
+ sender_role=sender, # [BUG FIX] Restore role for fail-safe engagement
194
+ conversation_id=session_id,
195
+ auto_report=True,
196
+ client_ip=client_ip,
197
+ should_finalize=is_finalizing_turn # [RESTORED] Critical for callback trigger
198
+ ),
199
+ timeout=25.0
200
+ )
201
+ except asyncio.TimeoutError:
202
+ logger.error(f"⏱️ DATA TIMEOUT ({session_id}): Orchestrator took >25s. Forcing fallback.")
203
+ # Construct a minimal valid 'result' to allow fall-through to standard response builder
204
+ result = {
205
+ "status": "partial_success",
206
+ "is_scam": False, # Fail open (continue)
207
+ "threat_level": "MEDIUM",
208
+ "honeypot_response": {"message": "Hello? Thoda network slow hai mera.", "persona": "fallback"},
209
+ "conversation": {"message_count": db_history_len + 1},
210
+ "aggregated_intelligence": conv.get("aggregated_intelligence", {}),
211
+ "confidence": 0.0,
212
+ "agent_notes": "Latency Timeout - Fallback Triggered"
213
+ }
214
 
215
  # [SCORING] Accurate message counting (Forensic Fix)
216
  # Orchestrator returns 'message_count', history list is not guaranteed in result
 
403
  bankAccounts=[], upiIds=[], phishingLinks=[], phoneNumbers=[], suspiciousKeywords=[]
404
  ),
405
  agentNotes=f"System Failover Triggered: {safe_error}",
406
+ reply="Hello? Awaaz nahi aa rahi... network issue lag raha hai.",
407
+ honeypotResponse="Hello? Awaaz nahi aa rahi... network issue lag raha hai."
408
  )
409
 
410