-
Notifications
You must be signed in to change notification settings - Fork 2
feat(memory): background graph extraction and agent loop integration #1227
Copy link
Copy link
Closed
Labels
corezeph-core cratezeph-core crateenhancementNew feature or requestNew feature or requestgraph-memoryKnowledge graph memory featureKnowledge graph memory featurememoryzeph-memory crate (SQLite)zeph-memory crate (SQLite)
Description
Summary
Phase 4 of graph memory (#1222): non-blocking background extraction wired into the agent loop, with TUI spinner support.
Depends on: #1223 (Arc-wrap prerequisite), #1226 (retrieval)
Tasks
1. Background Extraction in SemanticMemory
Add to SemanticMemory:
spawn_graph_extraction(message: &str, context: &[Message], episode_id: MessageId)— spawnstokio::spawnwithtokio::time::timeout(extraction_timeout_secs). The spawned task clonesArc<EmbeddingStore>,AnyProvider(already Clone),SqlitePool(already Clone). On timeout or error, logs warning and silently degrades.
2. Agent Loop Integration
In crates/zeph-core/src/agent/persistence.rs:
- After
remember_with_parts()stores a user message, callspawn_graph_extraction()ifconfig.memory.graph.enabled. - Tool output messages (
save_only()) are NOT extracted (too noisy, low entity density).
In crates/zeph-core/src/agent/context.rs:
- In the
FuturesUnorderedcontext preparation (from refactor(memory): Arc-wrap EmbeddingStore and FuturesUnordered context preparation #1223 refactor), add aGraphFactsfetcher gated by#[cfg(feature = "graph-memory")]. - Call
graph_recall()from Phase 3. - Inject as system message with
GRAPH_FACTS_PREFIXat appropriate position.
3. TUI Status Spinner
When graph extraction is running in background:
- Set status: "Extracting entities..." with spinner
- On completion: clear status (or show "Extracted 3 entities, 5 edges")
- Use existing
StatusUpdatechannel pattern from TUI
4. Extraction Counter Persistence
Increment extraction_count in graph_metadata table after each successful extraction. Used by Phase 5 to trigger community refresh when count % community_refresh_interval == 0.
Architecture Reference
See .local/plan/graph-memory-architecture.md Section 6 for Arc-wrapping details, spawning pattern, and context builder integration.
Acceptance Criteria
- Background extraction does not block agent response
- Extraction timeout (15s default) degrades gracefully (warning log, no error to user)
- TUI shows extraction spinner during processing
- Tool output messages skipped (not extracted)
- Extraction counter persisted in graph_metadata
- Graph facts appear in context when entities exist
- ~13 tests (10 unit + 3 integration)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
corezeph-core cratezeph-core crateenhancementNew feature or requestNew feature or requestgraph-memoryKnowledge graph memory featureKnowledge graph memory featurememoryzeph-memory crate (SQLite)zeph-memory crate (SQLite)