Backend:
- New /api/v1/agents/{id}/memory endpoints: CRUD for global_knowledge,
knowledge_entities, learning_patterns, vector_memories + import/export
- Fix scope_id column overflow: 3 model columns expanded to hold compound
keys (user_id:agent_id format, 73 chars vs old VARCHAR(36))
- Config: allow unknown env vars (extra="ignore") for optional overrides
Android:
- MemoryManageScreen: 4-tab UI (全局知识/知识实体/学习模式/对话记忆)
with search, delete, and FAB to add new entries
- Import/export via ShareSheet and file picker
- AgentListScreen: long-press dropdown menu → 记忆管理 entry point
- NavGraph: memory_manage/{agentId}/{agentName} route with URL encoding
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
"""
|
|
Agent 向量记忆模型。
|
|
|
|
存储对话片段的 embedding 向量,支持语义检索。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import Column, String, Text, DateTime, Index
|
|
from sqlalchemy.dialects.mysql import JSON as MySQLJSON
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class AgentVectorMemory(Base):
|
|
"""Agent 向量记忆 — 存储对话文本及 embedding"""
|
|
|
|
__tablename__ = "agent_vector_memories"
|
|
|
|
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
scope_kind = Column(String(16), nullable=False, index=True, comment="作用域类型: agent / bare")
|
|
scope_id = Column(String(255), nullable=False, index=True, comment="作用域 ID: agent_id / user_id")
|
|
session_key = Column(String(128), nullable=False, default="", comment="会话标识")
|
|
content_text = Column(Text, nullable=False, comment="原始对话文本")
|
|
embedding = Column(Text, nullable=True, comment="JSON 序列化的 embedding 向量")
|
|
metadata_ = Column("metadata", MySQLJSON, nullable=True, comment="元数据: {type, iteration, ...}")
|
|
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
|
|
__table_args__ = (
|
|
Index("ix_agent_vector_memory_scope", "scope_kind", "scope_id"),
|
|
)
|
|
|
|
def to_dict(self) -> dict:
|
|
return {
|
|
"id": self.id,
|
|
"scope_kind": self.scope_kind,
|
|
"scope_id": self.scope_id,
|
|
"session_key": self.session_key,
|
|
"content_text": self.content_text,
|
|
"embedding": self.embedding,
|
|
"metadata": self.metadata_ or {},
|
|
"created_at": self.created_at.isoformat() if self.created_at else None,
|
|
}
|