azettl commited on
Commit
865d4d1
Β·
verified Β·
1 Parent(s): e2948fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +102 -107
app.py CHANGED
@@ -832,107 +832,85 @@ class VisualConsensusEngine:
832
  return f"Error extracting OpenFloor research result: {str(e)}"
833
 
834
  def show_research_starting(self, function: str, query: str):
835
- """Show research request initiation with enhanced messaging"""
836
- session = get_or_create_session_state(self.session_id)
837
- current_state = session["roundtable_state"]
838
- all_messages = list(current_state.get("messages", []))
839
- participants = current_state.get("participants", [])
840
-
841
- existing_bubbles = list(current_state.get("showBubbles", []))
842
- # Ensure both Research Agent AND the calling model stay visible
843
- if "Research Agent" not in existing_bubbles:
844
- existing_bubbles.append("Research Agent")
845
- # Keep the current speaker (the one who requested research) visible
846
- current_speaker = current_state.get("currentSpeaker")
847
- if current_speaker and current_speaker not in existing_bubbles and current_speaker != "Research Agent":
848
- existing_bubbles.append(current_speaker)
849
-
850
- # Enhanced messages based on function type
851
- function_descriptions = {
852
- "search_web": "🌐 Web Search - Real-time information",
853
- "search_wikipedia": "πŸ“š Wikipedia - Authoritative encyclopedia",
854
- "search_academic": "πŸŽ“ Academic Research - Peer-reviewed papers",
855
- "search_technology_trends": "πŸ’» Technology Trends - GitHub analysis",
856
- "search_financial_data": "πŸ’° Financial Data - SEC filings",
857
- "multi_source_research": "πŸ”¬ Deep Research - Multiple sources"
858
  }
859
 
860
- function_desc = function_descriptions.get(function, function.replace('_', ' ').title())
861
-
862
- estimated_time = self.estimate_research_time(function)
863
- message = {
864
- "speaker": "Research Agent",
865
- "text": f"πŸ” **Initiating Research**\n{function_desc}\nπŸ“ Query: \"{query}\"\n⏰ Estimated time: {estimated_time}\n⏳ Connecting to data sources...",
866
- "type": "research_starting"
867
- }
868
- all_messages.append(message)
869
-
870
- self.update_visual_state({
871
- "participants": participants,
872
- "messages": all_messages,
873
- "currentSpeaker": None,
874
- "thinking": [],
875
- "showBubbles": existing_bubbles + ["Research Agent"]
876
- })
877
- time.sleep(0.5)
 
 
 
 
 
 
 
 
 
 
 
 
878
 
879
  def show_research_complete(self, function: str, query: str, result_length: int, requesting_model_name: str = None):
880
- """Show research ACTUALLY completed with data quality indicators"""
881
- session = get_or_create_session_state(self.session_id)
882
- current_state = session["roundtable_state"]
883
- all_messages = list(current_state.get("messages", []))
884
- participants = current_state.get("participants", [])
885
-
886
- existing_bubbles = list(current_state.get("showBubbles", []))
887
- # Ensure both Research Agent AND the calling model stay visible
888
- if "Research Agent" not in existing_bubbles:
889
- existing_bubbles.append("Research Agent")
890
- # Keep the current speaker (the one who requested research) visible
891
- current_speaker = current_state.get("currentSpeaker")
892
- if current_speaker and current_speaker not in existing_bubbles and current_speaker != "Research Agent":
893
- existing_bubbles.append(current_speaker)
894
-
895
- # Determine data quality based on result length
896
- if result_length > 2000:
897
- quality_indicator = "πŸ“Š High-quality data (comprehensive)"
898
- quality_emoji = "🎯"
899
- elif result_length > 800:
900
- quality_indicator = "πŸ“ˆ Good data (substantial)"
901
- quality_emoji = "βœ…"
902
- elif result_length > 200:
903
- quality_indicator = "πŸ“‹ Moderate data (basic)"
904
- quality_emoji = "⚠️"
905
- else:
906
- quality_indicator = "πŸ“„ Limited data (minimal)"
907
- quality_emoji = "⚑"
908
-
909
- # Function-specific completion messages
910
- function_summaries = {
911
- "search_web": "Live web data retrieved",
912
- "search_wikipedia": "Encyclopedia articles found",
913
- "search_academic": "Academic papers analyzed",
914
- "search_technology_trends": "Tech trends mapped",
915
- "search_financial_data": "Financial reports accessed",
916
- "multi_source_research": "Multi-source synthesis complete"
917
- }
918
-
919
- function_summary = function_summaries.get(function, "Research complete")
920
-
921
- message = {
922
- "speaker": "Research Agent",
923
- "text": f"βœ… **Research Complete**\nπŸ”¬ {function.replace('_', ' ').title()}\nπŸ“ Query: \"{query}\"\n{quality_emoji} {function_summary}\n{quality_indicator}\nπŸ“Š {result_length:,} characters analyzed\n🎯 Data ready for expert analysis",
924
- "type": "research_complete"
925
  }
