Bridge heartbeat Persona recall into prompts

This commit is contained in:
Meta Vens 2026-06-21 17:01:58 +01:00
commit 540e1e22aa
4 changed files with 119 additions and 41 deletions

View file

@ -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"
);
}

View file

@ -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;

View file

@ -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(

Binary file not shown.