Skip to content

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

fix(session-host): exclude memory block from prompt refresh comparison

Steven Enamakel94a6c58aafa5
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.rs
index 2f566770fb..6e06de5725 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
@@ -11,6 +11,10 @@
//! - the whole prompt, rendered afresh, when the agent's definition sets
//! `refresh_prompt_on_resume`, so prompt edits reach existing threads too.
//!
+//! - the memory block (`memory_block.rs`), when a generation starts; it is
+//! left out of the comparison below like the catalogue, so a memory change
+//! alone never seals a generation or adds the note.
+//!
//! Whatever is offered, the turn's transcript snapshot boundary moves with
//! it: the request starts with the offered prefix, not the recorded one.
//!
@@ -29,18 +33,19 @@ use tinyagents_runtime::{
};
use tinyinference_llm::message::Message;
+use super::memory_block::is_memory_block;
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.
+/// A prefix's messages without the permanent-tool catalogue and the memory
+/// block, 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))
+ prefix.messages().iter().filter(|message| {
+ !message.text().starts_with(PERMANENT_TOOLS_MARKER) && !is_memory_block(message)
+ })
}
fn prompt_refresh_log_fields(prompt_changed: bool) -> (&'static str, &'static str) {
@@ -72,11 +77,9 @@ impl OpenHumanTurnPrelude {
// Imported conversations can already be durable while lacking the
// prefix the first host turn must commit. Only an authoritative or
// inferred frozen prefix suppresses prompt preparation.
+ let cold = super::turn::prepare_prefix_for_turn(new_session, view.prefix_is_frozen);
let mut preparation = self
- .prepare(super::turn::prepare_prefix_for_turn(
- new_session,
- view.prefix_is_frozen,
- ))
+ .prepare(cold)
.await
.map_err(|error| RuntimeError::Driver(error.to_string()))?;
// Whether this turn rendered the current prompt. Only then can a
@@ -97,6 +100,8 @@ impl OpenHumanTurnPrelude {
.as_ref()
.is_some_and(|prefix| !prompt_messages(prefix).eq(prompt_messages(view.prefix)));
self.refresh_permanent_prefix(&mut preparation, view.prefix);
+ // Last, so the block follows everything else the prefix carries.
+ self.refresh_memory_block(&mut preparation, view, cold).await;
if let Some(prefix) = preparation.prefix.as_ref() {
// The runtime sends `prefix` in place of the recorded one, so the
// rounds this run produces start that much further on (or back).