Skip to content

Base

Base Memory Module for GLLM Agents.

This module defines the BaseMemory class which serves as a template for implementing different types of memory for agents.

Authors

Raymond Christopher (raymond.christopher@gdplabs.id)

References

https://github.com/GDP-ADMIN/gdplabs-exploration/blob/ai-agent-app/backend/gllm_agents/memory/base.py

BaseMemory

Bases: ABC

Base class for agent memory.

This concrete base class provides a default structure. Subclasses can inherit from this class to implement specific memory management behaviors.

add_message(message) abstractmethod

Add a message to the memory.

Adds a single ChatMessage to the memory storage. The exact implementation depends on the specific memory backend.

Parameters:

Name Type Description Default
message ChatMessage

The ChatMessage object to add to memory. The message should contain role and content information.

required

add_messages(messages)

Add multiple messages to the memory.

Parameters:

Name Type Description Default
messages Sequence[ChatMessage]

A sequence of ChatMessage objects to add.

required

clear() abstractmethod

Clears the memory or resets the state of the agent.

This method must be implemented to define the specific behavior for clearing or resetting the memory of the agent.

get_memory_variables()

Retrieve memory variables.

This method returns a dictionary containing memory-related variables. The default implementation returns a dictionary with chat_history.

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: A dictionary where keys are variable names and values

Dict[str, Any]

are the corresponding memory-related data.

get_messages() abstractmethod

Retrieve a list of messages.

Returns:

Type Description
List[ChatMessage]

List[ChatMessage]: A list of messages in a generic format.

validate_env() classmethod

Validate environment prerequisites for a memory backend.

This hook allows memory implementations to fail fast when required environment variables or credentials are missing. Default is a no-op.