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
View File
@@ -8,6 +8,7 @@ from deerflow.agents.memory.updater import (
create_memory_fact,
delete_memory_fact,
get_memory_data,
import_memory_data,
reload_memory_data,
update_memory_fact,
)
@@ -248,6 +249,34 @@ async def update_memory_fact_endpoint(fact_id: str, request: FactPatchRequest) -
return MemoryResponse(**memory_data)
@router.get(
"/memory/export",
response_model=MemoryResponse,
summary="Export Memory Data",
description="Export the current global memory data as JSON for backup or transfer.",
)
async def export_memory() -> MemoryResponse:
"""Export the current memory data."""
memory_data = get_memory_data()
return MemoryResponse(**memory_data)
@router.post(
"/memory/import",
response_model=MemoryResponse,
summary="Import Memory Data",
description="Import and overwrite the current global memory data from a JSON payload.",
)
async def import_memory(request: MemoryResponse) -> MemoryResponse:
"""Import and persist memory data."""
try:
memory_data = import_memory_data(request.model_dump())
except OSError as exc:
raise HTTPException(status_code=500, detail="Failed to import memory data.") from exc
return MemoryResponse(**memory_data)
@router.get(
"/memory/config",
response_model=MemoryConfigResponse,