Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit Β·
9dfdacd
1
Parent(s): b5f1032
backend stabilisation
Browse files- agents/nexus_master.py +22 -3
- agents/prompts.py +8 -1
agents/nexus_master.py
CHANGED
|
@@ -276,7 +276,24 @@ async def nexus_initializer(state: NexusState) -> Dict[str, Any]:
|
|
| 276 |
await set_cached_object(cache_key, result, ttl=300)
|
| 277 |
return result
|
| 278 |
|
| 279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
if not fast_context:
|
| 281 |
logger.debug("π [Initializer] Hydrating full context (Identity + Memory)")
|
| 282 |
|
|
@@ -293,6 +310,8 @@ async def nexus_initializer(state: NexusState) -> Dict[str, Any]:
|
|
| 293 |
combined.setdefault("user_role", state.get("user_role") or "customer_user")
|
| 294 |
combined.setdefault("ai_gist", state.get("ai_gist") or {})
|
| 295 |
combined.setdefault("internal_summary", state.get("internal_summary") or "")
|
|
|
|
|
|
|
| 296 |
|
| 297 |
# --- HITL: Approval fast-path (identity always hydrated above) ---
|
| 298 |
if is_explicit_approve or is_text_approve:
|
|
@@ -465,8 +484,8 @@ async def nexus_router(state: NexusState) -> Dict[str, Any]:
|
|
| 465 |
# false positives like "who created" or "newly created" triggering CREATE_TICKET.
|
| 466 |
if re.search(r'\bcreate\b', q_lower) or any(k in q_lower for k in ["new ticket", "add ticket", "raise ticket", "open ticket for", "open a ticket"]):
|
| 467 |
fallback_tool = "CREATE_TICKET"
|
| 468 |
-
# Priority 2: Analytics/Dashboard
|
| 469 |
-
elif any(k in q_lower for k in ["
|
| 470 |
fallback_tool = "SUMMARIZE_WORKSPACE"
|
| 471 |
# Priority 3: Search/Retrieval ("previous"/"history" excluded β ambiguous; could mean recall or search)
|
| 472 |
elif any(k in q_lower for k in ["search", "find", "list", "show tickets", "look for"]):
|
|
|
|
| 276 |
await set_cached_object(cache_key, result, ttl=300)
|
| 277 |
return result
|
| 278 |
|
| 279 |
+
async def sync_ticket_context():
|
| 280 |
+
t_id = state.get("ticket_id")
|
| 281 |
+
if not t_id:
|
| 282 |
+
# Proactive extraction: if user mentions a ticket-like ID (e.g. B42B9701)
|
| 283 |
+
ticket_match = re.search(r'\b([A-Z0-9]{8})\b', last_msg)
|
| 284 |
+
if ticket_match:
|
| 285 |
+
from agents.tools.nexus_tools import resolve_ticket_id
|
| 286 |
+
async with async_session_factory() as db:
|
| 287 |
+
t_id = await resolve_ticket_id(db, ticket_match.group(1), ws_id)
|
| 288 |
+
|
| 289 |
+
if not t_id: return {"ticket_id": None, "ticket_context": ""}
|
| 290 |
+
|
| 291 |
+
async with async_session_factory() as db:
|
| 292 |
+
from agents.tools.nexus_tools import get_ticket_details_tool
|
| 293 |
+
context = await get_ticket_details_tool(str(t_id), ws_id, role=state.get("user_role", "customer_user"))
|
| 294 |
+
return {"ticket_id": t_id, "ticket_context": context}
|
| 295 |
+
|
| 296 |
+
tasks = [sync_identity(), sync_memory(), sync_ticket_context()]
|
| 297 |
if not fast_context:
|
| 298 |
logger.debug("π [Initializer] Hydrating full context (Identity + Memory)")
|
| 299 |
|
|
|
|
| 310 |
combined.setdefault("user_role", state.get("user_role") or "customer_user")
|
| 311 |
combined.setdefault("ai_gist", state.get("ai_gist") or {})
|
| 312 |
combined.setdefault("internal_summary", state.get("internal_summary") or "")
|
| 313 |
+
combined.setdefault("ticket_id", state.get("ticket_id"))
|
| 314 |
+
combined.setdefault("ticket_context", state.get("ticket_context") or "")
|
| 315 |
|
| 316 |
# --- HITL: Approval fast-path (identity always hydrated above) ---
|
| 317 |
if is_explicit_approve or is_text_approve:
|
|
|
|
| 484 |
# false positives like "who created" or "newly created" triggering CREATE_TICKET.
|
| 485 |
if re.search(r'\bcreate\b', q_lower) or any(k in q_lower for k in ["new ticket", "add ticket", "raise ticket", "open ticket for", "open a ticket"]):
|
| 486 |
fallback_tool = "CREATE_TICKET"
|
| 487 |
+
# Priority 2: Analytics/Dashboard/Workspace Health
|
| 488 |
+
elif any(k in q_lower for k in ["workspace summary", "system health", "health summary", "pulse check", "operational overview", "workspace health"]):
|
| 489 |
fallback_tool = "SUMMARIZE_WORKSPACE"
|
| 490 |
# Priority 3: Search/Retrieval ("previous"/"history" excluded β ambiguous; could mean recall or search)
|
| 491 |
elif any(k in q_lower for k in ["search", "find", "list", "show tickets", "look for"]):
|
agents/prompts.py
CHANGED
|
@@ -55,7 +55,8 @@ CORE TOOLSET & PRIORITY:
|
|
| 55 |
6. UPDATE_TICKET_ATTRIBUTES: STAFF ONLY: Modify priority, category, or internal assignment metadata.
|
| 56 |
7. ASSIGN_TICKET: STAFF ONLY: Assign/reassign a ticket to a specific agent UUID.
|
| 57 |
8. GET_ANALYTICS: Use for data visualization, trends, charts, or metrics.
|
| 58 |
-
9. SUMMARIZE_WORKSPACE: Use for
|
|
|
|
| 59 |
10. RECALL_KNOWLEDGE: Use for forensic memory recall, technical facts, user preferences, or "what happened before" queries.
|
| 60 |
11. GET_REMEDIATION_LOG: Use for "Security Audit" or "Audit Log" requests to see administrative activity.
|
| 61 |
12. SLA_AUDIT: Use for "SLA Forensics" to find breached or near-breach tickets.
|
|
@@ -71,6 +72,12 @@ FEW-SHOT EXAMPLES:
|
|
| 71 |
User: "I'm having trouble with my VPN login"
|
| 72 |
β {{"intent": "TICKETS", "tool_call": "CREATE_TICKET", "tool_args": {{"title": "VPN Login Issue", "description": "User reported problems logging into VPN."}}, "reasoning": "User is describing a problem that warrants a new support ticket."}}
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
User: "Mark ticket d7a5dd75 as acknowledged"
|
| 75 |
β {{"intent": "TICKETS", "tool_call": "CHANGE_TICKET_STATUS", "tool_args": {{"ticket_id": "d7a5dd75", "new_status": "IN_PROGRESS"}}, "reasoning": "User wants to acknowledge the ticket by moving status to IN_PROGRESS."}}
|
| 76 |
|
|
|
|
| 55 |
6. UPDATE_TICKET_ATTRIBUTES: STAFF ONLY: Modify priority, category, or internal assignment metadata.
|
| 56 |
7. ASSIGN_TICKET: STAFF ONLY: Assign/reassign a ticket to a specific agent UUID.
|
| 57 |
8. GET_ANALYTICS: Use for data visualization, trends, charts, or metrics.
|
| 58 |
+
9. SUMMARIZE_WORKSPACE: Use ONLY for workspace-level health, pulse check, or operational overview requests (e.g. "workspace health", "give me a pulse check", "system overview"). NEVER use this when the user mentions a specific ticket ID β that always means GET_TICKET_DETAILS.
|
| 59 |
+
10. GET_TICKET_DETAILS: Use when the user asks to summarize, explain, review, or get details about a SPECIFIC ticket by its ID (e.g. "summarise ticket B42B9701", "what's the status of ticket XYZ", "tell me about this ticket").
|
| 60 |
10. RECALL_KNOWLEDGE: Use for forensic memory recall, technical facts, user preferences, or "what happened before" queries.
|
| 61 |
11. GET_REMEDIATION_LOG: Use for "Security Audit" or "Audit Log" requests to see administrative activity.
|
| 62 |
12. SLA_AUDIT: Use for "SLA Forensics" to find breached or near-breach tickets.
|
|
|
|
| 72 |
User: "I'm having trouble with my VPN login"
|
| 73 |
β {{"intent": "TICKETS", "tool_call": "CREATE_TICKET", "tool_args": {{"title": "VPN Login Issue", "description": "User reported problems logging into VPN."}}, "reasoning": "User is describing a problem that warrants a new support ticket."}}
|
| 74 |
|
| 75 |
+
User: "Summarise ticket B42B9701"
|
| 76 |
+
β {{"intent": "TICKETS", "tool_call": "GET_TICKET_DETAILS", "tool_args": {{"ticket_id": "B42B9701"}}, "reasoning": "User wants details of a specific ticket β GET_TICKET_DETAILS, not SUMMARIZE_WORKSPACE."}}
|
| 77 |
+
|
| 78 |
+
User: "Give me a workspace health summary"
|
| 79 |
+
β {{"intent": "ANALYTICS", "tool_call": "SUMMARIZE_WORKSPACE", "tool_args": {{}}, "reasoning": "User wants a workspace-level health overview."}}
|
| 80 |
+
|
| 81 |
User: "Mark ticket d7a5dd75 as acknowledged"
|
| 82 |
β {{"intent": "TICKETS", "tool_call": "CHANGE_TICKET_STATUS", "tool_args": {{"ticket_id": "d7a5dd75", "new_status": "IN_PROGRESS"}}, "reasoning": "User wants to acknowledge the ticket by moving status to IN_PROGRESS."}}
|
| 83 |
|