feat(memory): refactor config resolution to always retrieve workspace_id fallback
This commit is contained in:
@@ -291,19 +291,23 @@ class MemoryAgentService:
|
|||||||
ValueError: If config loading fails or write operation fails
|
ValueError: If config loading fails or write operation fails
|
||||||
"""
|
"""
|
||||||
# Resolve config_id and workspace_id
|
# Resolve config_id and workspace_id
|
||||||
|
# Always get workspace_id from end_user for fallback, even if config_id is provided
|
||||||
workspace_id = None
|
workspace_id = None
|
||||||
if config_id is None:
|
try:
|
||||||
try:
|
connected_config = get_end_user_connected_config(end_user_id, db)
|
||||||
connected_config = get_end_user_connected_config(end_user_id, db)
|
workspace_id = connected_config.get("workspace_id")
|
||||||
|
if config_id is None:
|
||||||
config_id = connected_config.get("memory_config_id")
|
config_id = connected_config.get("memory_config_id")
|
||||||
workspace_id = connected_config.get("workspace_id")
|
logger.info(f"Resolved config from end_user: config_id={config_id}, workspace_id={workspace_id}")
|
||||||
if config_id is None and workspace_id is None:
|
if config_id is None and workspace_id is None:
|
||||||
raise ValueError(f"No memory configuration found for end_user {end_user_id}. Please ensure the user has a connected memory configuration.")
|
raise ValueError(f"No memory configuration found for end_user {end_user_id}. Please ensure the user has a connected memory configuration.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if "No memory configuration found" in str(e):
|
if "No memory configuration found" in str(e):
|
||||||
raise # Re-raise our specific error
|
raise # Re-raise our specific error
|
||||||
logger.error(f"Failed to get connected config for end_user {end_user_id}: {e}")
|
logger.error(f"Failed to get connected config for end_user {end_user_id}: {e}")
|
||||||
|
if config_id is None:
|
||||||
raise ValueError(f"Unable to determine memory configuration for end_user {end_user_id}: {e}")
|
raise ValueError(f"Unable to determine memory configuration for end_user {end_user_id}: {e}")
|
||||||
|
# If config_id was provided, continue without workspace_id fallback
|
||||||
|
|
||||||
import time
|
import time
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
@@ -421,19 +425,23 @@ class MemoryAgentService:
|
|||||||
ori_message= message
|
ori_message= message
|
||||||
|
|
||||||
# Resolve config_id and workspace_id
|
# Resolve config_id and workspace_id
|
||||||
|
# Always get workspace_id from end_user for fallback, even if config_id is provided
|
||||||
workspace_id = None
|
workspace_id = None
|
||||||
if config_id is None:
|
try:
|
||||||
try:
|
connected_config = get_end_user_connected_config(end_user_id, db)
|
||||||
connected_config = get_end_user_connected_config(end_user_id, db)
|
workspace_id = connected_config.get("workspace_id")
|
||||||
|
if config_id is None:
|
||||||
config_id = connected_config.get("memory_config_id")
|
config_id = connected_config.get("memory_config_id")
|
||||||
workspace_id = connected_config.get("workspace_id")
|
logger.info(f"Resolved config from end_user: config_id={config_id}, workspace_id={workspace_id}")
|
||||||
if config_id is None and workspace_id is None:
|
if config_id is None and workspace_id is None:
|
||||||
raise ValueError(f"No memory configuration found for end_user {end_user_id}. Please ensure the user has a connected memory configuration.")
|
raise ValueError(f"No memory configuration found for end_user {end_user_id}. Please ensure the user has a connected memory configuration.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if "No memory configuration found" in str(e):
|
if "No memory configuration found" in str(e):
|
||||||
raise # Re-raise our specific error
|
raise # Re-raise our specific error
|
||||||
logger.error(f"Failed to get connected config for end_user {end_user_id}: {e}")
|
logger.error(f"Failed to get connected config for end_user {end_user_id}: {e}")
|
||||||
|
if config_id is None:
|
||||||
raise ValueError(f"Unable to determine memory configuration for end_user {end_user_id}: {e}")
|
raise ValueError(f"Unable to determine memory configuration for end_user {end_user_id}: {e}")
|
||||||
|
# If config_id was provided, continue without workspace_id fallback
|
||||||
|
|
||||||
logger.info(f"Read operation for group {end_user_id} with config_id {config_id}")
|
logger.info(f"Read operation for group {end_user_id} with config_id {config_id}")
|
||||||
|
|
||||||
@@ -729,21 +737,24 @@ class MemoryAgentService:
|
|||||||
Returns:
|
Returns:
|
||||||
生成的答案文本
|
生成的答案文本
|
||||||
"""
|
"""
|
||||||
if config_id is None:
|
# Always get workspace_id from end_user for fallback, even if config_id is provided
|
||||||
try:
|
workspace_id = None
|
||||||
connected_config = get_end_user_connected_config(end_user_id, db)
|
try:
|
||||||
|
connected_config = get_end_user_connected_config(end_user_id, db)
|
||||||
|
workspace_id = connected_config.get('workspace_id')
|
||||||
|
if config_id is None:
|
||||||
config_id = connected_config.get('memory_config_id')
|
config_id = connected_config.get('memory_config_id')
|
||||||
workspace_id = connected_config.get('workspace_id')
|
logger.info(f"Resolved config from end_user: config_id={config_id}, workspace_id={workspace_id}")
|
||||||
if config_id is None and workspace_id is None:
|
if config_id is None and workspace_id is None:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"No memory configuration found for end_user {end_user_id}. Please ensure the user has a connected memory configuration.")
|
f"No memory configuration found for end_user {end_user_id}. Please ensure the user has a connected memory configuration.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if "No memory configuration found" in str(e):
|
if "No memory configuration found" in str(e):
|
||||||
raise # Re-raise our specific error
|
raise # Re-raise our specific error
|
||||||
logger.error(f"Failed to get connected config for end_user {end_user_id}: {e}")
|
logger.error(f"Failed to get connected config for end_user {end_user_id}: {e}")
|
||||||
|
if config_id is None:
|
||||||
raise ValueError(f"Unable to determine memory configuration for end_user {end_user_id}: {e}")
|
raise ValueError(f"Unable to determine memory configuration for end_user {end_user_id}: {e}")
|
||||||
else:
|
# If config_id was provided, continue without workspace_id fallback
|
||||||
workspace_id = None
|
|
||||||
|
|
||||||
logger.info(f"Generating summary from retrieve info for query: {query[:50]}...")
|
logger.info(f"Generating summary from retrieve info for query: {query[:50]}...")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user