Skip to main content

openhands.server.conversation_manager.conversation_manager

ConversationManager Objects

class ConversationManager(ABC)

Abstract base class for managing conversations in OpenHands.

This class defines the interface for managing conversations, whether in standalone or clustered mode. It handles the lifecycle of conversations, including creation, attachment, detachment, and cleanup.

__aenter__

@abstractmethod
async def __aenter__()

Initialize the conversation manager.

__aexit__

@abstractmethod
async def __aexit__(exc_type, exc_value, traceback)

Clean up the conversation manager.

attach_to_conversation

@abstractmethod
async def attach_to_conversation(sid: str) -> Conversation | None

Attach to an existing conversation or create a new one.

detach_from_conversation

@abstractmethod
async def detach_from_conversation(conversation: Conversation)

Detach from a conversation.

join_conversation

@abstractmethod
async def join_conversation(sid: str, connection_id: str, settings: Settings,
user_id: str | None) -> EventStream | None

Join a conversation and return its event stream.

is_agent_loop_running

async def is_agent_loop_running(sid: str) -> bool

Check if an agent loop is running for the given session ID.

get_running_agent_loops

@abstractmethod
async def get_running_agent_loops(
user_id: str | None = None,
filter_to_sids: set[str] | None = None) -> set[str]

Get all running agent loops, optionally filtered by user ID and session IDs.

get_connections

@abstractmethod
async def get_connections(
user_id: str | None = None,
filter_to_sids: set[str] | None = None) -> dict[str, str]

Get all connections, optionally filtered by user ID and session IDs.

maybe_start_agent_loop

@abstractmethod
async def maybe_start_agent_loop(
sid: str,
settings: Settings,
user_id: str | None,
initial_user_msg: MessageAction | None = None) -> EventStream

Start an event loop if one is not already running

send_to_event_stream

@abstractmethod
async def send_to_event_stream(connection_id: str, data: dict)

Send data to an event stream.

disconnect_from_session

@abstractmethod
async def disconnect_from_session(connection_id: str)

Disconnect from a session.

close_session

@abstractmethod
async def close_session(sid: str)

Close a session.

get_instance

@classmethod
@abstractmethod
def get_instance(cls, sio: socketio.AsyncServer, config: AppConfig,
file_store: FileStore) -> ConversationManager

Get a store for the user represented by the token given