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): note a prompt update only when the current prompt was rendered
Shanu1f4c4c3b3544
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh.rsindex 1db2058385..13096196e1 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh.rs@@ -18,7 +18,8 @@//! with a one-time note saying so (`PROMPT_UPDATE_NOTE`). The conversation//! before it was written under the old prompt, and a model keeps to what it//! already said there (that something is "coming soon", say) over-//! instructions that changed since.+//! instructions that changed since. Only a prompt rendered on that turn+//! counts: the catalogue changing under a prompt the turn kept says nothing.use std::sync::PoisonError;@@ -54,10 +55,15 @@ impl OpenHumanTurnPrelude {.prepare(new_session).await.map_err(|error| RuntimeError::Driver(error.to_string()))?;- let refresh_prompt = view.resumed && self.refreshes_prompt_on_resume();- if refresh_prompt {+ // Whether this turn rendered the current prompt. Only then can a+ // changed prefix mean the prompt was replaced: the permanent-tool+ // catalogue below also changes the prefix of a prompt that was kept.+ let rendered = if view.resumed && self.refreshes_prompt_on_resume() {preparation.prefix = self.current_prompt_prefix(view).await;- }+ preparation.prefix.is_some()+ } else {+ false+ };self.refresh_permanent_prefix(&mut preparation, view.prefix);if let Some(prefix) = preparation.prefix.as_ref() {// The runtime sends `prefix` in place of the recorded one, so the@@ -68,7 +74,7 @@ impl OpenHumanTurnPrelude {.saturating_sub(view.prefix.messages().len())+ prefix.messages().len();}- if refresh_prompt {+ if rendered {let changed = preparation.prefix.as_ref()diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh_tests.rsindex e5200c64a2..20085a7006 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh_tests.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/prompt_refresh_tests.rs@@ -491,3 +491,51 @@ async fn a_prompt_that_fails_to_render_keeps_the_recorded_one() {.expect("a resumed turn does not fail on its prompt");assert_eq!(prepared.prefix, None);}++#[tokio::test]+async fn a_catalogue_change_under_a_kept_prompt_carries_no_note() {+ // The prompt is kept (the integrations it renders are not read yet), but+ // a permanent tool was added since the thread was recorded: the catalogue+ // is refreshed on the recorded prompt. The prompt itself was not+ // replaced, so the turn says nothing about it.+ let root = tempfile::tempdir().expect("tempdir");+ let prelude = composed_prelude(root.path(), SystemPromptBuilder::verbatim("current".into()));+ {+ let mut surface = prelude+ .tool_surface+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ let spec = tinytools::ToolSpec {+ name: "A_TOOL".into(),+ description: "d".into(),+ parameters: serde_json::json!({"type": "object"}),+ };+ surface.visible_tool_specs = Arc::new(vec![Arc::new(spec)]);+ surface.permanent_tool_names = ["A_TOOL".to_string()].into();+ }+ let recorded = PrefixSnapshot::new(vec![Message::system("recorded")]);+ let history = [Message::system("recorded"), Message::user("hi")];+ let sink = snapshot(3);+ let mut request = request();+ let prepared = prelude+ .prepare_turn(false, &resumed(&recorded, &history), &sink, &mut request)+ .await+ .expect("prepared turn");+ let prefix = prepared+ .prefix+ .as_ref()+ .expect("the refreshed catalogue is offered");+ assert_eq!(+ prefix.messages()[0].text(),+ "recorded",+ "the prompt is kept"+ );+ let catalogue = prefix.messages().last().expect("a catalogue").text();+ assert!(catalogue.contains("A_TOOL"));+ assert_eq!(sink.lock().unwrap().request_base_len, 4);+ assert_eq!(+ request.input.text(),+ "hi",+ "a catalogue change alone is not a replaced prompt"+ );+}