OpenHands/openhands/storage/conversation/conversation_store.py
Robert Brennan 366fd7ab8a
Improve agent loop tracking and make concurrent limit configurable (#6945)
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: Tim O'Farrell <tofarr@gmail.com>
2025-03-07 09:19:50 -07:00

55 lines
1.7 KiB
Python

from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Iterable
from openhands.core.config.app_config import AppConfig
from openhands.storage.data_models.conversation_metadata import ConversationMetadata
from openhands.storage.data_models.conversation_metadata_result_set import (
ConversationMetadataResultSet,
)
from openhands.utils.async_utils import wait_all
class ConversationStore(ABC):
"""
Storage for conversation metadata. May or may not support multiple users depending on the environment
"""
@abstractmethod
async def save_metadata(self, metadata: ConversationMetadata) -> None:
"""Store conversation metadata"""
@abstractmethod
async def get_metadata(self, conversation_id: str) -> ConversationMetadata:
"""Load conversation metadata"""
@abstractmethod
async def delete_metadata(self, conversation_id: str) -> None:
"""delete conversation metadata"""
@abstractmethod
async def exists(self, conversation_id: str) -> bool:
"""Check if conversation exists"""
@abstractmethod
async def search(
self,
page_id: str | None = None,
limit: int = 20,
) -> ConversationMetadataResultSet:
"""Search conversations"""
async def get_all_metadata(
self, conversation_ids: Iterable[str]
) -> list[ConversationMetadata]:
"""Get metadata for multiple conversations in parallel"""
return await wait_all([self.get_metadata(cid) for cid in conversation_ids])
@classmethod
@abstractmethod
async def get_instance(
cls, config: AppConfig, user_id: str | None
) -> ConversationStore:
"""Get a store for the user represented by the token given"""