feat: surface memex PersonalContext in orchestrator system prompt#286
Merged
toadkicker merged 1 commit intomainfrom Apr 14, 2026
Merged
feat: surface memex PersonalContext in orchestrator system prompt#286toadkicker merged 1 commit intomainfrom
toadkicker merged 1 commit intomainfrom
Conversation
Introduces `PersonalContext` — a compact JSON-LD preamble synthesised from EpisodeDB history, AgentProfile aggregates, and the optional TraitBeacon Person document — and injects it into the orchestrator's LLM calls via a `tokio::sync::watch` channel. ### What changes **`crates/papillon-shared`** - New `personal_context.rs` (native-gated): `PersonalContext` struct, `EpisodeSummary`, `AgentSummary`, `from_db()`, `to_system_preamble()` (`[PAP PERSONAL CONTEXT]…[END PAP CONTEXT]` sentinels), `is_empty()`. Six unit tests covering cap, ordering, JSON-LD validity, trait filtering. - `lib.rs`: export `personal_context` + `PersonalContext` (native only). **`apps/papillon`** - `state.rs`: add `context_tx: watch::Sender<String>` and `trait_beacon_profile: Arc<RwLock<Value>>` to `AppState`. `with_db()` loads the trait profile from DB, builds the initial preamble, and passes the receiver to `OnDeviceAiExecutor::new`. - `agents/on_device_ai.rs`: accepts `watch::Receiver<String>`, borrows the latest preamble lazily at call time and prepends it to the `[INST]` prompt when non-empty. Two new unit tests. - `inference.rs`: `build_orchestrator_prompt_with_template` gains `context: Option<&str>`; prepends the block when `Some` and non-empty. Two new tests; existing test updated to pass `None`. - `commands/episodes.rs`: `record_episode` gains `State<AppState>` and pushes a fresh preamble to `context_tx` after persisting. - `commands/orchestrator.rs`: same preamble push after scenario episode insertion. - `commands/agents.rs`: new `save_trait_beacon_profile` Tauri command — validates `@type == "Person"`, persists to DB setting, updates in-memory Arc, pushes preamble. - `lib.rs`: register `save_trait_beacon_profile`. - `commands/llm.rs`: pass `None` to the probe call (no personal context needed for capability probing). All 365 tests pass (241 papillon-shared, 124 papillon). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Benchmark Regression ReportThreshold: 10% regression vs baseline from main |
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
PersonalContext— a compact JSON-LD preamble built from EpisodeDB history,AgentProfileaggregates, and the user's TraitBeacon Person documenttokio::sync::watchchannel; consumers borrow the latest preamble lazily at call time (zero polling overhead)OnDeviceAiExecutor+build_orchestrator_prompt_with_templateonly.pap-agents/DynamicAgentHandlerare untouched.save_trait_beacon_profilelets the frontend persist the user's Schema.org Person document; triggers an immediate preamble refreshKey files
crates/papillon-shared/src/personal_context.rs(new)apps/papillon/src/state.rs—context_txwatch sender +trait_beacon_profileArcapps/papillon/src/agents/on_device_ai.rs— lazy preamble injectapps/papillon/src/inference.rs—context: Option<&str>paramapps/papillon/src/commands/episodes.rs/orchestrator.rs— push after writeapps/papillon/src/commands/agents.rs—save_trait_beacon_profilecommandTest plan
[PAP PERSONAL CONTEXT]block appears inRUST_LOG=debugoutputsave_trait_beacon_profilewith@type: "Person"persists and refreshes preamble🤖 Generated with Claude Code