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): correct prompt section ordering for learning context
Steven Enamakel2f070b6f124d
diff --git a/crates/openhuman-core/src/agent/learning/prompt_sections.rs b/crates/openhuman-core/src/agent/learning/prompt_sections.rsindex 4cf8d73dfd..b4ffa85dbe 100644--- a/crates/openhuman-core/src/agent/learning/prompt_sections.rs+++ b/crates/openhuman-core/src/agent/learning/prompt_sections.rs@@ -159,6 +159,9 @@ pub struct MemoryWriteSection {preferences: bool,facts: bool,delegate: bool,+ /// The fact-write route to name: `memory_store`, or the collapsed `memory`+ /// tool's `learn` action.+ fact_route: &'static str,}impl MemoryWriteSection {@@ -170,10 +173,22 @@ impl MemoryWriteSection {preferences,facts,delegate,+ fact_route: FACT_ROUTE_STORE,}}++ /// Name the collapsed `memory` tool's `learn` action as the fact-write+ /// route instead of `memory_store`.+ #[must_use]+ pub fn via_memory_tool(mut self) -> Self {+ self.fact_route = FACT_ROUTE_MEMORY;+ self+ }}+const FACT_ROUTE_STORE: &str = "`memory_store`";+const FACT_ROUTE_MEMORY: &str = "`memory` (`action: \"learn\"`)";+/// The instruction for a session offering `save_preference` (`preferences`)/// and/or `memory_store` (`facts`).///@@ -182,10 +197,21 @@ impl MemoryWriteSection {/// 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, delegate: bool) -> String {+ memory_write_instruction_via(preferences, facts, delegate, FACT_ROUTE_STORE)+}++/// [`memory_write_instruction`] with the fact-write route named explicitly.+#[must_use]+fn memory_write_instruction_via(+ preferences: bool,+ facts: bool,+ delegate: bool,+ fact_route: &str,+) -> 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`",+ (true, true) => format!("— `save_preference` for preferences, {fact_route} for everything else"),+ (true, false) => "with `save_preference`".to_string(),+ (false, true) => format!("with {fact_route}"),// Only when neither direct tool is held, so an agent that has one// renders exactly the text it rendered before this arm existed.//@@ -198,10 +224,9 @@ pub fn memory_write_instruction(preferences: bool, facts: bool, delegate: bool)// which is the #6048 bug arriving by a new route. The argument is// advertised on the tool's own schema, so this is a demand the model// can actually satisfy.- (false, false) if delegate => {- "with `manage_profile_memory` (pass `blocking: true` so the write \+ (false, false) if delegate => "with `manage_profile_memory` (pass `blocking: true` so the write \gates your reply)"- }+ .to_string(),(false, false) => return String::new(),};format!(@@ -217,10 +242,11 @@ impl PromptSection for MemoryWriteSection {}fn build(&self, _ctx: &PromptContext<'_>) -> Result<String> {- Ok(memory_write_instruction(+ Ok(memory_write_instruction_via(self.preferences,self.facts,self.delegate,+ self.fact_route,))}}@@ -238,7 +264,12 @@ impl PromptSection for MemoryWriteSection {////// [`any_tool_offered`] already receives the delegation tools separately, so/// this needed no new plumbing; the list was simply the wrong list.-pub const MEMORY_READ_TOOLS: [&str; 3] = ["memory_recall", "memory_search", "retrieve_memory"];+pub const MEMORY_READ_TOOLS: [&str; 4] = [+ "memory_recall",+ "memory_search",+ "retrieve_memory",+ MEMORY_TOOL,+];/// The tool a preference is written through.pub const SAVE_PREFERENCE_TOOL: &str = "save_preference";@@ -246,6 +277,10 @@ 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 collapsed memory tool (`ask` | `keyword_search` | `learn`); it reads and+/// writes, so it satisfies both the read rule and the fact-write rule.+pub const MEMORY_TOOL: &str = "memory";+/// The delegate an agent writes through when it holds neither direct write/// tool.///diff --git a/crates/openhuman-core/src/agent/session_host/builder/helpers.rs b/crates/openhuman-core/src/agent/session_host/builder/helpers.rsindex 2344eaf5f6..a439f1cc36 100644--- a/crates/openhuman-core/src/agent/session_host/builder/helpers.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/helpers.rs@@ -137,7 +137,11 @@ pub(super) fn add_memory_prompt_sections(// 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);+ let store_offered = any_tool_offered(&[MEMORY_STORE_TOOL], tools, delegation_tools, visible);+ // The collapsed `memory` tool writes through its `learn` action; the legacy+ // `memory_store` wins the wording only when both are held.+ let memory_offered = any_tool_offered(&[MEMORY_TOOL], tools, delegation_tools, visible);+ let facts = store_offered || memory_offered;// #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.@@ -148,11 +152,11 @@ pub(super) fn add_memory_prompt_sections(visible,);if preferences || facts || delegate {- prompt_builder = prompt_builder.add_section(Box::new(MemoryWriteSection::new(- preferences,- facts,- delegate,- )));+ let mut section = MemoryWriteSection::new(preferences, facts, delegate);+ if memory_offered && !store_offered {+ section = section.via_memory_tool();+ }+ prompt_builder = prompt_builder.add_section(Box::new(section));log::debug!("[memory_write] prompt section registered for agent={agent_id} \save_preference={preferences} memory_store={facts} \