修改memory为异步任务

This commit is contained in:
朱潮 2026-01-21 21:10:44 +08:00
parent 45f3a61a16
commit 8daa37c4c7
2 changed files with 5 additions and 10 deletions

View File

@ -11,6 +11,7 @@ from langgraph.runtime import Runtime
from .mem0_config import Mem0Config from .mem0_config import Mem0Config
from .mem0_manager import Mem0Manager, get_mem0_manager from .mem0_manager import Mem0Manager, get_mem0_manager
import asyncio
logger = logging.getLogger("app") logger = logging.getLogger("app")
@ -123,8 +124,6 @@ class Mem0Middleware(AgentMiddleware):
return None return None
try: try:
import asyncio
# 提取用户查询 # 提取用户查询
query = self._extract_user_query(state) query = self._extract_user_query(state)
if not query: if not query:
@ -224,8 +223,6 @@ class Mem0Middleware(AgentMiddleware):
return return
try: try:
import asyncio
# 触发后台增强任务 # 触发后台增强任务
asyncio.create_task(self._trigger_augmentation_async(state, runtime)) asyncio.create_task(self._trigger_augmentation_async(state, runtime))
except Exception as e: except Exception as e:
@ -242,7 +239,7 @@ class Mem0Middleware(AgentMiddleware):
return return
try: try:
await self._trigger_augmentation_async(state, runtime) asyncio.create_task(self._trigger_augmentation_async(state, runtime))
except Exception as e: except Exception as e:
logger.error(f"Error in Mem0Middleware.aafter_agent: {e}") logger.error(f"Error in Mem0Middleware.aafter_agent: {e}")

View File

@ -220,17 +220,15 @@
color: var(--text); color: var(--text);
} }
</style> </style>
<script src="https://unpkg.com/lucide@latest/dist/umd/lucide.js"></script>
<!-- Fonts --> <!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;500;600;700&family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;500;600;700&family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
<!-- Highlight.js --> <!-- Highlight.js -->
<link rel="stylesheet" href="https://cdn.staticfile.net/highlight.js/11.9.0/styles/github.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css">
<script src="https://cdn.staticfile.net/highlight.js/11.9.0/highlight.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<!-- Marked.js --> <!-- Marked.js -->
<script src="https://cdn.staticfile.net/marked/4.3.0/marked.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/marked@4.3.0/marked.min.js"></script>
<!-- Lucide Icons --> <!-- Lucide Icons -->
<script src="https://unpkg.com/lucide@latest/dist/umd/lucide.js"></script> <script src="https://unpkg.com/lucide@latest/dist/umd/lucide.js"></script>