Skip to content

Python: New Feature: Support Multiple Concurrent Sessions in Realtime Services [Python] #12471

@mateoperezrivera

Description

@mateoperezrivera

name: Feature request
about: Suggest an idea for this project


Feature Request: Support Multiple Concurrent Sessions in Realtime Services

Description

Currently, the Azure Realtime services (AzureRealtimeWebsocket and AzureRealtimeWebRTC) in Semantic Kernel are designed with a 1:1 relationship between service instance and session. This makes it challenging to build scalable backend applications that need to serve multiple concurrent users.

Current Behavior

  • Each AzureRealtimeWebsocket or AzureRealtimeWebRTC instance can only maintain one active session at a time
  • The create_session() method modifies the service instance's internal state directly
  • To serve multiple users, we need to create separate service instances for each user
  • The session state (connection, settings, etc.) is tightly coupled to the service instance

Proposed Solution

Refactor the Realtime services to support multiple concurrent sessions by separating session management from the service instance:
#Example

class AzureRealtimeWebsocket:
    async def create_session(
        self,
        chat_history: ChatHistory | None = None,
        settings: PromptExecutionSettings | None = None,
        **kwargs: Any
    ) -> RealtimeSession:
        """Create and return a new session instance"""
        session = RealtimeSession(
            service=self,
            chat_history=chat_history,
            settings=settings,
            **kwargs
        )
        await session.connect()
        return session

class RealtimeSession:
    """Represents an individual realtime session"""
    async def send(self, event: RealtimeEvents) -> None: ...
    async def receive(self) -> AsyncGenerator[RealtimeEvents, None]: ...
    async def update_session(self, **kwargs) -> None: ...
    async def close(self) -> None: ...

Metadata

Metadata

Labels

ai connectorAnything related to AI connectorspythonPull requests for the Python Semantic Kernel

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions