jdesiree commited on
Commit
df75c85
·
verified ·
1 Parent(s): b13216b

Update agents.py

Browse files
Files changed (1) hide show
  1. agents.py +73 -1
agents.py CHANGED
@@ -615,7 +615,79 @@ Design practice questions:"""
615
  except Exception as e:
616
  logger.error(f"Q&A Design error: {e}")
617
  return ""
618
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
619
  def general_reasoning(
620
  self,
621
  user_query: str,
 
615
  except Exception as e:
616
  logger.error(f"Q&A Design error: {e}")
617
  return ""
618
+
619
+ def process(
620
+ self,
621
+ user_input: str,
622
+ conversation_history: str = "",
623
+ thinking_prompts: str = "",
624
+ tool_img_output: str = "",
625
+ tool_context: str = ""
626
+ ) -> str:
627
+ """
628
+ Unified process method - runs thinking agents based on active prompts.
629
+
630
+ Args:
631
+ user_input: User's query
632
+ conversation_history: Formatted conversation history string
633
+ thinking_prompts: Newline-separated list of thinking prompts to activate
634
+ tool_img_output: HTML output from visualization tool
635
+ tool_context: Context from tool usage
636
+
637
+ Returns:
638
+ str: Combined thinking context from all activated agents
639
+ """
640
+ thinking_outputs = []
641
+
642
+ # Convert history string to list format for agent methods
643
+ history_list = []
644
+ if conversation_history and conversation_history != "No previous conversation":
645
+ for line in conversation_history.split('\n'):
646
+ if ':' in line:
647
+ role, content = line.split(':', 1)
648
+ history_list.append({'role': role.strip(), 'content': content.strip()})
649
+
650
+ # Determine which thinking agents to run based on prompts
651
+ prompt_list = [p.strip() for p in thinking_prompts.split('\n') if p.strip()]
652
+
653
+ # Math Thinking
654
+ if any('MATH' in p.upper() for p in prompt_list):
655
+ math_output = self.math_thinking(
656
+ user_query=user_input,
657
+ conversation_history=history_list,
658
+ tool_context=tool_context
659
+ )
660
+ if math_output:
661
+ thinking_outputs.append(f"[Mathematical Reasoning]\n{math_output}")
662
+
663
+ # Q&A Design Thinking
664
+ if any('PRACTICE' in p.upper() or 'QUESTION' in p.upper() for p in prompt_list):
665
+ qa_output = self.qa_design_thinking(
666
+ user_query=user_input,
667
+ conversation_history=history_list,
668
+ tool_context=tool_context
669
+ )
670
+ if qa_output:
671
+ thinking_outputs.append(f"[Practice Question Design]\n{qa_output}")
672
+
673
+ # General Reasoning (fallback or when no specific thinking needed)
674
+ if not thinking_outputs or any('REASONING' in p.upper() for p in prompt_list):
675
+ general_output = self.general_reasoning(
676
+ user_query=user_input,
677
+ conversation_history=history_list,
678
+ tool_context=tool_context
679
+ )
680
+ if general_output:
681
+ thinking_outputs.append(f"[General Reasoning]\n{general_output}")
682
+
683
+ # Combine all thinking outputs
684
+ combined_thinking = "\n\n".join(thinking_outputs) if thinking_outputs else ""
685
+
686
+ if combined_thinking:
687
+ logger.info(f"✓ Thinking complete: {len(combined_thinking)} chars from {len(thinking_outputs)} agents")
688
+
689
+ return combined_thinking
690
+
691
  def general_reasoning(
692
  self,
693
  user_query: str,