Skip to content

memory

Memory ORM Model

This module defines the Memory class, which represents an agent memory.

Attributes

MemoryType module-attribute

MemoryType = Literal['observation', 'integration']

Classes

Memory

Bases: Base

AI agent memory stream metadata

Attributes

__table_args__ class-attribute instance-attribute
__table_args__ = (
    Index(
        "idx_memory__memory_collection__agent",
        "memory_collection_pkid",
        "agent_pkid",
    ),
    {"comment": __doc__},
)
__tablename__ class-attribute instance-attribute
__tablename__ = 'memory'
access_count class-attribute instance-attribute
access_count: Mapped[int] = mapped_column(
    default=0,
    comment="Number of times the memory was accessed",
)
accessed class-attribute instance-attribute
accessed: Mapped[datetime] = mapped_column(
    server_default=now(),
    comment="Timestamp of last memory access",
)
activity_session class-attribute instance-attribute
activity_session: Mapped[ActivitySession] = relationship(
    back_populates="memories"
)
activity_session_pkid class-attribute instance-attribute
activity_session_pkid: Mapped[str] = mapped_column(
    ForeignKey("activity_session.pkid"),
    comment="Reference to the activity session in which the memory was created",
)
agent class-attribute instance-attribute
agent: Mapped[Agent] = relationship(
    back_populates="memories"
)
agent_pkid class-attribute instance-attribute
agent_pkid: Mapped[str] = mapped_column(
    ForeignKey("agent.pkid"),
    index=True,
    comment="Reference to the agent who owns the memory",
)
child_associations class-attribute instance-attribute
child_associations: Mapped[List[MemoryGraph]] = (
    relationship(
        foreign_keys=[parent_pkid],
        cascade="all, delete-orphan",
        lazy="dynamic",
        back_populates="parent",
        overlaps="parent,parent_of,child_of",
    )
)
create_ts class-attribute instance-attribute
create_ts: Mapped[datetime] = mapped_column(
    server_default=now(), comment="Record create timestamp"
)
deleted class-attribute instance-attribute
deleted: Mapped[bool] = mapped_column(
    default=False, comment="Memory soft delete flag"
)
importance class-attribute instance-attribute
importance: Mapped[int] = mapped_column(
    comment="Memory importance score as determined by the agent"
)
memo class-attribute instance-attribute
memo: Mapped[Optional[str]] = mapped_column(
    String(255),
    nullable=True,
    comment="Free-form memory annotation",
)
memory_collection class-attribute instance-attribute
memory_collection: Mapped[MemoryCollection] = relationship(
    back_populates="memories"
)
memory_collection_pkid class-attribute instance-attribute
memory_collection_pkid: Mapped[str] = mapped_column(
    ForeignKey("memory_collection.pkid"),
    comment="Reference to the memory collection",
)
memory_txt class-attribute instance-attribute
memory_txt: Mapped[str] = mapped_column(
    Text,
    nullable=False,
    comment="Raw memory text, this is what the agent 'remembers'",
)
memory_type class-attribute instance-attribute
memory_type: Mapped[MemoryType] = mapped_column(
    comment="Type of memory"
)
parent_associations class-attribute instance-attribute
parent_associations: Mapped[List[MemoryGraph]] = (
    relationship(
        foreign_keys=[child_pkid],
        cascade="all, delete-orphan",
        lazy="dynamic",
        back_populates="child",
        overlaps="child,child_of,parent_of",
    )
)
pkid class-attribute instance-attribute
pkid: Mapped[str] = mapped_column(
    String(PKID_LEN),
    primary_key=True,
    default=prefixed_uuid(__tablename__),
    comment="Unique memory ID in the RDBMS (not necessarily the same in the vector store)",
)
reduction_refs class-attribute instance-attribute
reduction_refs: Mapped[int] = mapped_column(
    default=0,
    comment="Count of foundational references, that is how many child memories in the graph were integrated to come up with this memory. Does not apply to observations.",
)
update_ts class-attribute instance-attribute
update_ts: Mapped[datetime] = mapped_column(
    server_default=now(),
    onupdate=current_timestamp(),
    comment="Record update timestamp",
)
vector_txt class-attribute instance-attribute
vector_txt: Mapped[Optional[str]] = mapped_column(
    Text,
    default=None,
    nullable=True,
    comment="Text used to generate vector index, when null, memory_txt is used",
)

Functions