Spaces:
Sleeping
Sleeping
BolyosCsaba commited on
Commit Β·
a524844
1
Parent(s): 1bb3be1
fix
Browse files- src/floor_manager.py +42 -0
- test_app.py +22 -0
src/floor_manager.py
CHANGED
|
@@ -201,6 +201,29 @@ class FloorManager:
|
|
| 201 |
for event in events:
|
| 202 |
event_type = event.get("eventType")
|
| 203 |
logger.info(f" - Event type: {event_type}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
except ValueError:
|
| 205 |
logger.debug(f"Response from {speaker_uri} is not JSON: {response.text[:200]}")
|
| 206 |
|
|
@@ -369,3 +392,22 @@ class FloorManager:
|
|
| 369 |
)
|
| 370 |
|
| 371 |
return any(results.values())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
for event in events:
|
| 202 |
event_type = event.get("eventType")
|
| 203 |
logger.info(f" - Event type: {event_type}")
|
| 204 |
+
|
| 205 |
+
# Extract utterance content if present
|
| 206 |
+
if event_type == "utterance":
|
| 207 |
+
params = event.get("parameters", {})
|
| 208 |
+
dialog_event = params.get("dialogEvent", {})
|
| 209 |
+
features = dialog_event.get("features", {})
|
| 210 |
+
text_feature = features.get("text", {})
|
| 211 |
+
tokens = text_feature.get("tokens", [])
|
| 212 |
+
if tokens:
|
| 213 |
+
text_content = " ".join([t.get("token", "") for t in tokens])
|
| 214 |
+
logger.info(f" π¬ Agent says: {text_content}")
|
| 215 |
+
|
| 216 |
+
# Store response for retrieval
|
| 217 |
+
if not hasattr(self, '_agent_responses'):
|
| 218 |
+
self._agent_responses = {}
|
| 219 |
+
if session_id not in self._agent_responses:
|
| 220 |
+
self._agent_responses[session_id] = []
|
| 221 |
+
self._agent_responses[session_id].append({
|
| 222 |
+
"agent_uri": speaker_uri,
|
| 223 |
+
"agent_name": agent_info.manifest.get("conversationalName", speaker_uri) if agent_info.manifest else speaker_uri,
|
| 224 |
+
"message": text_content,
|
| 225 |
+
"timestamp": datetime.now()
|
| 226 |
+
})
|
| 227 |
except ValueError:
|
| 228 |
logger.debug(f"Response from {speaker_uri} is not JSON: {response.text[:200]}")
|
| 229 |
|
|
|
|
| 392 |
)
|
| 393 |
|
| 394 |
return any(results.values())
|
| 395 |
+
|
| 396 |
+
def get_agent_responses(self, session_id: str) -> List[Dict[str, Any]]:
|
| 397 |
+
"""
|
| 398 |
+
Get agent responses for a session
|
| 399 |
+
|
| 400 |
+
Args:
|
| 401 |
+
session_id: Session identifier
|
| 402 |
+
|
| 403 |
+
Returns:
|
| 404 |
+
List of agent response dictionaries
|
| 405 |
+
"""
|
| 406 |
+
if not hasattr(self, '_agent_responses'):
|
| 407 |
+
return []
|
| 408 |
+
return self._agent_responses.get(session_id, [])
|
| 409 |
+
|
| 410 |
+
def clear_agent_responses(self, session_id: str):
|
| 411 |
+
"""Clear agent responses for a session"""
|
| 412 |
+
if hasattr(self, '_agent_responses') and session_id in self._agent_responses:
|
| 413 |
+
self._agent_responses[session_id] = []
|
test_app.py
CHANGED
|
@@ -299,8 +299,30 @@ def send_message(agent_name: str, message: str):
|
|
| 299 |
|
| 300 |
print(f"β
Broadcast complete: {sum(1 for r in results.values() if r)}/{len(results)} successful")
|
| 301 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
except Exception as e:
|
| 303 |
print(f"β Error broadcasting message: {e}")
|
|
|
|
|
|
|
| 304 |
|
| 305 |
return (
|
| 306 |
current_session.format_chat_history(),
|
|
|
|
| 299 |
|
| 300 |
print(f"β
Broadcast complete: {sum(1 for r in results.values() if r)}/{len(results)} successful")
|
| 301 |
|
| 302 |
+
# Check for agent responses
|
| 303 |
+
agent_responses = floor_manager.get_agent_responses(current_session.session_id)
|
| 304 |
+
if agent_responses:
|
| 305 |
+
print(f"π₯ Received {len(agent_responses)} agent response(s)")
|
| 306 |
+
for response in agent_responses:
|
| 307 |
+
# Add agent response to UI
|
| 308 |
+
agent_name = response["agent_name"]
|
| 309 |
+
agent_msg = response["message"]
|
| 310 |
+
print(f" π¬ {agent_name}: {agent_msg}")
|
| 311 |
+
|
| 312 |
+
# Add to mock session as a system message
|
| 313 |
+
current_session.messages.append({
|
| 314 |
+
"role": agent_name,
|
| 315 |
+
"content": agent_msg,
|
| 316 |
+
"timestamp": response["timestamp"].strftime("%H:%M:%S")
|
| 317 |
+
})
|
| 318 |
+
|
| 319 |
+
# Clear responses after displaying
|
| 320 |
+
floor_manager.clear_agent_responses(current_session.session_id)
|
| 321 |
+
|
| 322 |
except Exception as e:
|
| 323 |
print(f"β Error broadcasting message: {e}")
|
| 324 |
+
import traceback
|
| 325 |
+
traceback.print_exc()
|
| 326 |
|
| 327 |
return (
|
| 328 |
current_session.format_chat_history(),
|