926
- all_messages.append(message)
927
 
928
- self.update_visual_state({
929
- "participants": participants,
930
- "messages": all_messages,
931
- "currentSpeaker": requesting_model_name,
932
- "thinking": [],
933
- "showBubbles": existing_bubbles + ["Research Agent"]
934
- })
935
- time.sleep(1.5) # Longer pause to show the detailed completion
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
936
 
937
  def estimate_research_time(self, function_name: str) -> str:
938
  """Provide time estimates for different research functions"""
@@ -978,34 +956,51 @@ class VisualConsensusEngine:
978
  })
979
  time.sleep(1)
980
 
981
- def update_research_progress(self, progress_text: str):
982
- """Update research progress in real-time - ALWAYS REMOVE RESEARCH AGENT FROM THINKING"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
983
  session = get_or_create_session_state(self.session_id)
984
  current_state = session["roundtable_state"]
985
  all_messages = list(current_state.get("messages", []))
986
  participants = current_state.get("participants", [])
987
 
 
988
  existing_bubbles = list(current_state.get("showBubbles", []))
989
- if "Research Agent" not in existing_bubbles:
990
- existing_bubbles.append("Research Agent")
991
 
 
992
  progress_message = {
993
- "speaker": "Research Agent",
994
  "text": f"πŸ”„ {progress_text}",
995
  "type": "research_progress"
996
  }
997
  all_messages.append(progress_message)
998
 
999
- # Get current thinking and ALWAYS remove Research Agent
1000
- current_thinking = list(current_state.get("thinking", []))
1001
- if "Research Agent" in current_thinking:
1002
- current_thinking.remove("Research Agent")
1003
-
1004
  self.update_visual_state({
1005
  "participants": participants,
1006
  "messages": all_messages,
1007
- "currentSpeaker": None,
1008
- "thinking": current_thinking, # Research Agent NEVER in thinking
1009
  "showBubbles": existing_bubbles
1010
  })
1011
  time.sleep(0.3)
 
832
  return f"Error extracting OpenFloor research result: {str(e)}"
833
 
834
  def show_research_starting(self, function: str, query: str):
835
+ """Invite specific research agent to join conversation"""
836
+ function_to_agent = {
837
+ "search_web": "web_search",
838
+ "search_wikipedia": "wikipedia",
839
+ "search_academic": "arxiv",
840
+ "search_technology_trends": "github",
841
+ "search_financial_data": "sec_edgar"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
842
  }
843
 
844
+ if function in function_to_agent:
845
+ agent_name = function_to_agent[function]
846
+ # Use the existing invite method
847
+ self.invite_research_agent(agent_name, "current_conversation", "AI Expert")
848
+
849
+ # Add the query information
850
+ research_agent = self.research_agents[agent_name]
851
+ agent_display_name = research_agent.manifest.identification.conversationalName
852
+
853
+ session = get_or_create_session_state(self.session_id)
854
+ current_state = session["roundtable_state"]
855
+ all_messages = list(current_state.get("messages", []))
856
+
857
+ # Add research starting message
858
+ start_message = {
859
+ "speaker": agent_display_name,
860
+ "text": f"πŸ” **Starting Research**\nπŸ“ Query: \"{query}\"\n⏳ Connecting to data sources...",
861
+ "type": "research_starting"
862
+ }
863
+ all_messages.append(start_message)
864
+
865
+ existing_bubbles = list(current_state.get("showBubbles", []))
866
+ self.update_visual_state({
867
+ "participants": current_state.get("participants", []),
868
+ "messages": all_messages,
869
+ "currentSpeaker": agent_display_name,
870
+ "thinking": [],
871
+ "showBubbles": existing_bubbles
872
+ })
873
+
874
 
875
  def show_research_complete(self, function: str, query: str, result_length: int, requesting_model_name: str = None):
876
+ """Show research complete and dismiss the specific agent"""
877
+ function_to_agent = {
878
+ "search_web": "web_search",
879
+ "search_wikipedia": "wikipedia",
880
+ "search_academic": "arxiv",
881
+ "search_technology_trends": "github",
882
+ "search_financial_data": "sec_edgar"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
883
  }
 
884
 
885
+ if function in function_to_agent:
886
+ agent_name = function_to_agent[function]
887
+ research_agent = self.research_agents[agent_name]
888
+ agent_display_name = research_agent.manifest.identification.conversationalName
889
+
890
+ session = get_or_create_session_state(self.session_id)
891
+ current_state = session["roundtable_state"]
892
+ all_messages = list(current_state.get("messages", []))
893
+
894
+ # Show completion message
895
+ complete_message = {
896
+ "speaker": agent_display_name,
897
+ "text": f"βœ… **Research Complete**\nπŸ“Š {result_length:,} characters analyzed\n🎯 Research delivered to {requesting_model_name}",
898
+ "type": "research_complete"
899
+ }
900
+ all_messages.append(complete_message)
901
+
902
+ existing_bubbles = list(current_state.get("showBubbles", []))
903
+ self.update_visual_state({
904
+ "participants": current_state.get("participants", []),
905
+ "messages": all_messages,
906
+ "currentSpeaker": requesting_model_name,
907
+ "thinking": [],
908
+ "showBubbles": existing_bubbles
909
+ })
910
+ time.sleep(2)
911
+
912
+ # Use the existing dismiss method
913
+ self.dismiss_research_agent(agent_name, "current_conversation")
914
 
915
  def estimate_research_time(self, function_name: str) -> str:
916
  """Provide time estimates for different research functions"""
 
956
  })
957
  time.sleep(1)
958
 
959
+ def update_research_progress(self, progress_text: str, function_name: str = None):
960
+ """Update research progress from the specific active research agent"""
961
+
962
+ # Map function to agent to identify which agent is providing progress
963
+ function_to_agent = {
964
+ "search_web": "web_search",
965
+ "search_wikipedia": "wikipedia",
966
+ "search_academic": "arxiv",
967
+ "search_technology_trends": "github",
968
+ "search_financial_data": "sec_edgar"
969
+ }
970
+
971
+ # Determine which research agent is active
972
+ if function_name and function_name in function_to_agent:
973
+ agent_name = function_to_agent[function_name]
974
+ research_agent = self.research_agents[agent_name]
975
+ agent_display_name = research_agent.manifest.identification.conversationalName
976
+ else:
977
+ # Fallback to generic research agent if function not specified
978
+ agent_display_name = "Research Agent"
979
+
980
  session = get_or_create_session_state(self.session_id)
981
  current_state = session["roundtable_state"]
982
  all_messages = list(current_state.get("messages", []))
983
  participants = current_state.get("participants", [])
984
 
985
+ # Ensure the specific research agent is visible
986
  existing_bubbles = list(current_state.get("showBubbles", []))
987
+ if agent_display_name not in existing_bubbles:
988
+ existing_bubbles.append(agent_display_name)
989
 
990
+ # Add progress message from the specific agent
991
  progress_message = {
992
+ "speaker": agent_display_name,
993
  "text": f"πŸ”„ {progress_text}",
994
  "type": "research_progress"
995
  }
996
  all_messages.append(progress_message)
997
 
998
+ # Keep the agent active and visible during progress
 
 
 
 
999
  self.update_visual_state({
1000
  "participants": participants,
1001
  "messages": all_messages,
1002
+ "currentSpeaker": agent_display_name,
1003
+ "thinking": [],
1004
  "showBubbles": existing_bubbles
1005
  })
1006
  time.sleep(0.3)