From 540e1e22aa3fdf840c47b7960357897678e24e7f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 21 Jun 2026 17:01:58 +0100 Subject: [PATCH] Bridge heartbeat Persona recall into prompts --- .../epiphany-persona-memory-recall-smoke.rs | 104 +++++++++++------- epiphany-core/src/lib.rs | 1 + epiphany-core/src/persona_turn.rs | 55 +++++++++ state/ledgers.msgpack | Bin 378822 -> 379243 bytes 4 files changed, 119 insertions(+), 41 deletions(-) diff --git a/epiphany-core/src/bin/epiphany-persona-memory-recall-smoke.rs b/epiphany-core/src/bin/epiphany-persona-memory-recall-smoke.rs index 0799bc54..09adc401 100644 --- a/epiphany-core/src/bin/epiphany-persona-memory-recall-smoke.rs +++ b/epiphany-core/src/bin/epiphany-persona-memory-recall-smoke.rs @@ -17,13 +17,15 @@ use epiphany_core::build_persona_projector_prompt; use epiphany_core::build_persona_turn_prompt; use epiphany_core::render_persona_memory_recall_with_cache; use epiphany_core::render_persona_semantic_memory_recall; +use epiphany_core::semantic_memory_recall_from_heartbeat_action; use epiphany_state_model::EpiphanyMemoryContextPacket; use epiphany_state_model::EpiphanyMemoryFreshnessStatus; use epiphany_state_model::EpiphanyMemoryNode; use epiphany_state_model::EpiphanyMemorySummary; +use serde_json::json; fn main() { - let recall = render_persona_semantic_memory_recall(&EpiphanyMemoryContextPacket { + let fallback_recall = render_persona_semantic_memory_recall(&EpiphanyMemoryContextPacket { id: "memctx-persona-smoke".to_string(), query_id: "persona-smoke-current-turn".to_string(), summaries: vec![EpiphanyMemorySummary { @@ -50,45 +52,6 @@ fn main() { ..Default::default() }); - let identity = PersonaIdentity { - identity_id: "epiphany".to_string(), - display_name: "Epiphany".to_string(), - repo_name: "EpiphanyAgent".to_string(), - public_description: "Repo Persona for typed agent substrate.".to_string(), - jurisdiction: vec!["typed state and review-gated agency".to_string()], - }; - - let projector_prompt = build_persona_projector_prompt(&PersonaProjectorInput { - identity: identity.clone(), - semantic_memory_recall: recall.clone(), - ..Default::default() - }); - assert_contains(&projector_prompt, "Semantic memory recall"); - assert_contains(&projector_prompt, "typed memory graph"); - assert_contains(&projector_prompt, "not durable authority"); - - let persona_prompt = build_persona_turn_prompt(&PersonaTurnInput { - identity: identity.clone(), - projected_state: "Epiphany feels the mouth edge as a public contract, not a vent." - .to_string(), - semantic_memory_recall: recall.clone(), - ..Default::default() - }); - assert_contains(&persona_prompt, "Semantic memory recall"); - assert_contains(&persona_prompt, "VoidBot rebuilds semantic Persona recall"); - - let interpreter_prompt = build_persona_interpreter_prompt(&PersonaInterpreterInput { - identity, - persona_prompt, - persona_output: "I can speak, but the effect needs a receipt.".to_string(), - semantic_memory_recall: recall, - pending_mentions: Vec::new(), - allowed_channel_ids: vec!["aquarium".to_string()], - }); - assert_contains(&interpreter_prompt, "Dynamic semantic memory recall"); - assert_contains(&interpreter_prompt, "STATE NOTE"); - assert_contains(&interpreter_prompt, "SAY"); - let chunks = build_persona_memory_chunks(&persona_memory_entry(), "state/agents.msgpack#Persona"); assert!( @@ -109,6 +72,17 @@ fn main() { Some(&EpiphanyMemoryContextPacket { id: "memctx-smoke-fallback".to_string(), query_id: "persona-smoke-fallback".to_string(), + summaries: vec![EpiphanyMemorySummary { + id: "summary-smoke-fallback".to_string(), + target: "role:Persona".to_string(), + claim: fallback_recall, + action_implication: + "This fallback is heartbeat-carried context, not direct state authority." + .to_string(), + freshness: EpiphanyMemoryFreshnessStatus::Ready, + confidence: 80, + ..Default::default() + }], nodes: vec![EpiphanyMemoryNode { id: "node-smoke-fallback".to_string(), title: "Smoke fallback memory".to_string(), @@ -136,9 +110,57 @@ fn main() { .rendered_recall .contains("Fallback typed memory graph context") ); + let heartbeat_action = json!({ + "action_type": "persona_turn", + "persona_memory_recall": { + "privateStateExposed": false, + "renderedRecall": bridge.rendered_recall, + } + }); + let recall = semantic_memory_recall_from_heartbeat_action(&heartbeat_action); + assert_contains(&recall, "Fallback typed memory graph context"); + + let identity = PersonaIdentity { + identity_id: "epiphany".to_string(), + display_name: "Epiphany".to_string(), + repo_name: "EpiphanyAgent".to_string(), + public_description: "Repo Persona for typed agent substrate.".to_string(), + jurisdiction: vec!["typed state and review-gated agency".to_string()], + }; + + let projector_prompt = build_persona_projector_prompt(&PersonaProjectorInput { + identity: identity.clone(), + semantic_memory_recall: recall.clone(), + ..Default::default() + }); + assert_contains(&projector_prompt, "Semantic memory recall"); + assert_contains(&projector_prompt, "typed memory graph"); + assert_contains(&projector_prompt, "not durable authority"); + + let persona_prompt = build_persona_turn_prompt(&PersonaTurnInput { + identity: identity.clone(), + projected_state: "Epiphany feels the mouth edge as a public contract, not a vent." + .to_string(), + semantic_memory_recall: recall.clone(), + ..Default::default() + }); + assert_contains(&persona_prompt, "Semantic memory recall"); + assert_contains(&persona_prompt, "Fallback typed memory graph context"); + + let interpreter_prompt = build_persona_interpreter_prompt(&PersonaInterpreterInput { + identity, + persona_prompt, + persona_output: "I can speak, but the effect needs a receipt.".to_string(), + semantic_memory_recall: recall, + pending_mentions: Vec::new(), + allowed_channel_ids: vec!["aquarium".to_string()], + }); + assert_contains(&interpreter_prompt, "Dynamic semantic memory recall"); + assert_contains(&interpreter_prompt, "STATE NOTE"); + assert_contains(&interpreter_prompt, "SAY"); println!( - "status=ok recallSource=typed-memory-graph qdrantCache=persona-memory-bridge-wired liveQdrant=not-required personaLayers=projector,persona,interpreter privateStateExposed=false" + "status=ok recallSource=typed-memory-graph qdrantCache=persona-memory-bridge-wired heartbeatRecall=prompt-wired liveQdrant=not-required personaLayers=projector,persona,interpreter privateStateExposed=false" ); } diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index 6f18cdeb..ea93a07b 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -631,6 +631,7 @@ pub use persona_turn::build_persona_projector_prompt; pub use persona_turn::build_persona_turn_prompt; pub use persona_turn::persona_projected_surface_is_clean; pub use persona_turn::render_persona_semantic_memory_recall; +pub use persona_turn::semantic_memory_recall_from_heartbeat_action; pub use promotion::EpiphanyPromotionDecision; pub use promotion::EpiphanyPromotionInput; pub use promotion::EpiphanyStateReplacementValidationInput; diff --git a/epiphany-core/src/persona_turn.rs b/epiphany-core/src/persona_turn.rs index 012fccb0..f6be7ce3 100644 --- a/epiphany-core/src/persona_turn.rs +++ b/epiphany-core/src/persona_turn.rs @@ -6,6 +6,7 @@ use crate::render_organ_dependencies; use epiphany_state_model::EpiphanyMemoryContextPacket; use serde::Deserialize; use serde::Serialize; +use serde_json::Value; pub const PERSONA_PROJECTOR_PROMPT_SCHEMA_VERSION: &str = "epiphany.imagination_persona_projector_prompt.v0"; @@ -306,6 +307,32 @@ pub fn render_persona_semantic_memory_recall(packet: &EpiphanyMemoryContextPacke lines.join("\n") } +pub fn semantic_memory_recall_from_heartbeat_action(action: &Value) -> String { + let Some(recall) = action + .get("persona_memory_recall") + .or_else(|| action.get("personaMemoryRecall")) + else { + return "- semantic memory recall unavailable in heartbeat action; do not pretend it ran" + .to_string(); + }; + + if recall.get("privateStateExposed").and_then(Value::as_bool) != Some(false) { + return "- semantic memory recall refused: heartbeat action did not carry a private-state seal" + .to_string(); + } + + recall + .get("renderedRecall") + .and_then(Value::as_str) + .map(str::trim) + .filter(|value| !value.is_empty()) + .map(ToString::to_string) + .unwrap_or_else(|| { + "- semantic memory recall unavailable in heartbeat action; do not pretend it ran" + .to_string() + }) +} + pub fn persona_projected_surface_is_clean(surface: &str) -> bool { let forbidden = [ "STATE NOTE", @@ -477,6 +504,7 @@ mod tests { use epiphany_state_model::EpiphanyMemoryFreshnessStatus; use epiphany_state_model::EpiphanyMemoryNode; use epiphany_state_model::EpiphanyMemorySummary; + use serde_json::json; fn identity() -> PersonaIdentity { PersonaIdentity { @@ -615,6 +643,33 @@ mod tests { assert!(interpreter.contains("SAY")); } + #[test] + fn heartbeat_action_recall_extracts_only_when_private_state_is_sealed() { + let action = json!({ + "persona_memory_recall": { + "privateStateExposed": false, + "renderedRecall": "Derived Qdrant Persona recall; hints only." + } + }); + assert_eq!( + semantic_memory_recall_from_heartbeat_action(&action), + "Derived Qdrant Persona recall; hints only." + ); + + let leaking_action = json!({ + "persona_memory_recall": { + "privateStateExposed": true, + "renderedRecall": "sealed private note" + } + }); + let refused = semantic_memory_recall_from_heartbeat_action(&leaking_action); + assert!(refused.contains("refused")); + assert!(!refused.contains("sealed private note")); + + let missing = semantic_memory_recall_from_heartbeat_action(&json!({})); + assert!(missing.contains("unavailable")); + } + #[test] fn projected_surface_rejects_side_effect_syntax() { assert!(persona_projected_surface_is_clean( diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 9f4d46120e40d239121b1dd3b2794eba56400c4e..19114e2ee72ab1da872501b8c1a56c705a8dd6ba 100644 GIT binary patch delta 410 zcmX|+u};G<5Qa%1Y%tP+-~Ipcsr~!hemjWv&iW_4{^|M6ax4D1ct476qv-K|-g=m~ zB0uYY+t1F&ycPGp7pt#$e>YfOUjGhf^%YsC6@sG*70V1Ns6JvE{7zS2~A@#uoQp&YeKvSa~xeYcA*fe0%+*?x*n*~~m8B47?{%T&Y zZMAZQC5f)Fa*Rxga=Wgzc4lo-vSm~h_jUfTP`KB_2kd4aI6$mQjn5}a0K)IODo5r{!FGZ3?EpUT8) GcoYEs3=xt5