From 520c0352b55034f4b061e3b866f20ff77d341d8a Mon Sep 17 00:00:00 2001 From: Nan Gao <88081804+ggnnggez@users.noreply.github.com> Date: Sat, 28 Mar 2026 17:00:11 +0800 Subject: [PATCH] fix(middleware): fall back to configurable thread_id in MemoryMiddleware (#1425) (#1426) * fix(middleware): fall back to configurable thread_id in MemoryMiddleware (#1425) * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Willem Jiang Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../deerflow/agents/middlewares/memory_middleware.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/packages/harness/deerflow/agents/middlewares/memory_middleware.py b/backend/packages/harness/deerflow/agents/middlewares/memory_middleware.py index 31d339f..90907b6 100644 --- a/backend/packages/harness/deerflow/agents/middlewares/memory_middleware.py +++ b/backend/packages/harness/deerflow/agents/middlewares/memory_middleware.py @@ -6,6 +6,7 @@ from typing import Any, override from langchain.agents import AgentState from langchain.agents.middleware import AgentMiddleware +from langgraph.config import get_config from langgraph.runtime import Runtime from deerflow.agents.memory.queue import get_memory_queue @@ -122,8 +123,11 @@ class MemoryMiddleware(AgentMiddleware[MemoryMiddlewareState]): if not config.enabled: return None - # Get thread ID from runtime context + # Get thread ID from runtime context first, then fall back to LangGraph's configurable metadata thread_id = runtime.context.get("thread_id") if runtime.context else None + if thread_id is None: + config_data = get_config() + thread_id = config_data.get("configurable", {}).get("thread_id") if not thread_id: logger.debug("No thread_id in context, skipping memory update") return None