perf(memory): store memories asynchronously to prevent blocking
Some checks failed
Build and Push Docker / build-and-push (push) Failing after 3m3s

This commit is contained in:
gameloader
2025-10-13 09:44:26 +08:00
parent 2b2a40919b
commit 7fcbbe2f02

View File

@ -126,7 +126,7 @@ In your response, consider the memories above to provide a personalized answer."
assistant_response = response.choices[0].message.content assistant_response = response.choices[0].message.content
# Step 5: Store the interaction as new memories # Step 5: Store the interaction as new memories (异步执行)
messages = [ messages = [
{"role": "user", "content": user_input}, {"role": "user", "content": user_input},
{"role": "assistant", "content": assistant_response} {"role": "assistant", "content": assistant_response}
@ -138,7 +138,16 @@ In your response, consider the memories above to provide a personalized answer."
"type": "chat_interaction" "type": "chat_interaction"
} }
# 异步存储记忆,不阻塞主流程
def store_memory_async():
try:
self.add_memory(messages, user_id, metadata) self.add_memory(messages, user_id, metadata)
except Exception as e:
print(f"[WARNING] Async memory storage failed: {e}")
# 启动异步线程存储记忆
memory_thread = threading.Thread(target=store_memory_async, daemon=True)
memory_thread.start()
return { return {
"success": True, "success": True,