This directory contains the core logic for the Webex Contact Center BYOVA Gateway, including the gRPC server implementation and virtual agent routing system.
The optional datasource lifecycle is responsible for:
- Startup Registration: Discovers or registers the configured gateway URL before gRPC traffic is accepted
- Configuration Reconciliation: Keeps URL, schema, audience, subject, and active status aligned
- JWS Renewal: Uses
webex-byods-sdkto renew the datasource token beforetokenExpiryTime - Retry and Shutdown: Retries background renewal failures and stops through an interruptible event
- Credential Isolation: Resolves SDK credential values only from named environment variables
The router is responsible for:
- Dynamic Connector Loading: Loads connector implementations at runtime
- Request Routing: Routes incoming requests to appropriate virtual agents
- Agent Management: Manages agent selection and availability
- Session Coordination: Coordinates sessions across different connectors
The current connector set includes local audio, AWS Lex, and Google CX Agent
Studio (GECXConnector). The router discovers each implementation from
config/config.yaml; no provider-specific import is required in the core.
Key Methods:
class VirtualAgentRouter:
def load_connectors(self, config: dict) -> None:
"""Load connector implementations from configuration"""
def get_all_available_agents(self) -> list[str]:
"""Return all available agent IDs across all connectors"""
def get_connector_for_agent(self, agent_id: str) -> IVendorConnector:
"""Get the connector instance for a specific agent"""
def route_request(self, agent_id: str, method: str, *args, **kwargs) -> Any:
"""Route a request to the appropriate connector method"""The gRPC server implements the VoiceVirtualAgentServicer interface:
- ListVirtualAgents: Returns available virtual agents to WxCC
- ProcessCallerInput: Handles bidirectional streaming for voice interactions
- Session Management: Tracks active sessions and connection events
- Data Conversion: Converts between WxCC gRPC format and vendor formats
Key Features:
- Bidirectional streaming for real-time voice communication
- Independent bounded ingress/response queues and incremental connector
iterator consumption, including raw BYOVA
CHUNKoutput - A connector response sink for autonomous full-duplex output produced after a request-owned response iterator has completed
- Session lifecycle tracking (start, message, end events)
- Automatic session cleanup on stream termination
- Error handling and logging
The following files are generated from Protocol Buffer definitions:
byova_common_pb2.py- Common data structuresbyova_common_pb2_grpc.py- Common gRPC service definitionsvoicevirtualagent_pb2.py- Voice virtual agent data structuresvoicevirtualagent_pb2_grpc.py- Voice virtual agent service definitions
Regeneration:
# Regenerate stubs when proto files change
python -m grpc_tools.protoc -Iproto --python_out=src/core --grpc_python_out=src/core proto/byova_common.proto proto/voicevirtualagent.proto- Datasource Readiness: When enabled, startup reconciles the BYODS registration and schedules renewal
- WxCC Request: WxCC sends gRPC request to gateway
- Router Lookup: Gateway finds appropriate connector for agent
- Connector Processing: Connector processes request in vendor format
- Response Conversion: Response converted back to WxCC format
- Stream Response: Response streamed back to WxCC
# Conversation tracking in WxCCGatewayServer
self.active_conversations: Dict[str, Dict[str, Any]] = {
"conversation_id": {
"agent_id": "agent_name",
"conversation_id": "conv_id",
"customer_org_id": "org_id",
"welcome_sent": True,
"rpc_sessions": ["rpc_session_1", "rpc_session_2"]
}
}
# Connection event tracking
self.connection_events = [
{
"event_type": "start|message|end",
"conversation_id": "conversation_id",
"agent_id": "agent_id",
"timestamp": time.time(),
"rpc_session_id": "rpc_session_id",
**kwargs
}
]The core components implement comprehensive error handling:
- gRPC Status Codes: Proper error codes returned to WxCC
- Exception Logging: Detailed error logging with context
- Graceful Degradation: System continues operating despite individual failures
- Session Cleanup: Automatic cleanup of failed sessions
Core components are configured via the main config.yaml:
# Gateway settings
gateway:
host: "0.0.0.0"
port: 50051
max_workers: 10
# Session management
sessions:
timeout: 300 # seconds
cleanup_interval: 60 # seconds
max_sessions: 1000
# Logging
logging:
level: "INFO"
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"- Extend Router: Add new routing logic to
VirtualAgentRouter - Extend Server: Add new gRPC methods to
WxCCGatewayServer - Update Stubs: Regenerate gRPC stubs if proto files change
- Test Integration: Test with WxCC and connectors
# Unit tests for core components
python -m pytest tests/core/
# Integration tests
python -m pytest tests/integration/
# Load testing
python tests/load/test_gateway_load.py- Connection Pooling: Reuse connections to external services
- Async Processing: Use async/await for I/O operations
- Memory Management: Implement proper cleanup for large sessions
- Monitoring: Track performance metrics and bottlenecks
- gRPC Connection Errors: Check network connectivity and firewall rules
- Session Leaks: Monitor active sessions and implement cleanup
- Memory Issues: Profile memory usage and optimize data structures
- Performance: Monitor request latency and throughput
Enable detailed logging for troubleshooting:
logging:
level: "DEBUG"
handlers:
- type: "console"
level: "DEBUG"
- type: "file"
filename: "logs/gateway_debug.log"
level: "DEBUG"This code is licensed under the Cisco Sample Code License v1.1. See the main project README for details.