feat(db): add migration to simplify agent architecture

- Add migration to delete user_agents table and memories.agent_id
- Rename user_agent_catalog to system_agents
- Remove UserAgents model
- Rename UserAgentCatalog to SystemAgents model
This commit is contained in:
qzl
2026-03-04 11:04:13 +08:00
parent 7cc333a862
commit 2d410e8e84
4 changed files with 323 additions and 68 deletions
+2 -4
View File
@@ -13,10 +13,9 @@ from models.memories import Memory
from models.profile import Profile
from models.schedule_items import ScheduleItem
from models.schedule_subscriptions import ScheduleSubscription
from models.system_agents import SystemAgents
from models.todos import Todo
from models.todo_sources import TodoSource
from models.user_agents import UserAgent
from models.user_agent_catalog import UserAgentCatalog
__all__ = [
"AgentChatMessage",
@@ -33,8 +32,7 @@ __all__ = [
"Profile",
"ScheduleItem",
"ScheduleSubscription",
"SystemAgents",
"Todo",
"TodoSource",
"UserAgent",
"UserAgentCatalog",
]
@@ -9,8 +9,8 @@ from sqlalchemy.orm import Mapped, mapped_column
from core.db.base import Base, TimestampMixin
class UserAgentCatalog(TimestampMixin, Base):
__tablename__: str = "user_agent_catalog"
class SystemAgents(TimestampMixin, Base):
__tablename__: str = "system_agents"
agent_type: Mapped[str] = mapped_column(
String(20),
-62
View File
@@ -1,62 +0,0 @@
from __future__ import annotations
import uuid
from enum import Enum
from sqlalchemy import String
from sqlalchemy.dialects.postgresql import JSONB, UUID
from sqlalchemy.orm import Mapped, mapped_column
from core.db.base import Base, SoftDeleteMixin, TimestampMixin
class UserAgentStatus(str, Enum):
ACTIVE = "active"
PAUSED = "paused"
MIGRATING = "migrating"
class AgentType(str, Enum):
INTENT_RECOGNITION = "INTENT_RECOGNITION"
TASK_EXECUTION = "TASK_EXECUTION"
RESULT_REPORTING = "RESULT_REPORTING"
class UserAgent(TimestampMixin, SoftDeleteMixin, Base):
__tablename__: str = "user_agents"
__table_args__ = {"extend_existing": True}
id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
)
user_id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
nullable=False,
unique=True,
)
llm_id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
nullable=False,
)
agent_type: Mapped[AgentType] = mapped_column(
String(20),
nullable=False,
)
config: Mapped[dict] = mapped_column(
JSONB,
nullable=False,
server_default="{}",
)
status: Mapped[UserAgentStatus] = mapped_column(
String(20),
nullable=False,
default=UserAgentStatus.ACTIVE,
)
created_by: Mapped[uuid.UUID | None] = mapped_column(
UUID(as_uuid=True),
nullable=True,
)
updated_by: Mapped[uuid.UUID | None] = mapped_column(
UUID(as_uuid=True),
nullable=True,
)