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(prompt): give a delegated agent the memory write rule; time the fold
Shanu4b3af351e427
diff --git a/src/openhuman/agent/harness/archivist/recap.rs b/src/openhuman/agent/harness/archivist/recap.rsindex 0474e21685..31932d778b 100644--- a/src/openhuman/agent/harness/archivist/recap.rs+++ b/src/openhuman/agent/harness/archivist/recap.rs@@ -268,13 +268,21 @@ impl ArchivistHook {"[archivist] summarize_entries: LLM recap segment={segment_id} entries={}",entries.len());+ // #6200: timed because this await is on the turn path — the+ // caller's `flush_open_segment` is awaited before a turn+ // returns — and the only bound under it today is+ // tinyinference's 600s request default. The measurement is+ // what a deadline should be chosen from; logging it first+ // means the number comes from real folds rather than a guess.+ let started = std::time::Instant::now();let summary_result = fold_through_driver(&corpus_inputs, &summary_ctx).await;+ let elapsed_ms = started.elapsed().as_millis();match summary_result {Ok(output) if !output.content.is_empty() => {tracing::debug!("[archivist] summarize_entries: LLM recap ok segment={segment_id} \- chars={}",+ chars={} elapsed_ms={elapsed_ms}",output.content.len());return (output.content, true);@@ -282,13 +290,14 @@ impl ArchivistHook {Ok(_) => {tracing::debug!("[archivist] summarize_entries: LLM returned empty — \- heuristic fallback segment={segment_id}"+ heuristic fallback segment={segment_id} elapsed_ms={elapsed_ms}");}Err(e) => {tracing::warn!("[archivist] summarize_entries: LLM recap failed (non-fatal) \- segment={segment_id}: {e} — heuristic fallback"+ segment={segment_id} elapsed_ms={elapsed_ms}: {e} — \+ heuristic fallback");}}diff --git a/src/openhuman/agent/harness/session/builder/helpers.rs b/src/openhuman/agent/harness/session/builder/helpers.rsindex c99fcde2e8..13b114d53f 100644--- a/src/openhuman/agent/harness/session/builder/helpers.rs+++ b/src/openhuman/agent/harness/session/builder/helpers.rs@@ -121,7 +121,7 @@ pub(super) fn add_memory_prompt_sections() -> SystemPromptBuilder {use crate::openhuman::agent::learning::{any_tool_offered, MemoryAccessSection, MemoryWriteSection, MEMORY_READ_TOOLS,- MEMORY_STORE_TOOL, SAVE_PREFERENCE_TOOL,+ MEMORY_STORE_TOOL, MEMORY_WRITE_DELEGATE_TOOL, SAVE_PREFERENCE_TOOL,};let mut prompt_builder = prompt_builder;if any_tool_offered(&MEMORY_READ_TOOLS, tools, delegation_tools, visible) {@@ -138,17 +138,31 @@ pub(super) fn add_memory_prompt_sections(// about the other (review finding).let preferences = any_tool_offered(&[SAVE_PREFERENCE_TOOL], tools, delegation_tools, visible);let facts = any_tool_offered(&[MEMORY_STORE_TOOL], tools, delegation_tools, visible);- if preferences || facts {- prompt_builder =- prompt_builder.add_section(Box::new(MemoryWriteSection::new(preferences, facts)));+ // #6200: asked for as well as the pair, not instead of it. An agent whose+ // only write path is the delegate held the tool and no rule about using it+ // — the write-side twin of the read-side gap #6183 closed.+ let delegate = any_tool_offered(+ &[MEMORY_WRITE_DELEGATE_TOOL],+ tools,+ delegation_tools,+ visible,+ );+ if preferences || facts || delegate {+ prompt_builder = prompt_builder.add_section(Box::new(MemoryWriteSection::new(+ preferences,+ facts,+ delegate,+ )));log::debug!("[memory_write] prompt section registered for agent={agent_id} \- save_preference={preferences} memory_store={facts}"+ save_preference={preferences} memory_store={facts} \+ manage_profile_memory={delegate}");} else {log::debug!(- "[memory_write] skipping MemoryWriteSection — neither memory_store nor \- save_preference is registered+visible for agent={agent_id}"+ "[memory_write] skipping MemoryWriteSection — none of memory_store, \+ save_preference or manage_profile_memory is registered+visible for \+ agent={agent_id}");}prompt_builderdiff --git a/src/openhuman/agent/learning/mod.rs b/src/openhuman/agent/learning/mod.rsindex 36a15ecbc7..addc33eae4 100644--- a/src/openhuman/agent/learning/mod.rs+++ b/src/openhuman/agent/learning/mod.rs@@ -48,7 +48,8 @@ pub use profile_md_renderer::ProfileMdRenderer;pub use prompt_sections::{any_tool_offered, load_learned_from_cache, memory_write_instruction, LearnedContextSection,MemoryAccessSection, MemoryWriteSection, UserProfileSection, MEMORY_ACCESS_INSTRUCTION,- MEMORY_READ_TOOLS, MEMORY_STORE_TOOL, MEMORY_WRITE_TOOLS, SAVE_PREFERENCE_TOOL,+ MEMORY_READ_TOOLS, MEMORY_STORE_TOOL, MEMORY_WRITE_DELEGATE_TOOL, MEMORY_WRITE_TOOLS,+ SAVE_PREFERENCE_TOOL,};pub use reflection::ReflectionHook;pub use schemas::{diff --git a/src/openhuman/agent/learning/prompt_sections.rs b/src/openhuman/agent/learning/prompt_sections.rsindex 9c6aa17d44..d43257eff3 100644--- a/src/openhuman/agent/learning/prompt_sections.rs+++ b/src/openhuman/agent/learning/prompt_sections.rs@@ -155,14 +155,19 @@ impl PromptSection for MemoryAccessSection {pub struct MemoryWriteSection {preferences: bool,facts: bool,+ delegate: bool,}impl MemoryWriteSection {/// `preferences` = `save_preference` is offered here, `facts` =- /// `memory_store` is.+ /// `memory_store` is, `delegate` = [`MEMORY_WRITE_DELEGATE_TOOL`] is.#[must_use]- pub fn new(preferences: bool, facts: bool) -> Self {- Self { preferences, facts }+ pub fn new(preferences: bool, facts: bool, delegate: bool) -> Self {+ Self {+ preferences,+ facts,+ delegate,+ }}}@@ -173,11 +178,14 @@ impl MemoryWriteSection {/// Empty when neither tool is offered — which is also when nothing registers/// the section, so the empty string is a guard, not a path in normal use.#[must_use]-pub fn memory_write_instruction(preferences: bool, facts: bool) -> String {+pub fn memory_write_instruction(preferences: bool, facts: bool, delegate: bool) -> String {let route = match (preferences, facts) {(true, true) => "— `save_preference` for preferences, `memory_store` for everything else",(true, false) => "with `save_preference`",(false, true) => "with `memory_store`",+ // Only when neither direct tool is held, so an agent that has one+ // renders exactly the text it rendered before this arm existed.+ (false, false) if delegate => "with `manage_profile_memory`",(false, false) => return String::new(),};format!(@@ -195,7 +203,11 @@ impl PromptSection for MemoryWriteSection {}fn build(&self, _ctx: &PromptContext<'_>) -> Result<String> {- Ok(memory_write_instruction(self.preferences, self.facts))+ Ok(memory_write_instruction(+ self.preferences,+ self.facts,+ self.delegate,+ ))}}@@ -220,6 +232,22 @@ pub const SAVE_PREFERENCE_TOOL: &str = "save_preference";/// The tool every other remembered fact is written through.pub const MEMORY_STORE_TOOL: &str = "memory_store";+/// The delegate an agent writes through when it holds neither direct write+/// tool.+///+/// Synthesised from `profile_memory_agent`'s `delegate_name`, and the write-side+/// counterpart of `retrieve_memory` in [`MEMORY_READ_TOOLS`]. The orchestrator+/// is configured this way: its visible set carries this delegate and neither+/// [`MEMORY_STORE_TOOL`] nor [`SAVE_PREFERENCE_TOOL`], so keying the section on+/// the direct pair alone dropped the rule for the agent that needed it most —+/// the #6048 case, "got it, saved" with no tool call behind it.+///+/// The section's promise survives the indirection: `profile_memory_agent` is a+/// synchronous `worker`-tier sub-agent holding **both** direct tools, so a+/// delegated write reaches the same store and completes inside the parent's+/// turn.+pub const MEMORY_WRITE_DELEGATE_TOOL: &str = "manage_profile_memory";+/// The writing tools [`MemoryWriteSection`] is keyed on.pub const MEMORY_WRITE_TOOLS: [&str; 2] = [MEMORY_STORE_TOOL, SAVE_PREFERENCE_TOOL];diff --git a/src/openhuman/agent/learning/prompt_sections_tests_2_tests.rs b/src/openhuman/agent/learning/prompt_sections_tests_2_tests.rsindex 769001c38f..8da5144166 100644--- a/src/openhuman/agent/learning/prompt_sections_tests_2_tests.rs+++ b/src/openhuman/agent/learning/prompt_sections_tests_2_tests.rs@@ -332,19 +332,22 @@ fn visible(names: &[&str]) -> HashSet<String> {#[test]fn memory_write_section_states_the_rule_the_bug_needed() {- let section = MemoryWriteSection::new(true, true);+ let section = MemoryWriteSection::new(true, true, false);assert_eq!(section.name(), "memory_write");let rendered = section.build(&prompt_context(LearnedContextData::default())).unwrap();- assert_eq!(rendered.trim(), memory_write_instruction(true, true).trim());+ assert_eq!(+ rendered.trim(),+ memory_write_instruction(true, true, false).trim()+ );assert!(rendered.contains("## Remembering"), "{rendered}");assert!(rendered.contains("Never say saved"),"the instruction must forbid claiming a save that did not happen: {rendered}");// Not context-gated: it renders for an empty learned context too.- let empty = MemoryWriteSection::new(true, true)+ let empty = MemoryWriteSection::new(true, true, false).build(&prompt_context(LearnedContextData::default())).unwrap();assert!(!empty.trim().is_empty());@@ -355,13 +358,13 @@ fn memory_write_section_states_the_rule_the_bug_needed() {/// registering the section with no write tool at all.#[test]fn memory_write_instruction_names_only_the_offered_tools() {- let both = memory_write_instruction(true, true);+ let both = memory_write_instruction(true, true, false);assert!(both.contains("`save_preference`") && both.contains("`memory_store`"),"{both}");- let preferences_only = memory_write_instruction(true, false);+ let preferences_only = memory_write_instruction(true, false, false);assert!(preferences_only.contains("`save_preference`"),"{preferences_only}"@@ -371,7 +374,7 @@ fn memory_write_instruction_names_only_the_offered_tools() {"a session without memory_store must not be sent to it: {preferences_only}");- let facts_only = memory_write_instruction(false, true);+ let facts_only = memory_write_instruction(false, true, false);assert!(facts_only.contains("`memory_store`"), "{facts_only}");assert!(!facts_only.contains("`save_preference`"),@@ -395,8 +398,8 @@ fn memory_write_instruction_names_only_the_offered_tools() {/// a tool the session lacks.#[test]fn memory_write_instruction_is_empty_without_a_write_tool() {- assert!(memory_write_instruction(false, false).is_empty());- let rendered = MemoryWriteSection::new(false, false)+ assert!(memory_write_instruction(false, false, false).is_empty());+ let rendered = MemoryWriteSection::new(false, false, false).build(&prompt_context(LearnedContextData::default())).unwrap();assert!(rendered.is_empty(), "{rendered}");@@ -462,3 +465,95 @@ fn write_tool_gate_counts_delegation_tools_and_either_write_tool() {&visible(&[])));}++// ── The write rule reaches a delegated agent (#6200) ─────────────────────────++/// An agent whose only write path is the delegate gets the rule, and the rule+/// names the delegate.+///+/// This is the write-side twin of the gap #6183 closed on the read side. The+/// orchestrator is configured exactly this way — its visible set carries+/// `manage_profile_memory` and neither direct tool — so before this it held a+/// write path and no rule about using it: the #6048 case, "got it, saved" with+/// no tool call behind it.+///+/// Naming matters as much as presence. Pointing it at `memory_store`, a tool it+/// cannot see, is the failure `any_tool_offered` exists to prevent.+#[test]+fn a_delegate_only_agent_gets_the_write_rule_naming_the_delegate() {+ let delegate = named(&[MEMORY_WRITE_DELEGATE_TOOL]);+ let none: Vec<Box<dyn Tool>> = Vec::new();++ assert!(+ any_tool_offered(+ &[MEMORY_WRITE_DELEGATE_TOOL],+ &delegate,+ &none,+ &visible(&[])+ ),+ "the gate must see the delegate"+ );++ let rendered = memory_write_instruction(false, false, true);+ assert!(+ rendered.contains(MEMORY_WRITE_DELEGATE_TOOL),+ "the rule must name the delegate: {rendered}"+ );+ for absent in [MEMORY_STORE_TOOL, SAVE_PREFERENCE_TOOL] {+ assert!(+ !rendered.contains(absent),+ "the rule named `{absent}`, which a delegate-only agent cannot see: {rendered}"+ );+ }+}++/// An agent holding a direct write tool renders exactly what it rendered before+/// the delegate arm existed.+///+/// The regression that would matter most here is a silent prompt change for+/// every agent that was already working, so the delegate flag is asserted to be+/// inert whenever either direct tool is present.+#[test]+fn a_direct_write_tool_renders_the_same_text_with_or_without_the_delegate() {+ for (preferences, facts) in [(true, true), (true, false), (false, true)] {+ assert_eq!(+ memory_write_instruction(preferences, facts, false),+ memory_write_instruction(preferences, facts, true),+ "the delegate flag changed the text for ({preferences}, {facts})"+ );+ }+ // And the no-write case is still empty rather than falling into the+ // delegate arm by accident.+ assert!(memory_write_instruction(false, false, false).is_empty());+}++/// Read and write both admit their delegate, and neither list admits the+/// other's.+///+/// #6183 fixed the read side and left the write side behind; the two drifting+/// apart is what produced a half-fixed release. Pinning both directions here+/// makes that specific mistake fail a test rather than ship.+#[test]+fn read_and_write_rules_are_symmetric_about_their_delegates() {+ let none: Vec<Box<dyn Tool>> = Vec::new();+ let readers = named(&["retrieve_memory"]);+ let writers = named(&[MEMORY_WRITE_DELEGATE_TOOL]);++ assert!(+ any_tool_offered(&MEMORY_READ_TOOLS, &readers, &none, &visible(&[])),+ "the read list must admit its delegate"+ );+ assert!(+ !any_tool_offered(&MEMORY_READ_TOOLS, &writers, &none, &visible(&[])),+ "the read list must not admit the write delegate"+ );+ assert!(+ !any_tool_offered(+ &[MEMORY_WRITE_DELEGATE_TOOL],+ &readers,+ &none,+ &visible(&[])+ ),+ "the write delegate must not be satisfied by the read delegate"+ );+}