Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

Merge upstream/main into fix/6048-remember-writes-memory

Shanu21574eaf3e32
diff --cc docs/TEST-COVERAGE-MATRIX.md
index 6e55471825,bf60ddda3c..d4e1a87a2a
--- a/docs/TEST-COVERAGE-MATRIX.md
+++ b/docs/TEST-COVERAGE-MATRIX.md
@@@ -351,7 -351,9 +351,10 @@@ End-to-end coverage of the agent harnes
| 8.4.4 | Same-Topic Contradiction (replace) | RU | `src/openhuman/agent/tools/save_preference_tests.rs::recategorising_moves_pref_between_namespaces` | ✅ | `ON CONFLICT REPLACE`; a topic lives in exactly one scope |
| 8.4.5 | Cross-Topic Contradiction Surfacing | RU | `src/openhuman/agent/tools/save_preference_tests.rs::save_surfaces_related_preference_for_contradiction_check` | ✅ | Related prefs surfaced in the tool result for the chat agent to resolve |
| 8.4.6 | vector_chunks Model-Signature Recall Guard | RU | `src/openhuman/memory/store/namespace_store/query_tests.rs::vector_recall_excludes_other_model_signature` | ✅ | Excludes cross-model vectors; dim-guards legacy rows |
- | 8.4.10 | Memory-Write Instruction + `memory_store` defaults | RU | `src/openhuman/agent/learning/prompt_sections_tests_2_tests.rs::memory_write_*`, `src/openhuman/agent/learning/prompt_sections_tests_2_tests.rs::write_tool_gate_*`, `src/openhuman/agent/harness/session/builder/builder_tests_part_01_tests.rs::memory_write_instruction_*`, `src/openhuman/memory/tools/store_tests.rs::resolve_*` | ✅ | #6048: "remember X" must be a write before the reply; section keyed on write-tool visibility, not `learning.enabled`; `memory_store` namespace/key optional |
+ | 8.4.7 | Lane C — Auto-recall of User Facts (gated) | RU | `src/openhuman/memory/auto_recall/{gate_tests,auto_recall_tests}.rs`, `src/openhuman/agent/harness/session/turn_tests_part_05_tests.rs::auto_recall_*` | ✅ | #6040: lexical gate, bounded `fast_retrieve` via the guard, block rides the user message; `hooks.auto_recall` switch |
+ | 8.4.8 | Lane C Boot Warm-up | RU | `src/openhuman/memory/auto_recall/warm_tests.rs` | ✅ | One bounded retrieval after the memory module loads; failure/timeout are log-only |
+ | 8.4.9 | Memory-Access Instruction (ungated) | RU | `src/openhuman/agent/harness/session/builder/builder_tests_part_01_tests.rs::memory_access_instruction_is_present_with_learning_disabled`, `src/openhuman/agent/learning/prompt_sections_tests_2_tests.rs` | ✅ | Added whenever a retrieval tool is visible, independent of `learning.enabled`; forbids claiming absence unsearched |
++| 8.4.10 | Memory-Write Instruction + `memory_store` defaults | RU | `src/openhuman/agent/learning/prompt_sections_tests_2_tests.rs::memory_write_*`, `src/openhuman/agent/learning/prompt_sections_tests_2_tests.rs::write_tool_gate_*`, `src/openhuman/agent/harness/session/builder/builder_tests_part_03_tests.rs::memory_write_instruction_*`, `src/openhuman/memory/tools/store_tests.rs::resolve_*` | ✅ | #6048: "remember X" must be a write before the reply; section keyed on write-tool visibility, not `learning.enabled`; `memory_store` namespace/key optional |
### 8.5 Long-term Goals
diff --cc src/openhuman/agent/harness/session/builder/builder_tests.rs
index 48d8a28002,48d8a28002..6611dfa0ff
--- a/src/openhuman/agent/harness/session/builder/builder_tests.rs
+++ b/src/openhuman/agent/harness/session/builder/builder_tests.rs
@@@ -67,3 -67,3 +67,5 @@@ fn custom_profile
mod part_01_tests;
#[path = "builder_tests_part_02_tests.rs"]
mod part_02_tests;
++#[path = "builder_tests_part_03_tests.rs"]
++mod part_03_tests;
diff --cc src/openhuman/agent/harness/session/builder/builder_tests_part_03_tests.rs
index 0000000000,0000000000..25d5e73f46
new file mode 100644
--- /dev/null
+++ b/src/openhuman/agent/harness/session/builder/builder_tests_part_03_tests.rs
@@@ -1,0 -1,0 +1,110 @@@
++use super::*;
++
++// ── Memory-write instruction (#6048) ─────────────────────────────────────────
++//
++// "Please remember …" was answered with "saved" and zero tool calls. The rule
++// that a request to remember must become a write before the reply is keyed on
++// the write tools being offered — never on `learning.enabled`, which the
++// default install leaves off.
++
++#[tokio::test]
++async fn memory_write_instruction_is_present_with_learning_disabled() {
++ crate::openhuman::memory::host_impls::install_for_tests();
++ use crate::openhuman::agent::context::prompt::LearnedContextData;
++ use crate::openhuman::agent::harness::session::types::Agent;
++
++ let tmp = tempfile::TempDir::new().unwrap();
++ let config = test_config(&tmp);
++ assert!(
++ !config.learning.enabled,
++ "the default install has learning off; the write rule must not depend on it"
++ );
++ let orchestrator = builtin_def("orchestrator");
++ let agent = Agent::build_session_agent_inner(
++ &config,
++ "orchestrator",
++ Some(&orchestrator),
++ None,
++ false,
++ None,
++ )
++ .expect("build session");
++
++ let prompt = agent
++ .build_system_prompt(LearnedContextData::default())
++ .expect("build_system_prompt");
++ assert!(
++ prompt.contains("## Remembering"),
++ "a session offering memory_store / save_preference must carry the write rule"
++ );
++}
++
++#[tokio::test]
++async fn memory_write_instruction_is_absent_when_no_write_tool_is_visible() {
++ crate::openhuman::memory::host_impls::install_for_tests();
++ use crate::openhuman::agent::context::prompt::LearnedContextData;
++ use crate::openhuman::agent::harness::session::types::Agent;
++
++ let tmp = tempfile::TempDir::new().unwrap();
++ let config = test_config(&tmp);
++ let orchestrator = builtin_def("orchestrator");
++ let mut profile = crate::openhuman::agent::profiles::store::built_in_default_profile();
++ profile.id = "alice".to_string();
++ profile.built_in = false;
++ profile.allowed_tools = Some(vec!["file_read".to_string()]);
++
++ let agent = Agent::build_session_agent_inner(
++ &config,
++ "orchestrator",
++ Some(&orchestrator),
++ None,
++ false,
++ Some(&profile),
++ )
++ .expect("build profile-scoped session");
++
++ let prompt = agent
++ .build_system_prompt(LearnedContextData::default())
++ .expect("build_system_prompt");
++ assert!(
++ !prompt.contains("## Remembering"),
++ "a rule about tools the model cannot see would only teach it to apologise"
++ );
++}
++
++/// The live case both reviewers pointed at: `archivist`'s `[tools] named`
++/// scope carries `memory_store` but not `save_preference` (so do
++/// `trigger_reactor` and `workflow_builder`). Naming both routes there would
++/// mandate a tool the session cannot call — the failure the visibility gate
++/// exists to prevent.
++#[tokio::test]
++async fn memory_write_instruction_names_only_the_write_tool_a_scoped_agent_holds() {
++ crate::openhuman::memory::host_impls::install_for_tests();
++ use crate::openhuman::agent::context::prompt::LearnedContextData;
++ use crate::openhuman::agent::harness::session::types::Agent;
++
++ let tmp = tempfile::TempDir::new().unwrap();
++ let config = test_config(&tmp);
++ let archivist = builtin_def("archivist");
++ let agent =
++ Agent::build_session_agent_inner(&config, "archivist", Some(&archivist), None, false, None)
++ .expect("build archivist session");
++
++ let prompt = agent
++ .build_system_prompt(LearnedContextData::default())
++ .expect("build_system_prompt");
++ let block = prompt
++ .split("## Remembering")
++ .nth(1)
++ .expect("the archivist offers memory_store, so the write rule must be present");
++ // Read only this section: other sections may mention other tools.
++ let block = block.split("\n## ").next().unwrap_or(block);
++ assert!(
++ block.contains("`memory_store`"),
++ "the offered write tool must be named: {block}"
++ );
++ assert!(
++ !block.contains("`save_preference`"),
++ "a scope without save_preference must not be routed to it: {block}"
++ );
++}
diff --cc src/openhuman/agent/harness/session/builder/factory.rs
index 2228e54561,729fccb2dd..acb0a5835a
--- a/src/openhuman/agent/harness/session/builder/factory.rs
+++ b/src/openhuman/agent/harness/session/builder/factory.rs
@@@ -978,16 -973,36 +973,15 @@@ impl Agent
}
}
- // Phase 4 (#566): add the MemoryAccessSection bias instruction only
- // when at least one retrieval tool is actually loaded AND survives
- // filtering. We require both because:
- // - the tool may be filtered out by the agent's scope config
- // - the tool may not be registered at all on this agent (tool
- // listing is build-time configurable)
- // An empty `visible` set means "no filter" (wildcard / orchestrator
- // path); in that case any registered retrieval tool is reachable.
- // Not gated on `learning.enabled` (#6040): the instruction is about
- // the memory tools, which exist whether or not learning runs.
- {
- let recall_tools = ["memory_recall", "memory_search"];
- let has_retrieval = recall_tools.iter().any(|name| {
- let registered = tools.iter().any(|t| t.name() == *name)
- || delegation_tools.iter().any(|t| t.name() == *name);
- let allowed_by_filter = visible.is_empty() || visible.contains(*name);
- registered && allowed_by_filter
- });
- if has_retrieval {
- prompt_builder = prompt_builder.add_section(Box::new(
- crate::openhuman::agent::learning::MemoryAccessSection,
- ));
- log::debug!("[memory_access] prompt section registered");
- } else {
- log::debug!(
- "[memory_access] skipping MemoryAccessSection — neither memory_recall nor \
- memory_search is registered+visible for agent={agent_id}"
- );
- }
- }
+ // Memory prompt sections — the read side (#566) and the write side
+ // (#6048); both gates live in `helpers::add_memory_prompt_sections`.
+ prompt_builder = super::helpers::add_memory_prompt_sections(
+ prompt_builder,
- config,
+ &tools,
+ &delegation_tools,
+ &visible,
+ agent_id,
+ );
// De-duplicate: some synthesised tool names may collide with
// already-registered tools (unlikely for `delegate_*` names but
diff --cc src/openhuman/agent/harness/session/builder/helpers.rs
index f8321001d5,f0be2116c7..c99fcde2e8
--- a/src/openhuman/agent/harness/session/builder/helpers.rs
+++ b/src/openhuman/agent/harness/session/builder/helpers.rs
@@@ -21,11 -23,25 +23,29 @@@ use crate::openhuman::memory::tool_memo
use crate::openhuman::memory::Memory;
use std::sync::Arc;
+use crate::openhuman::agent::context::prompt::SystemPromptBuilder;
- use crate::openhuman::config::Config;
+use crate::openhuman::tools::traits::Tool;
+use std::collections::HashSet;
+
+ /// Binds this session's memory subtree once and hands back the two handles
+ /// the factory takes from it: the raw provider the archivist writes through,
+ /// and Lane C (#6040) over the same binding's guard, so the auto-recall reads
+ /// exactly the subtree the session chats against — a dedicated profile recalls
+ /// its own facts, never the shared tree's.
+ pub(super) fn bind_session_memory(
+ config: &crate::openhuman::config::Config,
+ memory_subdir: &str,
+ ) -> anyhow::Result<(Arc<dyn MemoryProvider>, Arc<AutoRecall>)> {
+ let binding = crate::openhuman::memory::binding::for_subtree(
+ &config.workspace_dir,
+ memory_subdir,
+ &config.subsystems.memory,
+ )
+ .map_err(|e| anyhow::anyhow!("archivist memory binding: {e}"))?;
+ let auto_recall = Arc::new(AutoRecall::from_guard(binding.guard()));
+ Ok((binding.provider().clone(), auto_recall))
+ }
+
/// (#1400) Best-effort synchronous prefetch of eager tool-scoped rules.
///
/// `from_config_*` is sync but typically runs inside a multi-threaded
@@@ -75,62 -91,3 +95,61 @@@ pub(super) fn prefetch_tool_memory_rule
})
})
}
+
+/// Register the memory prompt sections a session should carry.
+///
- /// Two independent gates, one per direction:
++/// One gate per direction, and neither consults `learning.enabled`: the
++/// instructions are about the memory *tools*, which exist whether or not the
++/// learning subsystem runs (#6040 untied the read side, #6048 the write side).
++/// A model holding those tools with no rule on when to use them is what
++/// produced both bugs — claiming absence unsearched, and "got it, saved" with
++/// zero tool calls.
+///
- /// - `MemoryAccessSection` (read side, #566): only when `learning.enabled` and
- /// a retrieval tool is offered.
- /// - `MemoryWriteSection` (write side, #6048): whenever a writing tool is
- /// offered, regardless of `learning.enabled`. The tools are registered either
- /// way, and a model that holds them with no rule on when to use them narrates
- /// a save it never made — "got it, saved" with zero tool calls.
++/// - `MemoryAccessSection` (read side, #566/#6040): a retrieval tool is offered.
++/// - `MemoryWriteSection` (write side, #6048): a writing tool is offered, and it
++/// names only the write tools this session actually holds.
+///
+/// Each gate needs the tool registered **and** visible after filtering
+/// (`any_tool_offered`): a rule about a tool the model cannot see would only
+/// teach it to apologise.
+pub(super) fn add_memory_prompt_sections(
+ prompt_builder: SystemPromptBuilder,
- config: &Config,
+ tools: &[Box<dyn Tool>],
+ delegation_tools: &[Box<dyn Tool>],
+ visible: &HashSet<String>,
+ agent_id: &str,
+) -> SystemPromptBuilder {
+ use crate::openhuman::agent::learning::{
+ any_tool_offered, MemoryAccessSection, MemoryWriteSection, MEMORY_READ_TOOLS,
+ MEMORY_STORE_TOOL, SAVE_PREFERENCE_TOOL,
+ };
+ let mut prompt_builder = prompt_builder;
- if config.learning.enabled {
- if any_tool_offered(&MEMORY_READ_TOOLS, tools, delegation_tools, visible) {
- prompt_builder = prompt_builder.add_section(Box::new(MemoryAccessSection));
- log::debug!("[learning] memory_access prompt section registered");
- } else {
- log::debug!(
- "[learning] skipping MemoryAccessSection — neither memory_recall nor \
- memory_search is registered+visible for agent={agent_id}"
- );
- }
++ if any_tool_offered(&MEMORY_READ_TOOLS, tools, delegation_tools, visible) {
++ prompt_builder = prompt_builder.add_section(Box::new(MemoryAccessSection));
++ log::debug!("[memory_access] prompt section registered");
++ } else {
++ log::debug!(
++ "[memory_access] skipping MemoryAccessSection — neither memory_recall nor \
++ memory_search is registered+visible for agent={agent_id}"
++ );
+ }
+ // Asked per tool, not once for the pair: the section names the routes it
+ // is given, so a profile carrying only one write tool must not be told
+ // 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)));
+ log::debug!(
+ "[memory_write] prompt section registered for agent={agent_id} \
+ save_preference={preferences} memory_store={facts}"
+ );
+ } else {
+ log::debug!(
+ "[memory_write] skipping MemoryWriteSection — neither memory_store nor \
+ save_preference is registered+visible for agent={agent_id}"
+ );
+ }
+ prompt_builder
+}