The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(agent): retain memory dedupe guidance without index tool
Steven Enamakele94e62023a62
diff --git a/crates/openhuman-core/src/agent/harness/memory_protocol.rs b/crates/openhuman-core/src/agent/harness/memory_protocol.rsindex c86a9c96be..5ec8de78c4 100644--- a/crates/openhuman-core/src/agent/harness/memory_protocol.rs+++ b/crates/openhuman-core/src/agent/harness/memory_protocol.rs@@ -135,6 +135,16 @@ impl MemoryProtocolObservation {/// Render the corrective note appended to the tool result, or `None` when no/// guidance is warranted. The wording escalates with the violations detected.pub fn guidance(&self, tool_name: &str) -> Option<String> {+ self.guidance_with_index_update(tool_name, true)+ }++ /// Keep dedupe guidance when the agent cannot update the index, without+ /// telling it to call a tool absent from its turn.+ pub fn guidance_with_index_update(+ &self,+ tool_name: &str,+ can_update_index: bool,+ ) -> Option<String> {if !self.needs_guidance() {return None;}@@ -146,19 +156,20 @@ impl MemoryProtocolObservation {so you don't store a near-duplicate."));}- if self.index_drift {+ if self.index_drift && can_update_index {parts.push("A previous memory write was never followed by `update_memory_md`, so the MEMORY.md \index is drifting from stored memory. Reconcile it now.".to_string(),);}- // The always-on closing-step reminder: keep the index in sync.- parts.push(- "After mutating memory, call `update_memory_md` to keep the MEMORY.md index in sync."- .to_string(),- );- Some(format!("{MEMORY_PROTOCOL_MARKER} {}", parts.join(" ")))+ if can_update_index {+ parts.push(+ "After mutating memory, call `update_memory_md` to keep the MEMORY.md index in sync."+ .to_string(),+ );+ }+ (!parts.is_empty()).then(|| format!("{MEMORY_PROTOCOL_MARKER} {}", parts.join(" ")))}}diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rsindex 625a47120e..57c833ab6e 100644--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs@@ -334,15 +334,14 @@ pub(super) fn assemble_turn_harness(// dedupe read or leaves the index stale. Pushed ahead of every other// result-rewriting middleware so its `after_tool` runs *after* the byte-cap// truncation, keeping the note.- // The closing-step reminder must only run when this agent can call the- // index-update tool. Otherwise a direct memory write would instruct it to- // call a tool that is absent from its turn.- if allowed+ // Dedupe guidance stays active; only the closing-step reminder depends on+ // whether this turn can call the index-update tool.+ let can_update_index = allowed.as_ref()- .is_none_or(|names| names.contains("update_memory_md"))- {- harness.push_middleware(Arc::new(middleware::MemoryProtocolMiddleware::new()));- }+ .is_none_or(|names| names.contains("update_memory_md"));+ harness.push_middleware(Arc::new(+ middleware::MemoryProtocolMiddleware::with_index_update_tool(can_update_index),+ ));// Repeated-failure circuit breaker: pause the run when a tool returns the same// error `REPEATED_TOOL_FAILURE_THRESHOLD` times in a row, so a deterministicdiff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/memory_protocol.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/memory_protocol.rsindex 2abd1d0f7a..51a49fe983 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/memory_protocol.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/memory_protocol.rs@@ -24,6 +24,7 @@ use tinytools::ToolResult as TaToolResult;/// neither creates an entry nor obliges an index update. Non-memory tools are/// ignored, so this is a no-op on turns that never touch memory.pub struct MemoryProtocolMiddleware {+ can_update_index: bool,tracker: std::sync::Mutex<crate::agent::harness::memory_protocol::MemoryProtocolTracker>,/// call_id → classified op, captured in `before_tool` (the tool result carries/// no arguments, yet `update_memory_md` and `memory_tree` can only be@@ -36,7 +37,12 @@ pub struct MemoryProtocolMiddleware {impl MemoryProtocolMiddleware {pub fn new() -> Self {+ Self::with_index_update_tool(true)+ }++ pub fn with_index_update_tool(can_update_index: bool) -> Self {Self {+ can_update_index,tracker: std::sync::Mutex::new(crate::agent::harness::memory_protocol::MemoryProtocolTracker::new(),),@@ -108,7 +114,8 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>};tracker.observe(op)};- if let Some(note) = observation.guidance(tool_name) {+ if let Some(note) = observation.guidance_with_index_update(tool_name, self.can_update_index)+ {tracing::debug!(tool = tool_name,missing_index_read = observation.missing_index_read,diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rsindex 685b8249f5..03e6ba2b66 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rs@@ -608,6 +608,19 @@ async fn memory_write_without_index_read_gets_a_corrective_note() {assert!(result_text(&result).starts_with("stored entry 42"));}+#[tokio::test]+async fn memory_write_without_index_tool_still_gets_dedupe_guidance() {+ let mw = MemoryProtocolMiddleware::with_index_update_tool(false);+ let result = run_cycle(&mw, "memory_store", json!({}), "stored entry", None).await;+ let text = result_text(&result);+ assert!(text.contains("without first reading the memory index"));+ assert!(!text.contains("update_memory_md"));++ run_cycle(&mw, "memory_recall", json!({}), "found entry", None).await;+ let after_read = run_cycle(&mw, "memory_store", json!({}), "stored another", None).await;+ assert!(!result_text(&after_read).contains("update_memory_md"));+}+#[tokio::test]async fn full_cycle_read_then_write_then_update_only_reminds_on_the_write() {let mw = MemoryProtocolMiddleware::new();