Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -855,6 +855,93 @@ class VisualConsensusEngine:
|
|
855 |
})
|
856 |
time.sleep(0.3)
|
857 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
858 |
def call_model(self, model: str, prompt: str, context: str = "") -> Optional[str]:
|
859 |
"""Enhanced model calling with native function calling support"""
|
860 |
if not self.models[model]['available']:
|
|
|
855 |
})
|
856 |
time.sleep(0.3)
|
857 |
|
858 |
+
def invite_research_agent(self, agent_name: str, conversation_id: str, requesting_expert: str):
|
859 |
+
"""Invite a research agent to join the conversation visually"""
|
860 |
+
|
861 |
+
if agent_name in self.research_agents:
|
862 |
+
research_agent = self.research_agents[agent_name]
|
863 |
+
|
864 |
+
# Research agent joins the conversation
|
865 |
+
research_agent.join_conversation(conversation_id)
|
866 |
+
|
867 |
+
# Update visual state to show the research agent joining
|
868 |
+
session = get_or_create_session_state(self.session_id)
|
869 |
+
current_state = session["roundtable_state"]
|
870 |
+
|
871 |
+
# Add research agent to participants if not already there
|
872 |
+
participants = list(current_state.get("participants", []))
|
873 |
+
agent_display_name = research_agent.manifest.identification.conversationalName
|
874 |
+
|
875 |
+
if agent_display_name not in participants:
|
876 |
+
participants.append(agent_display_name)
|
877 |
+
|
878 |
+
# Show join message
|
879 |
+
all_messages = list(current_state.get("messages", []))
|
880 |
+
join_message = {
|
881 |
+
"speaker": agent_display_name,
|
882 |
+
"text": f"🔗 **Joined Conversation**\nInvited by: {requesting_expert}\nSpecialty: {research_agent.manifest.identification.synopsis}\nReady to provide research assistance.",
|
883 |
+
"type": "agent_join"
|
884 |
+
}
|
885 |
+
all_messages.append(join_message)
|
886 |
+
|
887 |
+
# Update visual state
|
888 |
+
existing_bubbles = list(current_state.get("showBubbles", []))
|
889 |
+
if agent_display_name not in existing_bubbles:
|
890 |
+
existing_bubbles.append(agent_display_name)
|
891 |
+
|
892 |
+
self.update_visual_state({
|
893 |
+
"participants": participants,
|
894 |
+
"messages": all_messages,
|
895 |
+
"currentSpeaker": None,
|
896 |
+
"thinking": [],
|
897 |
+
"showBubbles": existing_bubbles
|
898 |
+
})
|
899 |
+
|
900 |
+
return True
|
901 |
+
|
902 |
+
return False
|
903 |
+
|
904 |
+
def dismiss_research_agent(self, agent_name: str, conversation_id: str):
|
905 |
+
"""Remove a research agent from the conversation visually"""
|
906 |
+
|
907 |
+
if agent_name in self.research_agents:
|
908 |
+
research_agent = self.research_agents[agent_name]
|
909 |
+
|
910 |
+
# Research agent leaves the conversation
|
911 |
+
research_agent.leave_conversation(conversation_id)
|
912 |
+
|
913 |
+
# Update visual state
|
914 |
+
session = get_or_create_session_state(self.session_id)
|
915 |
+
current_state = session["roundtable_state"]
|
916 |
+
|
917 |
+
agent_display_name = research_agent.manifest.identification.conversationalName
|
918 |
+
|
919 |
+
# Show leave message
|
920 |
+
all_messages = list(current_state.get("messages", []))
|
921 |
+
leave_message = {
|
922 |
+
"speaker": agent_display_name,
|
923 |
+
"text": f"👋 **Leaving Conversation**\nResearch assistance complete. Agent dismissed.",
|
924 |
+
"type": "agent_leave"
|
925 |
+
}
|
926 |
+
all_messages.append(leave_message)
|
927 |
+
|
928 |
+
# Remove from bubbles but keep in participants list for history
|
929 |
+
existing_bubbles = list(current_state.get("showBubbles", []))
|
930 |
+
if agent_display_name in existing_bubbles:
|
931 |
+
existing_bubbles.remove(agent_display_name)
|
932 |
+
|
933 |
+
self.update_visual_state({
|
934 |
+
"participants": current_state.get("participants", []),
|
935 |
+
"messages": all_messages,
|
936 |
+
"currentSpeaker": None,
|
937 |
+
"thinking": [],
|
938 |
+
"showBubbles": existing_bubbles
|
939 |
+
})
|
940 |
+
|
941 |
+
return True
|
942 |
+
|
943 |
+
return False
|
944 |
+
|
945 |
def call_model(self, model: str, prompt: str, context: str = "") -> Optional[str]:
|
946 |
"""Enhanced model calling with native function calling support"""
|
947 |
if not self.models[model]['available']:
|