Skip to content

feat(memory): background graph extraction and agent loop integration #1227

@bug-ops

Description

@bug-ops

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) — spawns tokio::spawn with tokio::time::timeout(extraction_timeout_secs). The spawned task clones Arc<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, call spawn_graph_extraction() if config.memory.graph.enabled.
  • Tool output messages (save_only()) are NOT extracted (too noisy, low entity density).

In crates/zeph-core/src/agent/context.rs:

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 StatusUpdate channel 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    corezeph-core crateenhancementNew feature or requestgraph-memoryKnowledge graph memory featurememoryzeph-memory crate (SQLite)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions