enhancement(core): implement functional LearningEngine (#1913)#1929
Merged
enhancement(core): implement functional LearningEngine (#1913)#1929
Conversation
Replace the stub LearningEngine with real behavioral learning: - Add SQLite table `learned_preferences` (migration 036) for cross-session preference persistence with UPSERT semantics - Add `sqlite/preferences.rs` with upsert, load, and watermark-based load functions; enforces key ≤ 128 B / value ≤ 256 B with warn! on truncation - Implement `LearningEngine::tick()`, `should_analyze()`, `mark_analyzed()` to trigger incremental analysis every 5 turns - Implement `Agent::analyze_and_learn()`: reads new `user_corrections` rows since last watermark, runs regex-based preference inference, persists high-confidence facts (Wilson score threshold) to `learned_preferences` - Implement `Agent::inject_learned_preferences()`: loads up to 3 highest- confidence preferences, sanitizes values (strip \\n/\\r), appends to the volatile system prompt block (after <!-- cache:volatile --> to preserve prompt caching, closes #1082 regression risk) - Gate analysis on `LearningConfig::correction_detection` (independent of `LearningConfig::enabled` which controls skill auto-improvement) - Preference inference uses word-boundary anchors to avoid false positives; covers verbosity, format, and language categories - 40 new unit and integration tests; total test count: 6072
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the
LearningEnginestub with real behavioral learning from interaction history.learned_preferences(migration 036) for cross-session preference persistenceuser_correctionsscanning via watermark (every 5 turns whencorrection_detectionis enabled)<!-- cache:volatile -->, preserving prompt caching)\n/\r) with length caps (key ≤ 128 B, value ≤ 256 B)LearningConfig::correction_detection, independent ofLearningConfig::enabledCloses #1913
Test plan
cargo +nightly fmt --check— cleancargo clippy --workspace --features full -- -D warnings— cleancargo nextest run --config-file .github/nextest.toml --workspace --features full --lib --bins— 6072 passed, 12 skipped