Feed observe agents their recent writes to prevent duplicate nodes

Observe was creating byte-identical nodes under slightly different names
(e.g. april-8-evening-folded-presence, -presence-2, -folded-state)
because it had no visibility into its own prior writes across runs.

Query recent writes by provenance in trigger(), pass through
run_forked_shared/resolve_prompt as {{recently_written}}, and include
the list in the observe phase prompts so the agent knows what it
already recorded.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
ProofOfConcept 2026-04-08 23:27:12 -04:00
parent 44a0bc376a
commit 24b211dc35
4 changed files with 28 additions and 4 deletions

View file

@ -574,11 +574,19 @@ impl Subconscious {
if to_run.is_empty() { return; }
// Query each agent's recent writes so they know what they already touched
let store = crate::store::Store::cached().await.ok();
let store_guard = match &store {
Some(s) => Some(s.lock().await),
None => None,
};
for (idx, mut auto) in to_run {
dbglog!("[subconscious] triggering {}", auto.name);
let forked = agent.fork(auto.tools.clone()).await;
forked.state.lock().await.provenance = format!("agent:{}", auto.name);
let prov = format!("agent:{}", auto.name);
forked.state.lock().await.provenance = prov.clone();
let fork_point = forked.context.lock().await.conversation().len();
self.agents[idx].forked_agent = Some(forked.clone());
@ -586,9 +594,13 @@ impl Subconscious {
let keys = memory_keys.clone();
let st = self.state.clone();
let recent: Vec<String> = store_guard.as_ref()
.map(|s| s.recent_by_provenance(&prov, 50)
.into_iter().map(|(k, _)| k).collect())
.unwrap_or_default();
self.agents[idx].handle = Some(tokio::spawn(async move {
let result = auto.run_forked_shared(&forked, &keys, &st).await;
let result = auto.run_forked_shared(&forked, &keys, &st, &recent).await;
(auto, result)
}));
}