memory
Agent memory service module
Attributes
Classes
MemoryService
Bases: BaseService
Agent memory service layer
Attributes
activity_session_dao
instance-attribute
activity_session_dao = ActivitySessionDao(
session=sa_session
)
memory_collection_dao
instance-attribute
memory_collection_dao = MemoryCollectionDao(
session=sa_session
)
Functions
create_memory
create_memory(
agent_pkid: str,
memory_collection_pkid: str,
activity_session_pkid: str,
memory_type: MemoryType,
memory_txt: str,
importance: int,
vectordb_ref: VectorStore,
memo: Optional[str] = None,
child_memory_pkids: Optional[List[str]] = None,
vector_txt: Optional[str] = None,
) -> Memory
Create a new memory.
Memories are initially created in a deleted state and are subsequently updated to a non-deleted state after the vectordb has been updated.
Parameters:
-
agent_pkid
(str
) –The primary key ID of the agent.
-
memory_collection_pkid
(str
) –The primary key ID of the memory collection.
-
activity_session_pkid
(str
) –The primary key ID of the activity session.
-
memory_type
(MemoryType
) –The type of memory.
-
memory_txt
(str
) –The text of the memory.
-
importance
(int
) –The importance of the memory.
-
vectordb_ref
(VectorStore
) –The reference to the vector store.
-
memo
(Optional[str]
, default:None
) –Additional memo for the memory. Defaults to None.
-
child_memory_pkids
(Optional[List[str]]
, default:None
) –The primary key IDs of the child memories. Defaults to None.
Returns:
-
Memory
–orm.Memory: The newly created memory.
delete_memories
Deletes memories with the given primary key IDs.
When hard_delete is True, a vectordb_ref must be provided. This is because hard deletion will also purge the memory from the vector index
Parameters:
-
memory_pkids
(Union[str, List[str]]
) –The primary key(s) of the memories to delete.
-
vectordb_ref
(Optional[VectorStore]
) –Reference to the VectorStore. Defaults to None.
Raises:
-
ServiceError
–If an error occurs during the deletion process.
Returns:
-
None
–None
get_memory
get_memory(memory_pkid: str) -> Memory
Retrieve a memory object by its primary key.
Parameters:
-
memory_pkid
(str
) –The primary key of the memory.
Returns:
-
Memory
–orm.Memory: The memory object.
Raises:
-
ServiceError
–If an error occurs while retrieving the memory.
undelete_memories
Undeletes memories with the given primary key IDs.
Parameters:
-
memory_pkids
(Union[str, List[str]]
) –The primary key ID(s) of the memories to undelete.
Raises:
-
ServiceError
–If the memory is not deleted or if an error occurs during the operation.
update_memory
update_memory(
memory_pkid: str,
memory_txt: Optional[str] = None,
importance: Optional[int] = None,
memo: Optional[str] = None,
) -> Memory
Update the attributes of a memory.
Parameters:
-
memory_pkid
(str
) –The primary key of the memory to be updated.
-
memory_txt
(str
, default:None
) –The new text for the memory. Defaults to None.
-
importance
(int
, default:None
) –The new importance value for the memory. Defaults to None.
-
memo
(str
, default:None
) –The new memo for the memory. Defaults to None.
Returns:
-
Memory
–orm.Memory: The updated memory object.
Raises:
-
ServiceError
–If an error occurs during the update operation.