Files
letta-server/letta/orm/archives_agents.py
Kian Jones f5c4ab50f4 chore: add ty + pre-commit hook and repeal even more ruff rules (#9504)
* auto fixes

* auto fix pt2 and transitive deps and undefined var checking locals()

* manual fixes (ignored or letta-code fixed)

* fix circular import

* remove all ignores, add FastAPI rules and Ruff rules

* add ty and precommit

* ruff stuff

* ty check fixes

* ty check fixes pt 2

* error on invalid
2026-02-24 10:55:11 -08:00

33 lines
1.4 KiB
Python

from datetime import datetime
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from letta.orm.agent import Agent
from letta.orm.archive import Archive
from sqlalchemy import Boolean, DateTime, ForeignKey, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship
from letta.orm.base import Base
class ArchivesAgents(Base):
"""Many-to-many relationship between agents and archives"""
__tablename__ = "archives_agents"
# TODO: Remove this unique constraint when we support multiple archives per agent
# For now, each agent can only have one archive
__table_args__ = (UniqueConstraint("agent_id", name="unique_agent_archive"),)
agent_id: Mapped[str] = mapped_column(String, ForeignKey("agents.id", ondelete="CASCADE"), primary_key=True)
archive_id: Mapped[str] = mapped_column(String, ForeignKey("archives.id", ondelete="CASCADE"), primary_key=True)
# track when the relationship was created and if agent is owner
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default="now()")
is_owner: Mapped[bool] = mapped_column(Boolean, default=False, doc="Whether this agent created/owns the archive")
# relationships
agent: Mapped["Agent"] = relationship("Agent", back_populates="archives_agents")
archive: Mapped["Archive"] = relationship("Archive", back_populates="archives_agents")