memoryscope.core.service

class memoryscope.core.service.BaseMemoryService(memory_operations: ~typing.Dict[str, dict], context: ~memoryscope.core.utils.singleton.singleton.<locals>._singleton, assistant_name: str | None = None, human_name: str | None = None, **kwargs)[源代码]

基类:object

An abstract base class for managing memory operations within a multithreaded context. It sets up the infrastructure for operation handling, message storage, and synchronization, along with logging capabilities and customizable configurations.

__init__(memory_operations: ~typing.Dict[str, dict], context: ~memoryscope.core.utils.singleton.singleton.<locals>._singleton, assistant_name: str | None = None, human_name: str | None = None, **kwargs)[源代码]

Initializes the BaseMemoryService with operation definitions, keys for memory access, and additional keyword arguments for flexibility.

参数:
  • memory_operations (Dict[str, dict]) -- A dictionary defining available memory operations.

  • context (MemoryscopeContext) -- runtime context.

  • human_name (str) -- human name.

  • assistant_name (str) -- assistant name.

  • **kwargs -- Additional parameters to customize service behavior.

property human_name: str
property assistant_name: str
get_chat_messages_scatter(recent_n_pair: int) List[Message][源代码]
property op_description_dict: Dict[str, str]

Property to retrieve a dictionary mapping operation keys to their descriptions. :returns: A dictionary where keys are operation identifiers and values are their descriptions. :rtype: Dict[str, str]

abstract add_messages_pair(messages: List[Message])[源代码]
abstract register_operation(name: str, operation_config: dict, **kwargs)[源代码]
abstract init_service(**kwargs)[源代码]
start_backend_service(name: str | None = None, **kwargs)[源代码]
stop_backend_service(wait_service: bool = False)[源代码]
abstract run_operation(name: str, role_name: str = '', **kwargs)[源代码]
class memoryscope.core.service.MemoryScopeService(history_msg_count: int = 100, contextual_msg_max_count: int = 10, contextual_msg_min_count: int = 0, **kwargs)[源代码]

基类:BaseMemoryService

__init__(history_msg_count: int = 100, contextual_msg_max_count: int = 10, contextual_msg_min_count: int = 0, **kwargs)[源代码]

init function. :param history_msg_count: The conversation history in memory, control the quantity, and reduce memory usage. :type history_msg_count: int :param contextual_msg_max_count: The maximum context length in a conversation. If it exceeds this length,

it will not be included in the context to prevent token overflow.

参数:
  • contextual_msg_min_count (int) -- The minimum context length in a conversation. If it is shorter than this length, no conversation summary will be made and no long-term memory will be generated.

  • kwargs (dict) -- Additional parameters to customize service behavior.

add_messages_pair(messages: List[Message])[源代码]

Adds a list of messages to the chat history, it can be a pair [user_message, assistant_message]. Ensuring the message list remains sorted by creation time and does not exceed the maximum history message count.

参数:
  • messages (List[Message] | Message) -- A single message instance or a list of message instances

  • history. (to be added to the chat)

register_operation(name: str, operation_config: dict, **kwargs)[源代码]
init_service(**kwargs)[源代码]
run_operation(name: str, role_name: str = '', **kwargs)[源代码]

Executes a specific operation by its name with provided keyword arguments.

参数:
  • name (str) -- The name of the operation to execute.

  • role_name (str) -- The name of the operation to execute.

  • **kwargs -- Keyword arguments for the operation's execution.

返回:

The result of the operation execution, if any. Otherwise, None.

抛出:

Warning -- If the operation name is not initialized in _operation_dict.

start_backend_service(name: str | None = None, **kwargs)[源代码]

Start all backend operations.

stop_backend_service(wait_service: bool = False)[源代码]

Stops all backend operations that are currently running.