feat: Set SqlAlchemy to fetch sequence_id from DB, not generate it itself (#1726)

This commit is contained in:
Matthew Zhou
2025-04-15 19:25:46 -07:00
committed by GitHub
parent d572f04285
commit 0780cec6b9
2 changed files with 27 additions and 50 deletions

View File

@@ -1,7 +1,7 @@
from typing import List, Optional
from openai.types.chat.chat_completion_message_tool_call import ChatCompletionMessageToolCall as OpenAIToolCall
from sqlalchemy import BigInteger, ForeignKey, Index, Sequence, event, text
from sqlalchemy import BigInteger, FetchedValue, ForeignKey, Index, Sequence, event, text
from sqlalchemy.orm import Mapped, Session, mapped_column, relationship
from letta.orm.custom_columns import MessageContentColumn, ToolCallColumn, ToolReturnColumn
@@ -46,7 +46,13 @@ class Message(SqlalchemyBase, OrganizationMixin, AgentMixin):
)
# Monotonically increasing sequence for efficient/correct listing
sequence_id = mapped_column(BigInteger, Sequence("message_seq_id"), unique=True, nullable=False)
sequence_id: Mapped[int] = mapped_column(
BigInteger,
Sequence("message_seq_id"),
server_default=FetchedValue(),
unique=True,
nullable=False,
)
# Relationships
agent: Mapped["Agent"] = relationship("Agent", back_populates="messages", lazy="selectin")