FloorManager / test_envelope_logging.py
BolyosCsaba
envelop log revamp
99f7738
#!/usr/bin/env python3
"""
Test script to demonstrate enhanced envelope logging in FloorManager
This script shows how the FloorManager logs detailed envelope communications
similar to the example with badword-01 sentinel and parrot-agent.
"""
import asyncio
import logging
import json
from datetime import datetime
from src.floor_manager import FloorManager
from src.agent_manager import AgentInfo
# Set up logging to see all the details
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
async def test_envelope_logging():
"""Test the enhanced envelope logging with a realistic example"""
print("\n" + "="*80)
print("TESTING ENHANCED ENVELOPE LOGGING")
print("="*80 + "\n")
# Create Floor Manager
fm = FloorManager()
# Create a test session
session_id = "1234567890"
floor_manager_uri = "tag:floormanager.example.com,2026:fm-01"
floor_manager_url = "https://example.com/floor"
session = fm.create_session(
session_id=session_id,
floor_manager_uri=floor_manager_uri,
floor_manager_url=floor_manager_url
)
# Add a mock agent participant (parrot agent)
agent_info = AgentInfo(
speaker_uri="tag:openfloor-demo.com,2025:parrot-agent",
service_url="https://example.com/agent",
manifest={
"conversationalName": "Parrot Agent",
"capabilities": ["utterance"]
}
)
session.add_participant(agent_info)
print("\n📋 Test Scenario: Badword Sentinel sends a moderation alert\n")
# Create a test envelope similar to your example
# This simulates receiving an envelope from the badword sentinel
test_envelope = {
"openFloor": {
"schema": {
"version": "1.0.0"
},
"conversation": {
"id": "1234567890"
},
"sender": {
"speakerUri": "tag:sentinel.ofpbadword.service,2025:badword-01",
"serviceUrl": "https://bladeszasza-ofpbadword.hf.space/ofp"
},
"events": [
{
"eventType": "utterance",
"to": {
"speakerUri": "tag:openfloor-demo.com,2025:parrot-agent",
"private": True
},
"parameters": {
"dialogEvent": {
"id": "de:b060efca-2ae4-46b0-baa6-28b04bce91fa",
"speakerUri": "tag:sentinel.ofpbadword.service,2025:badword-01",
"span": {
"startTime": "2026-01-13T14:25:11.160538Z"
},
"features": {
"text": {
"mimeType": "text/plain",
"tokens": [
{
"value": "⚠️ Content moderation alert: 2 violation(s) detected. Censored: This is a test utterance! **** on ****",
"confidence": 1.0
}
]
}
}
}
}
}
]
}
}
# Test 1: Log incoming envelope (received from badword sentinel)
print("\n" + "-"*80)
print("TEST 1: Logging INCOMING envelope from badword sentinel")
print("-"*80)
fm._log_envelope_details(test_envelope, direction="📨 RECEIVED")
# Test 2: Simulate handling the incoming envelope
print("\n" + "-"*80)
print("TEST 2: Handling incoming envelope (will broadcast to participants)")
print("-"*80)
await fm.handle_incoming_envelope(session_id, test_envelope)
# Test 3: Create and log an outgoing response envelope
print("\n" + "-"*80)
print("TEST 3: Logging OUTGOING response envelope")
print("-"*80)
response_envelope = {
"openFloor": {
"schema": {
"version": "1.0.0"
},
"conversation": {
"id": "1234567890"
},
"sender": {
"speakerUri": "tag:openfloor-demo.com,2025:parrot-agent",
"serviceUrl": "https://example.com/agent"
},
"events": [
{
"eventType": "utterance",
"parameters": {
"dialogEvent": {
"id": "de:response-001",
"speakerUri": "tag:openfloor-demo.com,2025:parrot-agent",
"span": {
"startTime": datetime.utcnow().isoformat() + "Z"
},
"features": {
"text": {
"mimeType": "text/plain",
"tokens": [
{
"value": "Thank you for the moderation alert. I understand.",
"confidence": 1.0
}
]
}
}
}
}
}
]
}
}
fm._log_envelope_details(response_envelope, direction="📤 OUTGOING")
# Test 4: Show what detailed logging looks like in JSON format
print("\n" + "-"*80)
print("TEST 4: Complete envelope structure in JSON format")
print("-"*80)
print("\nOriginal envelope (badword sentinel alert):")
print(json.dumps(test_envelope, indent=2))
print("\nResponse envelope (agent acknowledgment):")
print(json.dumps(response_envelope, indent=2))
print("\n" + "="*80)
print("LOGGING TEST COMPLETE")
print("="*80)
print("\n✅ The FloorManager now logs detailed envelope communications including:")
print(" - Schema version and conversation ID")
print(" - Sender information (speakerUri and serviceUrl)")
print(" - Event types and targets (public/private)")
print(" - Dialog event details (ID, speaker, timestamps)")
print(" - Utterance content with tokens and confidence levels")
print(" - Complete JSON structure for debugging\n")
if __name__ == "__main__":
asyncio.run(test_envelope_logging())