feat:客户agent以及记忆模块功能开发

This commit is contained in:
2026-09-11 22:38:15 +08:00
parent 0197ac2ef2
commit 4da4775e8c
39 changed files with 2508 additions and 14 deletions
+37
View File
@@ -0,0 +1,37 @@
"""biz_work_order 工单表 ORM 模型。"""
from __future__ import annotations
from datetime import datetime
from typing import Any
from sqlalchemy import BigInteger, DateTime, JSON, String, func
from sqlalchemy.orm import Mapped, mapped_column
from model.base import Base
class BizWorkOrder(Base):
"""客户工单状态记录。"""
__tablename__ = "biz_work_order"
__table_args__ = {"comment": "通用业务工单表"}
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
work_order_no: Mapped[str] = mapped_column(String(32), nullable=False)
order_type: Mapped[str] = mapped_column(String(32), nullable=False)
sub_type: Mapped[str | None] = mapped_column(String(32), nullable=True)
customer_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
submitter_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
handler_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
current_node: Mapped[str] = mapped_column(String(32), nullable=False)
priority: Mapped[str] = mapped_column(String(8), nullable=False)
status: Mapped[str] = mapped_column(String(16), nullable=False)
biz_content: Mapped[dict[str, Any] | None] = mapped_column(JSON, nullable=True)
create_time: Mapped[datetime] = mapped_column(
DateTime, server_default=func.now(), nullable=False
)
update_time: Mapped[datetime] = mapped_column(
DateTime, server_default=func.now(), onupdate=func.now(), nullable=False
)
+40
View File
@@ -0,0 +1,40 @@
"""conversation_archive 会话归档表 ORM 模型。"""
from __future__ import annotations
from datetime import datetime
from typing import Any
from sqlalchemy import BigInteger, DateTime, Index, JSON, String, Text, UniqueConstraint, func
from sqlalchemy.orm import Mapped, mapped_column
from model.base import Base
class ConversationArchive(Base):
"""客服会话消息归档记录。"""
__tablename__ = "conversation_archive"
__table_args__ = (
UniqueConstraint("session_id", "message_id", name="uk_session_message"),
Index("idx_session", "session_id"),
Index("idx_user_time", "user_id", "create_time"),
Index("idx_agent", "agent_type"),
Index("idx_agent_run", "agent_run_id"),
{"comment": "会话归档表(审计回溯 + Agent 持续学习素材)"},
)
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
session_id: Mapped[str] = mapped_column(String(64), nullable=False)
customer_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
user_id: Mapped[int] = mapped_column(BigInteger, nullable=False)
agent_type: Mapped[str] = mapped_column(String(32), nullable=False)
role: Mapped[str] = mapped_column(String(16), nullable=False)
content: Mapped[str | None] = mapped_column(Text, nullable=True)
tool_calls: Mapped[list[dict[str, Any]] | None] = mapped_column(JSON, nullable=True)
message_id: Mapped[str] = mapped_column(String(64), nullable=False)
agent_run_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
trace_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
create_time: Mapped[datetime] = mapped_column(
DateTime, server_default=func.now(), nullable=False
)
+27
View File
@@ -0,0 +1,27 @@
"""customer_relation 客户-投顾关系表 ORM 模型。"""
from __future__ import annotations
from datetime import datetime
from sqlalchemy import BigInteger, DateTime, String
from sqlalchemy.orm import Mapped, mapped_column
from model.base import Base
class CustomerRelation(Base):
"""客户与投顾的当前或历史关系。"""
__tablename__ = "customer_relation"
__table_args__ = {"comment": "客户-投顾关系表"}
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
customer_id: Mapped[int] = mapped_column(BigInteger, nullable=False)
advisor_id: Mapped[int] = mapped_column(BigInteger, nullable=False)
assign_time: Mapped[datetime] = mapped_column(DateTime, nullable=False)
signed_time: Mapped[datetime | None] = mapped_column(DateTime)
end_time: Mapped[datetime | None] = mapped_column(DateTime)
status: Mapped[str] = mapped_column(String(16), nullable=False)
reason: Mapped[str | None] = mapped_column(String(128))
+56
View File
@@ -0,0 +1,56 @@
"""memory_unit 客户长期记忆主体表 ORM 模型。"""
from __future__ import annotations
from datetime import datetime
from decimal import Decimal
from typing import Any
from sqlalchemy import BigInteger, DateTime, Integer, JSON, Numeric, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column
from model.base import Base
class MemoryUnit(Base):
"""客户长期记忆主体,向量和关系索引保存在外部库。"""
__tablename__ = "memory_unit"
__table_args__ = {"comment": "客户长期记忆主体表"}
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
customer_id: Mapped[int] = mapped_column(BigInteger, nullable=False)
session_id: Mapped[str | None] = mapped_column(String(64))
agent_run_id: Mapped[str | None] = mapped_column(String(64))
memory_type: Mapped[str] = mapped_column(String(32), nullable=False)
tag: Mapped[str] = mapped_column(String(64), nullable=False)
content: Mapped[str] = mapped_column(String(512), nullable=False)
info_type: Mapped[str] = mapped_column(String(8), nullable=False)
source: Mapped[str] = mapped_column(String(32), nullable=False)
evidence_ref: Mapped[list[dict[str, Any]] | None] = mapped_column(JSON)
source_confidence: Mapped[Decimal] = mapped_column(Numeric(5, 2), server_default="0.20")
confidence: Mapped[Decimal] = mapped_column(Numeric(5, 2), server_default="0.20")
historical_accuracy: Mapped[Decimal] = mapped_column(Numeric(5, 2), server_default="0.50")
confidence_version: Mapped[str | None] = mapped_column(String(32))
confidence_reason: Mapped[str | None] = mapped_column(String(255))
confidence_update_time: Mapped[datetime | None] = mapped_column(DateTime)
evidence_count: Mapped[int] = mapped_column(Integer, server_default="0")
conflict_count: Mapped[int] = mapped_column(Integer, server_default="0")
recall_count: Mapped[int] = mapped_column(Integer, server_default="0")
memory_version: Mapped[int] = mapped_column(Integer, server_default="1")
update_time: Mapped[datetime | None] = mapped_column(DateTime)
last_recall_time: Mapped[datetime | None] = mapped_column(DateTime)
create_time: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
status: Mapped[str] = mapped_column(String(16), server_default="candidate")
valid_from: Mapped[datetime | None] = mapped_column(DateTime)
valid_until: Mapped[datetime | None] = mapped_column(DateTime)
last_verified_at: Mapped[datetime | None] = mapped_column(DateTime)
milvus_id: Mapped[str | None] = mapped_column(String(128))
graph_node_id: Mapped[str | None] = mapped_column(String(128))
milvus_sync_status: Mapped[str] = mapped_column(String(16), server_default="pending")
neo4j_sync_status: Mapped[str] = mapped_column(String(16), server_default="pending")
sync_retry_count: Mapped[int] = mapped_column(Integer, server_default="0")
last_sync_error: Mapped[str | None] = mapped_column(String(500))
next_retry_at: Mapped[datetime | None] = mapped_column(DateTime)
last_synced_at: Mapped[datetime | None] = mapped_column(DateTime)