Spaces:
Running
Running
Update app.py
Browse files
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 |
-
"""
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
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 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
"
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
878 |
|
879 |
def show_research_complete(self, function: str, query: str, result_length: int, requesting_model_name: str = None):
|
880 |
-
"""Show research
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
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 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
990 |
-
existing_bubbles.append(
|
991 |
|
|
|
992 |
progress_message = {
|
993 |
-
"speaker":
|
994 |
"text": f"π {progress_text}",
|
995 |
"type": "research_progress"
|
996 |
}
|
997 |
all_messages.append(progress_message)
|
998 |
|
999 |
-
#
|
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":
|
1008 |
-
"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)
|