refactor(memory): restructure memory system and improve configuration management

- Remove deprecated main.py entry point from memory module
- Reorganize imports across controllers and services for consistency
- Update emotion controller to pass db session instead of config_id to services
- Enhance memory agent controller with db session parameter for status_type and user_profile endpoints
- Refactor memory agent service to accept db parameter in classify_message_type method
- Improve configuration handling in celery_app by removing automatic database reload
- Update all memory-related services to use centralized config management
- Standardize import ordering and remove unused imports across 50+ files
- Add pilot_run_service for new pilot execution workflow
- Refactor extraction engine, reflection engine, and search services for better modularity
- Update LLM utilities and embedder configuration for improved flexibility
- Enhance type classifier and verification tools with better error handling
- Improve memory evaluation modules (LOCOMO, LongMemEval, MemSciQA) with consistent patterns
This commit is contained in:
Ke Sun
2025-12-23 17:17:04 +08:00
parent 258b88276f
commit 283c64a358
58 changed files with 2171 additions and 1797 deletions

View File

@@ -176,7 +176,7 @@ def read_message_task(self, group_id: str, message: str, history: List[Dict[str,
"""Celery task to process a read message via MemoryAgentService.
Args:
group_id: Group ID for the memory agent
group_id: Group ID for the memory agent (also used as end_user_id)
message: User message to process
history: Conversation history
search_switch: Search switch parameter
@@ -190,9 +190,28 @@ def read_message_task(self, group_id: str, message: str, history: List[Dict[str,
"""
start_time = time.time()
# Resolve config_id if None
actual_config_id = config_id
if actual_config_id is None:
try:
from app.services.memory_agent_service import get_end_user_connected_config
db = next(get_db())
try:
connected_config = get_end_user_connected_config(group_id, db)
actual_config_id = connected_config.get("memory_config_id")
finally:
db.close()
except Exception as e:
# Log but continue - will fail later with proper error
pass
async def _run() -> str:
service = MemoryAgentService()
return await service.read_memory(group_id, message, history, search_switch, config_id,storage_type,user_rag_memory_id)
db = next(get_db())
try:
service = MemoryAgentService()
return await service.read_memory(group_id, message, history, search_switch, actual_config_id, db, storage_type, user_rag_memory_id)
finally:
db.close()
try:
# 使用 nest_asyncio 来避免事件循环冲突
@@ -246,7 +265,7 @@ def write_message_task(self, group_id: str, message: str, config_id: str,storage
"""Celery task to process a write message via MemoryAgentService.
Args:
group_id: Group ID for the memory agent
group_id: Group ID for the memory agent (also used as end_user_id)
message: Message to write
config_id: Optional configuration ID
@@ -258,9 +277,28 @@ def write_message_task(self, group_id: str, message: str, config_id: str,storage
"""
start_time = time.time()
# Resolve config_id if None
actual_config_id = config_id
if actual_config_id is None:
try:
from app.services.memory_agent_service import get_end_user_connected_config
db = next(get_db())
try:
connected_config = get_end_user_connected_config(group_id, db)
actual_config_id = connected_config.get("memory_config_id")
finally:
db.close()
except Exception as e:
# Log but continue - will fail later with proper error
pass
async def _run() -> str:
service = MemoryAgentService()
return await service.write_memory(group_id, message, config_id,storage_type,user_rag_memory_id)
db = next(get_db())
try:
service = MemoryAgentService()
return await service.write_memory(group_id, message, actual_config_id, db, storage_type, user_rag_memory_id)
finally:
db.close()
try:
# 使用 nest_asyncio 来避免事件循环冲突