fix(agent): add memory config validation and fix config id reference
- Add null check for actual_config_id before calling term_memory_save in langchain_agent.py to prevent errors when memory config is unavailable - Add warning log when skipping term_memory_save due to missing memory config - Fix incorrect attribute reference from memory_config.id to memory_config.config_id in memory_agent_service.py - Fix method call from private _get_workspace_default_config to public get_workspace_default_config in memory_config_service.py - Ensures graceful handling of missing memory configurations and prevents runtime errors
This commit is contained in:
@@ -512,7 +512,10 @@ class LangChainAgent:
|
|||||||
# AI 回复写入(用户消息和 AI 回复配对,一次性写入完整对话)
|
# AI 回复写入(用户消息和 AI 回复配对,一次性写入完整对话)
|
||||||
await self.write(storage_type, actual_end_user_id, message_chat, content, user_rag_memory_id, actual_end_user_id, actual_config_id)
|
await self.write(storage_type, actual_end_user_id, message_chat, content, user_rag_memory_id, actual_end_user_id, actual_config_id)
|
||||||
'''长期'''
|
'''长期'''
|
||||||
await self.term_memory_save(long_term_messages,actual_config_id,end_user_id,"chunk")
|
if actual_config_id:
|
||||||
|
await self.term_memory_save(long_term_messages,actual_config_id,end_user_id,"chunk")
|
||||||
|
else:
|
||||||
|
logger.warning(f"Skipping term_memory_save: no memory config available for end_user {end_user_id}")
|
||||||
response = {
|
response = {
|
||||||
"content": content,
|
"content": content,
|
||||||
"model": self.model_name,
|
"model": self.model_name,
|
||||||
@@ -698,7 +701,10 @@ class LangChainAgent:
|
|||||||
# AI 回复写入(用户消息和 AI 回复配对,一次性写入完整对话)
|
# AI 回复写入(用户消息和 AI 回复配对,一次性写入完整对话)
|
||||||
long_term_messages = await agent_chat_messages(message_chat, full_content)
|
long_term_messages = await agent_chat_messages(message_chat, full_content)
|
||||||
await self.write(storage_type, end_user_id, message_chat, full_content, user_rag_memory_id, end_user_id, actual_config_id)
|
await self.write(storage_type, end_user_id, message_chat, full_content, user_rag_memory_id, end_user_id, actual_config_id)
|
||||||
await self.term_memory_save(long_term_messages, actual_config_id, end_user_id, "chunk")
|
if actual_config_id:
|
||||||
|
await self.term_memory_save(long_term_messages, actual_config_id, end_user_id, "chunk")
|
||||||
|
else:
|
||||||
|
logger.warning(f"Skipping term_memory_save: no memory config available for end_user {end_user_id}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Agent astream_events 失败: {str(e)}", exc_info=True)
|
logger.error(f"Agent astream_events 失败: {str(e)}", exc_info=True)
|
||||||
|
|||||||
@@ -1194,7 +1194,7 @@ def get_end_user_connected_config(end_user_id: str, db: Session) -> Dict[str, An
|
|||||||
workspace_id=app.workspace_id
|
workspace_id=app.workspace_id
|
||||||
)
|
)
|
||||||
|
|
||||||
memory_config_id = str(memory_config.id) if memory_config else None
|
memory_config_id = str(memory_config.config_id) if memory_config else None
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
"end_user_id": str(end_user_id),
|
"end_user_id": str(end_user_id),
|
||||||
|
|||||||
@@ -525,7 +525,7 @@ class MemoryConfigService:
|
|||||||
"No memory config ID provided, using workspace default",
|
"No memory config ID provided, using workspace default",
|
||||||
extra={"workspace_id": str(workspace_id)}
|
extra={"workspace_id": str(workspace_id)}
|
||||||
)
|
)
|
||||||
return self._get_workspace_default_config(workspace_id)
|
return self.get_workspace_default_config(workspace_id)
|
||||||
|
|
||||||
config = self.db.get(MemoryConfigModel, memory_config_id)
|
config = self.db.get(MemoryConfigModel, memory_config_id)
|
||||||
|
|
||||||
@@ -540,7 +540,7 @@ class MemoryConfigService:
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return self._get_workspace_default_config(workspace_id)
|
return self.get_workspace_default_config(workspace_id)
|
||||||
|
|
||||||
def delete_config(
|
def delete_config(
|
||||||
self,
|
self,
|
||||||
|
|||||||
Reference in New Issue
Block a user