feat: support memory import and export (#1521)

* feat: support memory import and export

* fix(memory): address review feedback

* style: format memory settings page

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
This commit is contained in:
Admire
2026-03-30 17:25:47 +08:00
committed by GitHub
parent 2330c38209
commit 9a557751d6
14 changed files with 604 additions and 27 deletions
+29 -3
View File
@@ -7,6 +7,7 @@ from deerflow.agents.memory.updater import (
clear_memory_data,
create_memory_fact,
delete_memory_fact,
import_memory_data,
update_memory_fact,
)
from deerflow.config.memory_config import MemoryConfig
@@ -233,6 +234,31 @@ def test_delete_memory_fact_raises_for_unknown_id() -> None:
raise AssertionError("Expected KeyError for missing fact id")
def test_import_memory_data_saves_and_returns_imported_memory() -> None:
imported_memory = _make_memory(
facts=[
{
"id": "fact_import",
"content": "User works on DeerFlow.",
"category": "context",
"confidence": 0.87,
"createdAt": "2026-03-20T00:00:00Z",
"source": "manual",
}
]
)
mock_storage = MagicMock()
mock_storage.save.return_value = True
mock_storage.load.return_value = imported_memory
with patch("deerflow.agents.memory.updater.get_memory_storage", return_value=mock_storage):
result = import_memory_data(imported_memory)
mock_storage.save.assert_called_once_with(imported_memory, None)
mock_storage.load.assert_called_once_with(None)
assert result == imported_memory
def test_update_memory_fact_updates_only_matching_fact() -> None:
current_memory = _make_memory(
facts=[
@@ -349,7 +375,7 @@ def test_update_memory_fact_rejects_invalid_confidence() -> None:
# ---------------------------------------------------------------------------
# _extract_text LLM response content normalization
# _extract_text - LLM response content normalization
# ---------------------------------------------------------------------------
@@ -409,7 +435,7 @@ class TestExtractText:
# ---------------------------------------------------------------------------
# format_conversation_for_update handles mixed list content
# format_conversation_for_update - handles mixed list content
# ---------------------------------------------------------------------------
@@ -439,7 +465,7 @@ class TestFormatConversationForUpdate:
# ---------------------------------------------------------------------------
# update_memory structured LLM response handling
# update_memory - structured LLM response handling
# ---------------------------------------------------------------------------