feat: add prompts table

This commit is contained in:
Andy Li
2025-07-22 13:59:52 -07:00
committed by GitHub
parent 695e935b55
commit 2cca2cc73a
5 changed files with 73 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
"""add prompts
Revision ID: ddecfe4902bc
Revises: c4eb5a907b38
Create Date: 2025-07-21 15:58:13.357459
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "ddecfe4902bc"
down_revision: Union[str, None] = "c4eb5a907b38"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"prompts",
sa.Column("id", sa.String(), nullable=False),
sa.Column("prompt", sa.String(), nullable=False),
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True),
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True),
sa.Column("is_deleted", sa.Boolean(), server_default=sa.text("FALSE"), nullable=False),
sa.Column("_created_by_id", sa.String(), nullable=True),
sa.Column("_last_updated_by_id", sa.String(), nullable=True),
sa.Column("project_id", sa.String(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("prompts")
# ### end Alembic commands ###

View File

@@ -20,6 +20,7 @@ from letta.orm.mcp_server import MCPServer
from letta.orm.message import Message
from letta.orm.organization import Organization
from letta.orm.passage import AgentPassage, BasePassage, SourcePassage
from letta.orm.prompt import Prompt
from letta.orm.provider import Provider
from letta.orm.provider_trace import ProviderTrace
from letta.orm.sandbox_config import AgentEnvironmentVariable, SandboxConfig, SandboxEnvironmentVariable

View File

@@ -62,3 +62,11 @@ class SandboxConfigMixin(Base):
__abstract__ = True
sandbox_config_id: Mapped[str] = mapped_column(String, ForeignKey("sandbox_configs.id"))
class ProjectMixin(Base):
"""Mixin for models that belong to a project."""
__abstract__ = True
project_id: Mapped[str] = mapped_column(String, nullable=True, doc="The associated project id.")

13
letta/orm/prompt.py Normal file
View File

@@ -0,0 +1,13 @@
from sqlalchemy.orm import Mapped, mapped_column
from letta.orm.mixins import ProjectMixin
from letta.orm.sqlalchemy_base import SqlalchemyBase
from letta.schemas.prompt import Prompt as PydanticPrompt
class Prompt(SqlalchemyBase, ProjectMixin):
__pydantic_model__ = PydanticPrompt
__tablename__ = "prompts"
id: Mapped[str] = mapped_column(primary_key=True, doc="Unique passage identifier")
prompt: Mapped[str] = mapped_column(doc="The string contents of the prompt.")

9
letta/schemas/prompt.py Normal file
View File

@@ -0,0 +1,9 @@
from pydantic import Field
from letta.schemas.letta_base import OrmMetadataBase
class Prompt(OrmMetadataBase):
id: str = Field(..., description="The id of the agent. Assigned by the database.")
project_id: str | None = Field(None, description="The associated project id.")
prompt: str = Field(..., description="The string contents of the prompt.")