Spaces:
Paused

dushyantsingh0 commited on
Commit
e31f3f6
·
1 Parent(s): 2f22ffb

perf: implement single-turn graph fusion for conversational queries

Browse files
agents/analytics.py CHANGED
@@ -57,7 +57,7 @@ async def generate_service_insights(metrics: Dict[str, Any], tickets: List[Dict[
57
  # 3-Attempt Retry Logic for Stability
58
  for attempt in range(1, 4):
59
  try:
60
- llm = get_llm(timeout=120) # Elevated timeout
61
 
62
  prompt = ChatPromptTemplate.from_template(ANALYTICS_PROMPT)
63
  chain = prompt | llm
 
57
  # 3-Attempt Retry Logic for Stability
58
  for attempt in range(1, 4):
59
  try:
60
+ llm = get_llm(timeout=300) # Maximum safe-side timeout for complex narratives
61
 
62
  prompt = ChatPromptTemplate.from_template(ANALYTICS_PROMPT)
63
  chain = prompt | llm
agents/nexus_master.py CHANGED
@@ -825,13 +825,24 @@ def create_nexus_graph(is_agent: bool = True):
825
 
826
  def route_after_router(state: NexusState) -> str:
827
  last_msg = state["messages"][-1]
 
 
828
  if hasattr(last_msg, "tool_calls") and last_msg.tool_calls:
829
  return "executor"
 
 
 
 
 
 
 
 
830
  return "responder"
831
 
832
  workflow.add_conditional_edges("router", route_after_router, {
833
  "executor": "executor",
834
- "responder": "responder"
 
835
  })
836
 
837
  def check_approval(state: NexusState) -> str:
 
825
 
826
  def route_after_router(state: NexusState) -> str:
827
  last_msg = state["messages"][-1]
828
+
829
+ # 1. Complex Intent -> Tool Execution
830
  if hasattr(last_msg, "tool_calls") and last_msg.tool_calls:
831
  return "executor"
832
+
833
+ # 2. Conversational Intent -> Single-Turn Fusion (Skip Responder)
834
+ # If the Router already generated text content, we advance straight to cleanup
835
+ if last_msg.content and len(last_msg.content.strip()) > 1:
836
+ logger.info("⚡ [Nexus Master] Single-Turn Fusion triggered. Skipping Responder node.")
837
+ return "pruner"
838
+
839
+ # 3. Fallback -> Responder
840
  return "responder"
841
 
842
  workflow.add_conditional_edges("router", route_after_router, {
843
  "executor": "executor",
844
+ "responder": "responder",
845
+ "pruner": "pruner"
846
  })
847
 
848
  def check_approval(state: NexusState) -> str:
agents/prompts.py CHANGED
@@ -69,6 +69,7 @@ TICKET_DATA (AUTOMATICALLY LOADED):
69
  RESPONSE FORMAT:
70
  - To call a tool: Use the JSON tool-calling syntax.
71
  - For conversation: Respond with a direct, concise message.
 
72
  - NEVER mix a tool name (e.g. SUMMARIZE_WORKSPACE) directly into a text response.
73
  """
74
 
 
69
  RESPONSE FORMAT:
70
  - To call a tool: Use the JSON tool-calling syntax.
71
  - For conversation: Respond with a direct, concise message.
72
+ - **SINGLE-TURN FUSION (LATENCY)**: If the user query is conversational (greeting, appreciation, question about your identity, or request for information you ALREADY possess), fulfill the request DIRECTLY in your text response. Do NOT call a tool.
73
  - NEVER mix a tool name (e.g. SUMMARIZE_WORKSPACE) directly into a text response.
74
  """
75
 
api/v1/dashboard.py CHANGED
@@ -403,7 +403,7 @@ async def get_ai_insights(
403
  queue = await list_tickets(limit=5, current_user=current_user, db=db)
404
 
405
  # Prepare Prompt with strict timeout for UI responsiveness
406
- llm = get_llm(timeout=45)
407
  prompt = ChatPromptTemplate.from_template("""
408
  You are the Nexus Workspace Intelligence Engine.
409
  Analyze the following workspace operational data and provide a high-fidelity summary.
 
403
  queue = await list_tickets(limit=5, current_user=current_user, db=db)
404
 
405
  # Prepare Prompt with strict timeout for UI responsiveness
406
+ llm = get_llm(timeout=120)
407
  prompt = ChatPromptTemplate.from_template("""
408
  You are the Nexus Workspace Intelligence Engine.
409
  Analyze the following workspace operational data and provide a high-fidelity summary.
core/config.py CHANGED
@@ -96,8 +96,8 @@ class Settings(BaseSettings):
96
  # AI Settings (100% Ollama-Only Transition)
97
  AI_PROVIDER: str = "ollama"
98
  # AI_MODEL: str = "kimi-k2.5:cloud"
99
- AI_MODEL: str = "gemma3:27b-cloud"
100
- AI_FAST_MODEL: str = "minimax-m2:cloud"
101
 
102
  # AI Providers (Hybrid Switch)
103
  AI_IMAGE_PROVIDER: str = "local"
 
96
  # AI Settings (100% Ollama-Only Transition)
97
  AI_PROVIDER: str = "ollama"
98
  # AI_MODEL: str = "kimi-k2.5:cloud"
99
+ AI_MODEL: str = "minimax-m2:cloud"
100
+ AI_FAST_MODEL: str = "gemma3:27b-cloud"
101
 
102
  # AI Providers (Hybrid Switch)
103
  AI_IMAGE_PROVIDER: str = "local"
core/llm.py CHANGED
@@ -31,12 +31,12 @@ def get_llm(provider: str = None, model: str = None, use_fast_model: bool = Fals
31
  model = model or settings.AI_MODEL
32
  base_url = settings.OLLAMA_BASE_URL
33
 
34
- # Default increased to 90s to handle cold-boots and complex gists
35
- timeout = kwargs.get("timeout", 90)
36
 
37
- # Force 3-minute window for background analytical tasks identified via flags
38
  if kwargs.get("is_heavy_task"):
39
- timeout = 180
40
 
41
  # Create cache key based on configuration
42
  cache_key = (model, base_url, timeout, str(sorted(kwargs.items())))
 
31
  model = model or settings.AI_MODEL
32
  base_url = settings.OLLAMA_BASE_URL
33
 
34
+ # Default increased to 120s to handle cold-boots and complex gists
35
+ timeout = kwargs.get("timeout", 120)
36
 
37
+ # Force 5-minute window for background analytical tasks identified via flags
38
  if kwargs.get("is_heavy_task"):
39
+ timeout = 300
40
 
41
  # Create cache key based on configuration
42
  cache_key = (model, base_url, timeout, str(sorted(kwargs.items())))
core/tasks.py CHANGED
@@ -1584,7 +1584,7 @@ async def generate_workspace_insights(ctx, workspace_id: str, **kwargs):
1584
  queue = await get_agent_queue(workspace_id, current_user=system_user, db=db)
1585
 
1586
  # 3. Invoke LLM
1587
- llm = get_llm(timeout=45) # Longer timeout in background is OK
1588
  prompt = ChatPromptTemplate.from_template("""
1589
  You are the Nexus Workspace Intelligence Engine.
1590
  Analyze the following workspace operational data and provide:
 
1584
  queue = await get_agent_queue(workspace_id, current_user=system_user, db=db)
1585
 
1586
  # 3. Invoke LLM
1587
+ llm = get_llm(timeout=120) # Safe side timeout for background processing
1588
  prompt = ChatPromptTemplate.from_template("""
1589
  You are the Nexus Workspace Intelligence Engine.
1590
  Analyze the following workspace operational data and provide: