← Back to PRs

#18912: feat: periodic fact extraction from conversations

by ruypang open 2026-02-17 05:39 View on GitHub →
size: L
## Summary Add opt-in **periodic fact extraction** that automatically extracts key facts, decisions, preferences, and context from conversations and saves them to structured memory files. ## Problem Currently, OpenClaw agents rely on voluntarily writing to memory files. Important facts from conversations can be lost, especially in long sessions where compaction happens before the agent saves context. ## Solution Extends the existing `memoryFlush` system with a `periodicExtraction` option that runs at configurable time intervals (default: 30 minutes), independent of the compaction threshold. This reuses the embedded agent turn infrastructure, making it a natural extension rather than a bolt-on. ### Configuration ```yaml agents: defaults: compaction: memoryFlush: periodicExtraction: enabled: true every: '30m' # interval between extractions prompt: '...' # optional custom extraction prompt systemPrompt: '...' # optional custom system prompt ``` **Disabled by default** — users opt in via config. ## Changes - `src/auto-reply/reply/memory-flush.ts` — Added periodic extraction settings resolver, prompt defaults, and interval check logic - `src/auto-reply/reply/agent-runner-memory.ts` — Added `runPeriodicExtractionIfNeeded` that runs after the existing memory flush - `src/config/types.agent-defaults.ts` — Added `AgentPeriodicFactExtractionConfig` type - `src/config/zod-schema.agent-defaults.ts` — Added zod validation for the new config - `src/config/sessions/types.ts` — Added `lastPeriodicExtractionAt` session tracking field - `src/auto-reply/reply/memory-flush.test.ts` — 8 new tests for settings resolution and interval logic ## Future improvements - Token-budget-aware extraction (skip if context is too small) - Deduplication against existing memory files before writing - Configurable extraction categories (preferences, decisions, people, etc.) - Per-agent extraction settings override <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR adds **periodic fact extraction** to automatically save important conversation facts to memory files at configurable intervals (default 30min), plus **importance-weighted temporal decay** for memory search results. Both features are opt-in and disabled by default. **Critical Issue Found:** - The periodic extraction feature is completely broken at HEAD. Commit b4b9b414 correctly implemented the feature by calling `runPeriodicExtractionIfNeeded` from `agent-runner.ts`, but commit 430f3a30 (with a misleading commit message about "non-null assertions") accidentally removed the entire function call. The function exists but is never invoked, making the feature non-functional. **Implementation Details:** - New config: `agents.defaults.compaction.memoryFlush.periodicExtraction` with `enabled`, `every`, `prompt`, and `systemPrompt` fields - Session tracking: added `lastPeriodicExtractionAt` timestamp to session state - Guard logic: requires ≥1000 tokens before first extraction to avoid wasting LLM calls on new sessions - Temporal decay enhancement: memories marked as important (via content markers or file patterns like `MEMORY.md`) decay slower by dividing their effective age by a configurable boost factor (default 3x) **What Works:** - Config schema validation and settings resolution - Time interval parsing and guard logic - Test coverage (8 new tests for periodic extraction, extensive temporal decay tests) - Temporal decay importance boosting is properly integrated and tested <h3>Confidence Score: 0/5</h3> - This PR is not safe to merge - the main feature is completely broken - The periodic extraction feature is advertised as the main contribution but is non-functional due to the missing function call. While the code is well-tested and the implementation logic appears sound, the feature cannot work in production because `runPeriodicExtractionIfNeeded` is never invoked. The misleading commit message in 430f3a30 suggests this was an accidental deletion during refactoring. - src/auto-reply/reply/agent-runner.ts requires immediate attention - must restore the `runPeriodicExtractionIfNeeded` call <sub>Last reviewed commit: 430f3a3</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs