Memory
Memory module for the GLLM agents.
References
https://github.com/GDP-ADMIN/gdplabs-exploration/blob/ai-agent-app/backend/gllm_agents/memory/init.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.
MemoryFactory
Factory to build concrete memory adapters by backend name.
create(backend, **kwargs)
staticmethod
Create a memory adapter instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend |
str
|
Backend identifier (e.g., "mem0"). |
required |
**kwargs |
Any
|
Keyword args passed to adapter constructor (e.g., limit, max_chars, namespace). |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
BaseMemory |
BaseMemory
|
A constructed memory adapter instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If backend is unknown or adapter can't be constructed. |
MemoryMethod
Constants for memory method names used in hasattr checks.