Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit Β·
fee8487
1
Parent(s): 5813b86
backend
Browse files- agents/nexus_master.py +85 -26
- agents/prompts.py +83 -1
agents/nexus_master.py
CHANGED
|
@@ -124,9 +124,21 @@ async def nexus_initializer(state: NexusState) -> Dict[str, Any]:
|
|
| 124 |
|
| 125 |
greetings = ["hi", "hello", "hey", "nexus", "start"]
|
| 126 |
thanks = ["thanks", "thank you", "thx", "awesome", "great"]
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
# --- HITL: Approval Signal Detection (ISSUE #2 FIX: Stricter Word-Boundary Matching) ---
|
| 131 |
is_explicit_approve = state.get("action_approved", False)
|
| 132 |
is_text_approve = False
|
|
@@ -500,11 +512,12 @@ async def nexus_router(state: NexusState) -> Dict[str, Any]:
|
|
| 500 |
logger.info(f"[NEXUS_TRACE] node=router | output=CONVERSE_FALLBACK | duration={int((time.time()-t0)*1000)}ms")
|
| 501 |
return {"messages": [AIMessage(content="I'm ready to help! What would you like to explore within your workspace?")]}
|
| 502 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
if response.intent == "CONVERSE" and not response.tool_call:
|
| 504 |
logger.info(f"[NEXUS_TRACE] node=router | output=CONVERSE | duration={int((time.time()-t0)*1000)}ms")
|
| 505 |
-
if fallback_tool == "CONVERSE":
|
| 506 |
-
# If we hit the fast-track, we might want to flag it
|
| 507 |
-
logger.info("[NEXUS_TRACE] node=router | fast_track=HIT")
|
| 508 |
return {"current_tool_output": "CONVERSE"}
|
| 509 |
|
| 510 |
if response.tool_call:
|
|
@@ -764,11 +777,18 @@ async def nexus_executor(state: NexusState) -> Dict[str, Any]:
|
|
| 764 |
timed_tasks = [asyncio.wait_for(t, timeout=_TOOL_TIMEOUT) for t in tasks]
|
| 765 |
read_results = await asyncio.gather(*timed_tasks, return_exceptions=True)
|
| 766 |
tool_duration = time.time() - tool_t0
|
|
|
|
| 767 |
for cid, res in zip(c_ids, read_results):
|
| 768 |
-
|
| 769 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 770 |
tool_messages.append(ToolMessage(content=content, tool_call_id=cid))
|
| 771 |
-
logger.info(f"[NEXUS_TRACE] node=executor | output=TOOLS_COMPLETE | tools={[t[0] for t in task_calls]} | batch_duration={int(tool_duration*1000)}ms | total_duration={int((time.time()-t0)*1000)}ms")
|
| 772 |
combined_output = "\n".join([m.content for m in tool_messages if isinstance(m, ToolMessage) and "[ACTION_REQUIRED]" not in m.content])
|
| 773 |
|
| 774 |
# --- SEQUENTIAL FOLLOW-UP: inject next tool call using primary results as context ---
|
|
@@ -848,10 +868,44 @@ async def nexus_responder(state: NexusState) -> Dict[str, Any]:
|
|
| 848 |
}
|
| 849 |
|
| 850 |
# --- NATIVE PROMPT CONSTRUCTION ---
|
| 851 |
-
# We move away from manual .format() to native LangChain variable injection.
|
| 852 |
ai_gist = state.get("ai_gist", {})
|
| 853 |
ws_personality = state.get("workspace_personality", "Professional")
|
| 854 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 855 |
persona_context = f"\n\nWORKSPACE PERSONALITY: {ws_personality}\n"
|
| 856 |
if ai_gist:
|
| 857 |
persona_context += (
|
|
@@ -861,26 +915,24 @@ async def nexus_responder(state: NexusState) -> Dict[str, Any]:
|
|
| 861 |
f"- Behavioral Pattern: {ai_gist.get('behavioral_footprint', 'Solution-oriented')}"
|
| 862 |
)
|
| 863 |
|
| 864 |
-
# Note: '{' and '}' inside get_prompt strings are escaped at the registry level now ({{/}}),
|
| 865 |
-
# but we still use native ChatPromptTemplate to handle raw inputs safely.
|
| 866 |
base_prompt_str = get_prompt("responder")
|
| 867 |
full_system_template = f"{base_prompt_str}{{persona_context}}"
|
| 868 |
-
|
| 869 |
prompt = ChatPromptTemplate.from_messages([
|
| 870 |
-
("system", full_system_template),
|
| 871 |
MessagesPlaceholder(variable_name="messages")
|
| 872 |
])
|
| 873 |
-
|
| 874 |
history_for_llm = standardize_history(state["messages"][-10:])
|
| 875 |
input_vars = {
|
| 876 |
"messages": history_for_llm,
|
| 877 |
"user_name": state.get("user_name", "there"),
|
| 878 |
"user_role": state.get("user_role", "customer_user"),
|
| 879 |
"is_agent": state.get("is_agent", False),
|
| 880 |
-
"sources": ", ".join(set(state.get("sources", []))),
|
| 881 |
"ticket_context": state.get("ticket_context", "No active ticket context available."),
|
| 882 |
-
"tool_output":
|
| 883 |
-
"command_tolerance": 0.5,
|
| 884 |
"persona_context": persona_context
|
| 885 |
}
|
| 886 |
|
|
@@ -903,16 +955,16 @@ async def nexus_responder(state: NexusState) -> Dict[str, Any]:
|
|
| 903 |
await asyncio.wait_for(_stream_responder(), timeout=90.0)
|
| 904 |
except Exception as e:
|
| 905 |
logger.error(f"[NEXUS_TRACE] node=responder | output=EXCEPTION:{type(e).__name__} | partial_len={len(full_content)} | error={str(e)[:200]}")
|
| 906 |
-
if not full_content:
|
|
|
|
| 907 |
|
| 908 |
logger.info(f"[NEXUS_TRACE] node=responder | output=COMPLETE | response_len={len(full_content)} | duration={int((time.time()-t0)*1000)}ms")
|
| 909 |
|
| 910 |
-
_is_internal_sentinel = tool_out in ("NO_ACTION", "PROCEED", "CONVERSE", "GATEKEEPER_RESPONSE", "SAFETY_BLOCK", "ROUTED")
|
| 911 |
if not full_content.strip():
|
| 912 |
-
if
|
| 913 |
-
full_content = f"
|
| 914 |
else:
|
| 915 |
-
full_content = "I'm
|
| 916 |
|
| 917 |
# PROTOCOL STRIPPER: Defensive removal of any leaked internal protocol markers
|
| 918 |
full_content = re.sub(r'<function_calls>.*?</function_calls>', '', full_content, flags=re.DOTALL)
|
|
@@ -959,7 +1011,7 @@ async def get_nexus_app(is_agent: bool = False):
|
|
| 959 |
global _GRAPH_LOCK
|
| 960 |
if _GRAPH_LOCK is None:
|
| 961 |
_GRAPH_LOCK = asyncio.Lock()
|
| 962 |
-
cache_key = f"
|
| 963 |
async with _GRAPH_LOCK:
|
| 964 |
# Double-checked locking: re-check inside the lock to handle concurrent waiters
|
| 965 |
if cache_key in _GRAPH_CACHE:
|
|
@@ -985,7 +1037,14 @@ async def get_nexus_app(is_agent: bool = False):
|
|
| 985 |
{"end": END, "router": "router"}
|
| 986 |
)
|
| 987 |
|
| 988 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 989 |
|
| 990 |
# After executor: loop back to executor ONLY for fup_-prefixed follow-up tool calls.
|
| 991 |
# Using a broad "has tool_calls" check causes false loops β prior turns leave AIMessages
|
|
|
|
| 124 |
|
| 125 |
greetings = ["hi", "hello", "hey", "nexus", "start"]
|
| 126 |
thanks = ["thanks", "thank you", "thx", "awesome", "great"]
|
| 127 |
+
# Only treat as a pure greeting/thanks if the message is SHORT and doesn't contain
|
| 128 |
+
# workspace-intent words β prevents "hi, what happened to my ticket?" fast-pathing as a greeting
|
| 129 |
+
_has_workspace_intent = bool(re.search(
|
| 130 |
+
r"\b(ticket|issue|problem|incident|error|status|update|help|search|find|assign|close|open|create|report|analytic|summary|vpn|access|login|password|bug|fix|resolve|sla|workspace|analytics|kb|article|comment|note)\b",
|
| 131 |
+
q_lower, re.I
|
| 132 |
+
))
|
| 133 |
+
is_greeting = (
|
| 134 |
+
not _has_workspace_intent and
|
| 135 |
+
any(q_lower == g or q_lower.startswith(g + " ") for g in greetings)
|
| 136 |
+
)
|
| 137 |
+
is_thanks = (
|
| 138 |
+
not _has_workspace_intent and
|
| 139 |
+
any(q_lower == t or q_lower.startswith(t + " ") for t in thanks)
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
# --- HITL: Approval Signal Detection (ISSUE #2 FIX: Stricter Word-Boundary Matching) ---
|
| 143 |
is_explicit_approve = state.get("action_approved", False)
|
| 144 |
is_text_approve = False
|
|
|
|
| 512 |
logger.info(f"[NEXUS_TRACE] node=router | output=CONVERSE_FALLBACK | duration={int((time.time()-t0)*1000)}ms")
|
| 513 |
return {"messages": [AIMessage(content="I'm ready to help! What would you like to explore within your workspace?")]}
|
| 514 |
|
| 515 |
+
if response.intent == "CLARIFY" and not response.tool_call:
|
| 516 |
+
logger.info(f"[NEXUS_TRACE] node=router | output=CLARIFY | duration={int((time.time()-t0)*1000)}ms")
|
| 517 |
+
return {"current_tool_output": "CLARIFY"}
|
| 518 |
+
|
| 519 |
if response.intent == "CONVERSE" and not response.tool_call:
|
| 520 |
logger.info(f"[NEXUS_TRACE] node=router | output=CONVERSE | duration={int((time.time()-t0)*1000)}ms")
|
|
|
|
|
|
|
|
|
|
| 521 |
return {"current_tool_output": "CONVERSE"}
|
| 522 |
|
| 523 |
if response.tool_call:
|
|
|
|
| 777 |
timed_tasks = [asyncio.wait_for(t, timeout=_TOOL_TIMEOUT) for t in tasks]
|
| 778 |
read_results = await asyncio.gather(*timed_tasks, return_exceptions=True)
|
| 779 |
tool_duration = time.time() - tool_t0
|
| 780 |
+
all_errors = True
|
| 781 |
for cid, res in zip(c_ids, read_results):
|
| 782 |
+
if isinstance(res, Exception):
|
| 783 |
+
content = f"Error: {str(res)}"
|
| 784 |
+
logger.warning(f"[NEXUS_TRACE] node=executor/tool_result | call_id={cid} | error={str(res)[:120]}")
|
| 785 |
+
else:
|
| 786 |
+
content = str(res)
|
| 787 |
+
if content.strip() and content.strip() not in ("[]", "{}", "No tickets found.", "No results found."):
|
| 788 |
+
all_errors = False
|
| 789 |
+
logger.info(f"[NEXUS_TRACE] node=executor/tool_result | call_id={cid} | output_len={len(content)}")
|
| 790 |
tool_messages.append(ToolMessage(content=content, tool_call_id=cid))
|
| 791 |
+
logger.info(f"[NEXUS_TRACE] node=executor | output=TOOLS_COMPLETE | tools={[t[0] for t in task_calls]} | all_errors={all_errors} | batch_duration={int(tool_duration*1000)}ms | total_duration={int((time.time()-t0)*1000)}ms")
|
| 792 |
combined_output = "\n".join([m.content for m in tool_messages if isinstance(m, ToolMessage) and "[ACTION_REQUIRED]" not in m.content])
|
| 793 |
|
| 794 |
# --- SEQUENTIAL FOLLOW-UP: inject next tool call using primary results as context ---
|
|
|
|
| 868 |
}
|
| 869 |
|
| 870 |
# --- NATIVE PROMPT CONSTRUCTION ---
|
|
|
|
| 871 |
ai_gist = state.get("ai_gist", {})
|
| 872 |
ws_personality = state.get("workspace_personality", "Professional")
|
| 873 |
+
|
| 874 |
+
_SENTINELS = {"NO_ACTION", "PROCEED", "CONVERSE", "CLARIFY", "GATEKEEPER_RESPONSE", "SAFETY_BLOCK", "ROUTED"}
|
| 875 |
+
_is_sentinel = tool_out.strip() in _SENTINELS or not tool_out.strip()
|
| 876 |
+
_has_tool_error = tool_out.startswith("Error:") or "asyncio.TimeoutError" in tool_out or "timed out" in tool_out.lower()
|
| 877 |
+
_tool_returned_empty = (
|
| 878 |
+
_is_sentinel or
|
| 879 |
+
tool_out.strip() in ("[]", "{}", "No tickets found.", "No results found.", "No data available.")
|
| 880 |
+
)
|
| 881 |
+
|
| 882 |
+
# Build effective tool output for the LLM β never let it see a raw sentinel
|
| 883 |
+
if tool_out == "CLARIFY":
|
| 884 |
+
effective_tool_output = (
|
| 885 |
+
"[NO_DATA] The user's query was too vague to retrieve data. "
|
| 886 |
+
"Your job: ask ONE focused clarifying question to understand what they need. "
|
| 887 |
+
"Do NOT fabricate any data, tickets, incidents, or summaries."
|
| 888 |
+
)
|
| 889 |
+
elif tool_out == "CONVERSE":
|
| 890 |
+
effective_tool_output = (
|
| 891 |
+
"[CONVERSATIONAL] No tool was called. Respond naturally to the user's message. "
|
| 892 |
+
"If they seem to be asking about workspace data or a specific issue, "
|
| 893 |
+
"ask what they need rather than inventing an answer."
|
| 894 |
+
)
|
| 895 |
+
elif _has_tool_error:
|
| 896 |
+
effective_tool_output = (
|
| 897 |
+
f"[TOOL_ERROR] The system encountered an error retrieving data: {tool_out[:300]}\n"
|
| 898 |
+
"Acknowledge the issue briefly, then offer an alternative path forward."
|
| 899 |
+
)
|
| 900 |
+
elif _tool_returned_empty:
|
| 901 |
+
effective_tool_output = (
|
| 902 |
+
f"[NO_RESULTS] The tool returned no matching data.\n"
|
| 903 |
+
"Do NOT invent results. Acknowledge there's nothing found, then ask "
|
| 904 |
+
"a clarifying question (e.g., different search terms, ticket ID, date range)."
|
| 905 |
+
)
|
| 906 |
+
else:
|
| 907 |
+
effective_tool_output = tool_out
|
| 908 |
+
|
| 909 |
persona_context = f"\n\nWORKSPACE PERSONALITY: {ws_personality}\n"
|
| 910 |
if ai_gist:
|
| 911 |
persona_context += (
|
|
|
|
| 915 |
f"- Behavioral Pattern: {ai_gist.get('behavioral_footprint', 'Solution-oriented')}"
|
| 916 |
)
|
| 917 |
|
|
|
|
|
|
|
| 918 |
base_prompt_str = get_prompt("responder")
|
| 919 |
full_system_template = f"{base_prompt_str}{{persona_context}}"
|
| 920 |
+
|
| 921 |
prompt = ChatPromptTemplate.from_messages([
|
| 922 |
+
("system", full_system_template),
|
| 923 |
MessagesPlaceholder(variable_name="messages")
|
| 924 |
])
|
| 925 |
+
|
| 926 |
history_for_llm = standardize_history(state["messages"][-10:])
|
| 927 |
input_vars = {
|
| 928 |
"messages": history_for_llm,
|
| 929 |
"user_name": state.get("user_name", "there"),
|
| 930 |
"user_role": state.get("user_role", "customer_user"),
|
| 931 |
"is_agent": state.get("is_agent", False),
|
| 932 |
+
"sources": ", ".join(set(state.get("sources", []))),
|
| 933 |
"ticket_context": state.get("ticket_context", "No active ticket context available."),
|
| 934 |
+
"tool_output": effective_tool_output,
|
| 935 |
+
"command_tolerance": 0.5,
|
| 936 |
"persona_context": persona_context
|
| 937 |
}
|
| 938 |
|
|
|
|
| 955 |
await asyncio.wait_for(_stream_responder(), timeout=90.0)
|
| 956 |
except Exception as e:
|
| 957 |
logger.error(f"[NEXUS_TRACE] node=responder | output=EXCEPTION:{type(e).__name__} | partial_len={len(full_content)} | error={str(e)[:200]}")
|
| 958 |
+
if not full_content:
|
| 959 |
+
full_content = "I hit a temporary issue processing that request. Could you try again, or let me know if you'd like me to approach it differently?"
|
| 960 |
|
| 961 |
logger.info(f"[NEXUS_TRACE] node=responder | output=COMPLETE | response_len={len(full_content)} | duration={int((time.time()-t0)*1000)}ms")
|
| 962 |
|
|
|
|
| 963 |
if not full_content.strip():
|
| 964 |
+
if not _is_sentinel and not _tool_returned_empty and tool_out:
|
| 965 |
+
full_content = f"Here's what I found:\n\n{tool_out}"
|
| 966 |
else:
|
| 967 |
+
full_content = "I'm not sure I have enough context to answer that accurately. Could you tell me more β for example, which ticket or issue you're referring to?"
|
| 968 |
|
| 969 |
# PROTOCOL STRIPPER: Defensive removal of any leaked internal protocol markers
|
| 970 |
full_content = re.sub(r'<function_calls>.*?</function_calls>', '', full_content, flags=re.DOTALL)
|
|
|
|
| 1011 |
global _GRAPH_LOCK
|
| 1012 |
if _GRAPH_LOCK is None:
|
| 1013 |
_GRAPH_LOCK = asyncio.Lock()
|
| 1014 |
+
cache_key = f"nexus_v2_{is_agent}"
|
| 1015 |
async with _GRAPH_LOCK:
|
| 1016 |
# Double-checked locking: re-check inside the lock to handle concurrent waiters
|
| 1017 |
if cache_key in _GRAPH_CACHE:
|
|
|
|
| 1037 |
{"end": END, "router": "router"}
|
| 1038 |
)
|
| 1039 |
|
| 1040 |
+
# Router -> Executor (default) OR -> Responder directly (CONVERSE / CLARIFY β no tool needed)
|
| 1041 |
+
def _router_route(state: NexusState) -> str:
|
| 1042 |
+
out = state.get("current_tool_output", "")
|
| 1043 |
+
if out in ("CONVERSE", "CLARIFY"):
|
| 1044 |
+
return "responder"
|
| 1045 |
+
return "executor"
|
| 1046 |
+
|
| 1047 |
+
workflow.add_conditional_edges("router", _router_route, {"executor": "executor", "responder": "responder"})
|
| 1048 |
|
| 1049 |
# After executor: loop back to executor ONLY for fup_-prefixed follow-up tool calls.
|
| 1050 |
# Using a broad "has tool_calls" check causes false loops β prior turns leave AIMessages
|
agents/prompts.py
CHANGED
|
@@ -61,6 +61,7 @@ CORE TOOLSET & PRIORITY:
|
|
| 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.
|
| 63 |
13. CONVERSE: Use ONLY for pure greetings/acknowledgments ("hi", "thanks") OR queries that are 100% unrelated to the workspace (weather, sports scores, general trivia). CRITICAL: Vague workspace queries like "any updates?", "what's happening?", "give me a status", "latest updates", "retry", "try again" are IN-SCOPE β route them to the appropriate workspace tool, NOT CONVERSE. When in doubt, call a tool.
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
STRATEGIC DIRECTIVES:
|
|
@@ -97,6 +98,12 @@ User: "What's happening?"
|
|
| 97 |
User: "can you try again?" or "retry"
|
| 98 |
β {{"intent": "ANALYTICS", "tool_call": "SUMMARIZE_WORKSPACE", "tool_args": {{}}, "reasoning": "User asking to retry previous workspace query β default to workspace summary."}}
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
User: "What is today's weather?"
|
| 101 |
β {{"intent": "CONVERSE", "tool_call": null, "tool_args": null, "reasoning": "Out-of-scope question unrelated to the support workspace."}}
|
| 102 |
|
|
@@ -180,6 +187,80 @@ TOOL OUTPUT (PRIMARY SOURCE):
|
|
| 180 |
{tool_output}
|
| 181 |
"""
|
| 182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
MEMORY_DISTILLER_PROMPT_V1 = """
|
| 184 |
You are the Nexus Memory Distiller. Your job is to update the Long-Term Summary of a conversation.
|
| 185 |
|
|
@@ -241,6 +322,7 @@ PROMPTS = {
|
|
| 241 |
},
|
| 242 |
"responder": {
|
| 243 |
"v1": RESPONDER_SYSTEM_PROMPT_V1,
|
|
|
|
| 244 |
},
|
| 245 |
"memory_distiller": {
|
| 246 |
"v1": MEMORY_DISTILLER_PROMPT_V1,
|
|
@@ -256,7 +338,7 @@ PROMPTS = {
|
|
| 256 |
# Active version selection (change here to A/B test)
|
| 257 |
ACTIVE_VERSIONS = {
|
| 258 |
"router": "v2",
|
| 259 |
-
"responder": "
|
| 260 |
"memory_distiller": "v1",
|
| 261 |
"identity_architect": "v1",
|
| 262 |
"thread_summarizer": "v1",
|
|
|
|
| 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.
|
| 63 |
13. CONVERSE: Use ONLY for pure greetings/acknowledgments ("hi", "thanks") OR queries that are 100% unrelated to the workspace (weather, sports scores, general trivia). CRITICAL: Vague workspace queries like "any updates?", "what's happening?", "give me a status", "latest updates", "retry", "try again" are IN-SCOPE β route them to the appropriate workspace tool, NOT CONVERSE. When in doubt, call a tool.
|
| 64 |
+
14. CLARIFY: Use when the query is genuinely too ambiguous to route to any tool confidently β the agent will ask a focused clarifying question. Example: user says "what happened with that issue" with NO ticket context and NO prior conversation β CLARIFY. Use sparingly; prefer routing to a tool over asking. Only use CLARIFY when calling any tool would produce meaningless results.
|
| 65 |
|
| 66 |
|
| 67 |
STRATEGIC DIRECTIVES:
|
|
|
|
| 98 |
User: "can you try again?" or "retry"
|
| 99 |
β {{"intent": "ANALYTICS", "tool_call": "SUMMARIZE_WORKSPACE", "tool_args": {{}}, "reasoning": "User asking to retry previous workspace query β default to workspace summary."}}
|
| 100 |
|
| 101 |
+
User: "what happened?" (no ticket context, no prior conversation)
|
| 102 |
+
β {{"intent": "CLARIFY", "tool_call": null, "tool_args": null, "reasoning": "Query is too vague with no context β need to ask which incident or ticket they mean."}}
|
| 103 |
+
|
| 104 |
+
User: "what happened?" (ticket context IS present in state)
|
| 105 |
+
β {{"intent": "TICKETS", "tool_call": "GET_TICKET_DETAILS", "tool_args": {{"ticket_id": "<active_ticket_id>"}}, "reasoning": "Active ticket context available β user is asking about it."}}
|
| 106 |
+
|
| 107 |
User: "What is today's weather?"
|
| 108 |
β {{"intent": "CONVERSE", "tool_call": null, "tool_args": null, "reasoning": "Out-of-scope question unrelated to the support workspace."}}
|
| 109 |
|
|
|
|
| 187 |
{tool_output}
|
| 188 |
"""
|
| 189 |
|
| 190 |
+
RESPONDER_SYSTEM_PROMPT_V2 = """
|
| 191 |
+
You are Nexus, an expert AI assistant embedded in a support workspace. You are precise, proactive, and conversational β like a knowledgeable teammate, not a search engine.
|
| 192 |
+
|
| 193 |
+
User: {user_name} | Role: {user_role} | Staff: {is_agent}
|
| 194 |
+
|
| 195 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 196 |
+
RULE 1 β ZERO HALLUCINATION (HARDEST RULE, NEVER BREAK)
|
| 197 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 198 |
+
The TOOL OUTPUT below is your ONLY data source. You must not invent, assume, or extrapolate any facts.
|
| 199 |
+
|
| 200 |
+
- If TOOL OUTPUT is empty, a sentinel (CONVERSE, NO_ACTION, PROCEED, etc.), or contains an error β you have NO real data. Do NOT answer as if you do.
|
| 201 |
+
- NEVER fabricate: ticket IDs, incident IDs, dates, user names, statuses, counts, descriptions, or any structured content.
|
| 202 |
+
- NEVER produce "example" or "sample" data to illustrate a point.
|
| 203 |
+
- If a tool call returned an error or timed out β acknowledge it honestly, then pivot (see Rule 3).
|
| 204 |
+
|
| 205 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 206 |
+
RULE 2 β ASK, DON'T ASSUME (BE INTERACTIVE)
|
| 207 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 208 |
+
You are NOT a one-shot search engine. When you need more context, ASK β concisely and specifically.
|
| 209 |
+
|
| 210 |
+
Ask a follow-up question when:
|
| 211 |
+
- The query is ambiguous ("what happened?", "any updates?") and you have no tool data to anchor on
|
| 212 |
+
- Tool results returned nothing β ask the user to narrow down (ticket ID, date range, keyword)
|
| 213 |
+
- A write action needs clarification (which ticket? which user? what priority?)
|
| 214 |
+
- Multiple valid interpretations exist β list them and let the user pick
|
| 215 |
+
|
| 216 |
+
Good clarifying questions (natural, not robotic):
|
| 217 |
+
- "Which ticket or incident are you referring to?"
|
| 218 |
+
- "Are you looking at the last 7 days, or a specific period?"
|
| 219 |
+
- "Do you want me to search all tickets or just your own?"
|
| 220 |
+
- "Could you share the ticket ID or a few keywords about the issue?"
|
| 221 |
+
|
| 222 |
+
NEVER ask more than one question at a time. Pick the most important gap.
|
| 223 |
+
|
| 224 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 225 |
+
RULE 3 β SELF-HEAL WHEN TOOLS FAIL
|
| 226 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 227 |
+
If a tool returned an error or empty results:
|
| 228 |
+
1. Acknowledge it in one sentence ("I couldn't retrieve that data right now.")
|
| 229 |
+
2. Offer a concrete alternative ("Could you share the ticket ID directly?" / "Want me to search by keyword instead?")
|
| 230 |
+
3. Never go silent. Always end with a path forward.
|
| 231 |
+
|
| 232 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 233 |
+
RULE 4 β PROACTIVE INTELLIGENCE
|
| 234 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 235 |
+
When tool data IS available:
|
| 236 |
+
- Surface non-obvious insights (e.g., "3 of these tickets are approaching SLA breach")
|
| 237 |
+
- Suggest natural next steps ("Want me to assign it?" / "Should I draft a comment?")
|
| 238 |
+
- Don't just recite the raw data β synthesize it into a useful briefing
|
| 239 |
+
|
| 240 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 241 |
+
RULE 5 β FORMAT & TONE
|
| 242 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 243 |
+
- Tone: Knowledgeable partner β direct, warm, no corporate fluff
|
| 244 |
+
- No: "I apologize", "I will now process", "diligently working", "team is reviewing"
|
| 245 |
+
- No: Protocol markers like <function_calls>, [ACTION_REQUIRED]
|
| 246 |
+
- No: Internal file names (.md, .json) shown to customers
|
| 247 |
+
- Format: GitHub-Flavored Markdown. Tables for structured data. Code blocks for technical content.
|
| 248 |
+
- Mermaid diagrams: ONLY for aggregate visualisations (charts, timelines). NEVER for a single ticket. NEVER with invented data.
|
| 249 |
+
- Mermaid PIE: `pie title "T"` then `"Label" : Number` (no percentages)
|
| 250 |
+
- Mermaid XY: `xychart-beta` with quoted axis labels and numeric data arrays
|
| 251 |
+
- Length: Customers β 2-4 sentences max. Staff β technical depth ok, stay high-impact.
|
| 252 |
+
- Cite sources when relevant: [Sources: {sources}]
|
| 253 |
+
|
| 254 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 255 |
+
CONTEXT
|
| 256 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 257 |
+
Active ticket context:
|
| 258 |
+
{ticket_context}
|
| 259 |
+
|
| 260 |
+
TOOL OUTPUT β your PRIMARY and ONLY data source:
|
| 261 |
+
{tool_output}
|
| 262 |
+
"""
|
| 263 |
+
|
| 264 |
MEMORY_DISTILLER_PROMPT_V1 = """
|
| 265 |
You are the Nexus Memory Distiller. Your job is to update the Long-Term Summary of a conversation.
|
| 266 |
|
|
|
|
| 322 |
},
|
| 323 |
"responder": {
|
| 324 |
"v1": RESPONDER_SYSTEM_PROMPT_V1,
|
| 325 |
+
"v2": RESPONDER_SYSTEM_PROMPT_V2,
|
| 326 |
},
|
| 327 |
"memory_distiller": {
|
| 328 |
"v1": MEMORY_DISTILLER_PROMPT_V1,
|
|
|
|
| 338 |
# Active version selection (change here to A/B test)
|
| 339 |
ACTIVE_VERSIONS = {
|
| 340 |
"router": "v2",
|
| 341 |
+
"responder": "v2",
|
| 342 |
"memory_distiller": "v1",
|
| 343 |
"identity_architect": "v1",
|
| 344 |
"thread_summarizer": "v1",
|