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(session): leave the recorded tool catalogue out of the prompt compare
M3gA-Mind72b8c7d4dfa2
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/permanent.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/permanent.rsindex 6bba70ff4b..23590d366c 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session/permanent.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/permanent.rs@@ -3,6 +3,9 @@use super::OpenHumanTurnPrelude;use tinyagents_runtime::{PrefixSnapshot, TurnPreparation};+/// Opens the system message that carries the permanent-tool catalogue.+pub(super) const PERMANENT_TOOLS_MARKER: &str = "<openhuman-permanent-tools>\n";+impl OpenHumanTurnPrelude {pub(super) fn refresh_permanent_prefix(&self,@@ -17,7 +20,7 @@ impl OpenHumanTurnPrelude {preparation.prefix.as_ref().unwrap_or(current),&surface.visible_tool_specs,&surface.permanent_tool_names,- "<openhuman-permanent-tools>\n",+ PERMANENT_TOOLS_MARKER,"</openhuman-permanent-tools>",).or(preparation.prefix.take());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 0a7137fb0c..0b90d0ec64 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@@ -29,10 +29,20 @@ use tinyagents_runtime::{};use tinyinference_llm::message::Message;+use super::permanent::PERMANENT_TOOLS_MARKER;use super::OpenHumanTurnPrelude;use crate::agent::message_convert::{user_message_from_text, user_text_with_markers};use crate::agent::tinyagents::middleware::turn_context::TranscriptSnapshotSink;+/// A prefix's messages without the permanent-tool catalogue, which the+/// recorded prefix carries and a freshly rendered prompt does not.+fn prompt_messages(prefix: &PrefixSnapshot) -> impl Iterator<Item = &Message> {+ prefix+ .messages()+ .iter()+ .filter(|message| !message.text().starts_with(PERMANENT_TOOLS_MARKER))+}+fn prompt_refresh_log_fields(prompt_changed: bool) -> (&'static str, &'static str) {if prompt_changed {("refreshed", "prompt_changed")@@ -73,12 +83,13 @@ impl OpenHumanTurnPrelude {false};// Compared before the catalogue refresh below, which changes the- // prefix of a kept prompt too: only the rendered prompt itself counts.+ // prefix of a kept prompt too, and without the catalogue the recorded+ // prefix carries: only the rendered prompt itself counts.let changed = rendered&& preparation.prefix.as_ref()- .is_some_and(|prefix| prefix.messages() != view.prefix.messages());+ .is_some_and(|prefix| !prompt_messages(prefix).eq(prompt_messages(view.prefix)));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 thediff --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 cf0b75b687..d32b1d1240 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@@ -654,3 +654,54 @@ async fn a_catalogue_change_under_a_rendered_but_identical_prompt_carries_no_not"a catalogue change under a kept prompt is not a replaced prompt");}++#[tokio::test]+async fn a_recorded_catalogue_is_not_read_as_a_replaced_prompt() {+ // The thread recorded a permanent-tool catalogue beside its prompt, and+ // the current prompt renders identical to the recorded one. Whether the+ // catalogue is unchanged or names another tool now, the prompt was not+ // replaced, so the user's message carries no note.+ let spec = |name: &str| {+ Arc::new(tinytools::ToolSpec {+ name: name.into(),+ description: "d".into(),+ parameters: serde_json::json!({"type": "object"}),+ })+ };+ let recorded = tinyagents_runtime::refresh_prefix(+ ¤t(),+ &[spec("A_TOOL")],+ &["A_TOOL".to_string()].into(),+ super::super::permanent::PERMANENT_TOOLS_MARKER,+ "</openhuman-permanent-tools>",+ )+ .expect("a recorded catalogue");+ for now in ["A_TOOL", "B_TOOL"] {+ let root = tempfile::tempdir().expect("tempdir");+ let prelude = prelude(root.path(), "current", true);+ {+ let mut surface = prelude+ .tool_surface+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ surface.visible_tool_specs = Arc::new(vec![spec(now)]);+ surface.permanent_tool_names = [now.to_string()].into();+ }+ let history = [Message::user("earlier"), Message::assistant("hello")];+ let mut request = request();+ prelude+ .prepare_turn(+ false,+ &resumed(&recorded, &history),+ &snapshot(4),+ &mut request,+ )+ .await+ .expect("prepared turn");+ assert_eq!(+ request.input.text(),+ "hi",+ "catalogue now names {now}: the prompt was not replaced"+ );+ }+}