Skip to content

feat(memory): add delete fact and clear all memory endpoints#1436

Open
mvanhorn wants to merge 1 commit intobytedance:mainfrom
mvanhorn:osc/1333-memory-management-api
Open

feat(memory): add delete fact and clear all memory endpoints#1436
mvanhorn wants to merge 1 commit intobytedance:mainfrom
mvanhorn:osc/1333-memory-management-api

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

Summary

Adds memory management capabilities. The backend API now supports deleting individual facts and clearing all memory. The frontend memory settings page gets interactive delete buttons per fact and a "Clear All Memory" button with confirmation dialog.

Why this matters

Issue #1333 requests memory clearing/management. The current API only supports reading memory data (GET /api/memory) and reloading from file (POST /api/memory/reload). There is no way to delete facts or reset memory. The settings page renders memory as read-only markdown.

Changes

Backend (harness layer - deerflow.*)

  • delete_memory_fact(fact_id) in updater.py - removes a single fact by ID, returns False if not found
  • clear_memory() in updater.py - resets memory to empty state via _create_empty_memory() + _save_memory_to_file()

Backend (app layer - app.*)

  • DELETE /api/memory/facts/{fact_id} - returns 200 on success, 404 if fact not found
  • DELETE /api/memory - clears all memory, returns the empty state

Frontend

  • deleteMemoryFact() and clearAllMemory() API functions in core/memory/api.ts
  • useDeleteFact() and useClearMemory() TanStack Query mutation hooks with cache invalidation
  • Interactive FactsTable component replaces the markdown table - each row has a trash icon button
  • "Clear All Memory" button with confirmation dialog at the top of the memory section

Testing

6 unit tests covering:

  • Delete existing fact (verifies removal + other facts preserved)
  • Delete nonexistent fact (returns False, no side effects)
  • Delete from empty facts list
  • Clear resets to empty state (all sections zeroed)
  • Clear updates lastUpdated timestamp
  • Clear when already empty (idempotent)

Harness boundary test passes - no app.* imports in deerflow.*.

Video Demo

Demo

Fixes #1333

This contribution was developed with AI assistance (Claude Code).

Add memory management capabilities to the backend API and frontend settings page:

Backend:
- DELETE /api/memory/facts/{fact_id} - delete a single fact by ID
- DELETE /api/memory - clear all memory data (reset to empty state)
- delete_memory_fact() and clear_memory() functions in updater.py

Frontend:
- Interactive facts table with per-row trash icon delete buttons
- "Clear All Memory" button with confirmation dialog
- TanStack Query mutations with automatic cache invalidation

Tests:
- 6 unit tests covering delete, clear, edge cases

Fixes bytedance#1333

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add Memory Management / Clearing Function in Settings

1 participant