From b6b3650e50feff7ffae4fec91786ecb6be760a3d Mon Sep 17 00:00:00 2001 From: Airene Fang Date: Wed, 20 May 2026 22:34:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(trace):memory=20=E4=B8=AD=E6=96=87=20in=20t?= =?UTF-8?q?race=20info=20is=20unicode=20escape=20sequence.=20(#3104)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(trace):memory 中文 in trace is unicode * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../harness/deerflow/agents/memory/updater.py | 2 +- backend/tests/test_memory_updater.py | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/backend/packages/harness/deerflow/agents/memory/updater.py b/backend/packages/harness/deerflow/agents/memory/updater.py index 6e55330a1..2007a97e2 100644 --- a/backend/packages/harness/deerflow/agents/memory/updater.py +++ b/backend/packages/harness/deerflow/agents/memory/updater.py @@ -338,7 +338,7 @@ class MemoryUpdater: reinforcement_detected=reinforcement_detected, ) prompt = MEMORY_UPDATE_PROMPT.format( - current_memory=json.dumps(current_memory, indent=2), + current_memory=json.dumps(current_memory, indent=2, ensure_ascii=False), conversation=conversation_text, correction_hint=correction_hint, ) diff --git a/backend/tests/test_memory_updater.py b/backend/tests/test_memory_updater.py index 03d135564..038cec627 100644 --- a/backend/tests/test_memory_updater.py +++ b/backend/tests/test_memory_updater.py @@ -78,6 +78,41 @@ def test_apply_updates_skips_existing_duplicate_and_preserves_removals() -> None assert all(fact["id"] != "fact_remove" for fact in result["facts"]) +def test_prepare_update_prompt_preserves_non_ascii_memory_text() -> None: + updater = MemoryUpdater() + current_memory = _make_memory( + facts=[ + { + "id": "fact_cn", + "content": "Deer-flow是一个非常好的框架。", + "category": "context", + "confidence": 0.9, + "createdAt": "2026-05-20T00:00:00Z", + "source": "thread-cn", + }, + ] + ) + + with ( + patch("deerflow.agents.memory.updater.get_memory_config", return_value=_memory_config(enabled=True)), + patch("deerflow.agents.memory.updater.get_memory_data", return_value=current_memory), + ): + msg = MagicMock() + msg.type = "human" + msg.content = "你好" + prepared = updater._prepare_update_prompt( + [msg], + agent_name=None, + correction_detected=False, + reinforcement_detected=False, + ) + + assert prepared is not None + _, prompt = prepared + assert "Deer-flow是一个非常好的框架。" in prompt + assert "\\u" not in prompt + + def test_apply_updates_skips_same_batch_duplicates_and_keeps_source_metadata() -> None: updater = MemoryUpdater() current_memory = _make_memory()