Skip to content

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

feat(memory): add per-turn recall timeout binding

Steven Enamakelc05fa01295c7
diff --git a/crates/openhuman-core/src/config/schema/memory.rs b/crates/openhuman-core/src/config/schema/memory.rs
index a48eecaa24..6fd7f20cc5 100644
--- a/crates/openhuman-core/src/config/schema/memory.rs
+++ b/crates/openhuman-core/src/config/schema/memory.rs
@@ -5,6 +5,7 @@
//! engine = "tinyhumans" # "tinyhumans" | "cortexdb"
//! # agent_id = "writer-7" # host binding: every agent on this config is this memory agent
//! # root = "team:acme" # host binding: the layout root (one per tenant)
+//! # recall_each_turn_ms = 1500 # host binding: recall the current message, waiting this long
//!
//! [memory.engines.cortexdb]
//! endpoint = "https://api-v1.cortexdb.ai" # key in the keychain as "memory-cortexdb"
@@ -114,6 +115,13 @@ pub struct MemoryConfig {
/// Unset is the default root.
#[serde(skip_serializing_if = "Option::is_none")]
pub root: Option<String>,
+ /// Host binding: recall memory for the user's current message on every
+ /// turn and wait at most this many milliseconds for it before the first
+ /// model call. A late or failed recall leaves the turn without a memory
+ /// note. Unset (the default), a turn only reads the pack completed in the
+ /// background for an earlier turn.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub recall_each_turn_ms: Option<u64>,
/// Where memory sits on the engine: `legacy` (the shared
/// `app:tinymemory` tree, the default) or `v3` (the signed-in person's
/// own `org:<id>` subtree, chats pooled at `ws:main`). Switched by the
@@ -224,6 +232,7 @@ impl Default for MemoryConfig {
engines: BTreeMap::new(),
agent_id: None,
root: None,
+ recall_each_turn_ms: None,
layout: MemoryLayoutMode::Legacy,
conversations: MemoryConversationsConfig::default(),
recall: RecallSettings::default(),
diff --git a/crates/openhuman-core/src/inference/turn_models.rs b/crates/openhuman-core/src/inference/turn_models.rs
index e2e82b71ea..f560d33858 100644
--- a/crates/openhuman-core/src/inference/turn_models.rs
+++ b/crates/openhuman-core/src/inference/turn_models.rs
@@ -218,7 +218,7 @@ fn build_turn_models_crate(
.primary_model_pin(model)
.primary_opts(opts.clone())
.workload_requests(workload_requests)
- .summarization(role, Some(model.to_owned()))
+ .summarization(role, Some(summarizer_model_id.clone()))
.summarization_opts(opts)
.build()?;
let mut registrations = built.registrations("primary").into_iter();
diff --git a/crates/openhuman-core/src/memory/lifecycle/session_hooks.rs b/crates/openhuman-core/src/memory/lifecycle/session_hooks.rs
index 57296a3902..3e8a519aba 100644
--- a/crates/openhuman-core/src/memory/lifecycle/session_hooks.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/session_hooks.rs
@@ -2,8 +2,11 @@
//!
//! Before the model runs, [`OpenHumanTurnPrelude::memory_pre_turn`] logs the
//! user turn and refreshes memory in the background, taking a completed cached
-//! pack immediately (`memory::lifecycle::prefetch::pre_turn`); `MemoryPackMiddleware` then adds the
-//! pack to the turn's requests without persisting it. After the durable
+//! pack immediately (`memory::lifecycle::prefetch::pre_turn`). When the
+//! config binds `[memory] recall_each_turn_ms`, it instead waits up to that
+//! long for the pack recalled for the current message, alongside the rest of
+//! turn setup. `MemoryPackMiddleware` then adds the pack to the turn's
+//! requests without persisting it. After the durable
//! commit, [`OpenHumanTurnPrelude::memory_post_turn`] logs the reply with its
//! tool calls. Both run under the session's own config, so a host binding set
//! on a derived context (`[memory] agent_id` / `root`) is honoured, and both
@@ -26,6 +29,7 @@ use tinyinference_llm::message::Message;
use super::OpenHumanTurnPrelude;
use crate::agent::tinyagents::host::OpenHumanRunContext;
use crate::memory::lifecycle::hooks::{self, MemoryTurn, ToolCallSummary};
+use crate::memory::lifecycle::prefetch::RecallEachTurn;
use tinymemory_tools::layout::identity::ResolvedIdentity;
/// The memory side of the turn in flight, held from pre-turn to commit.
@@ -186,7 +190,10 @@ impl OpenHumanTurnPrelude {
.as_ref()
.and_then(crate::memory::lifecycle::sender::channel_actor),
memory_channel,
- None,
+ config
+ .memory
+ .recall_each_turn_ms
+ .map(|ms| RecallEachTurn::new(std::time::Duration::from_millis(ms))),
)
.await;
Some(Arc::new(MemoryTurn {
diff --git a/crates/openhuman-embed/src/agent/build.rs b/crates/openhuman-embed/src/agent/build.rs
index afce8671cf..7c98e3ed4f 100644
--- a/crates/openhuman-embed/src/agent/build.rs
+++ b/crates/openhuman-embed/src/agent/build.rs
@@ -175,6 +175,9 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInn
log::debug!("[embed][agent] id={id} binds its memory agent_id={agent_id}");
config.memory.agent_id = Some(agent_id.to_string());
config.memory.root = binding.root_namespace().map(|root| root.trim().to_string());
+ config.memory.recall_each_turn_ms = binding
+ .recall_each_turn_timeout()
+ .map(|timeout| u64::try_from(timeout.as_millis()).unwrap_or(u64::MAX));
}
if let Some(f) = parts.config_fn {
diff --git a/crates/openhuman-embed/src/agent/spec.rs b/crates/openhuman-embed/src/agent/spec.rs
index 035eae3aed..217a4d3478 100644
--- a/crates/openhuman-embed/src/agent/spec.rs
+++ b/crates/openhuman-embed/src/agent/spec.rs
@@ -101,6 +101,14 @@ impl MemoryBinding {
/// Recall memory for the user's current message on every turn, and wait
/// at most `timeout` for it before the turn's first model call.
+ ///
+ /// The recall runs alongside the rest of turn setup. A pack that arrives
+ /// in time rides every model request of the turn as an ephemeral note
+ /// after the user's message, and is never written to the transcript. A
+ /// late or failed recall leaves the turn without a note; it never fails
+ /// the turn. Without this, a turn only sees the pack the background
+ /// refresh completed for an earlier turn, which a host whose users write
+ /// minutes apart rarely has.
#[must_use]
pub fn recall_each_turn(mut self, timeout: std::time::Duration) -> Self {
self.recall_each_turn = Some(timeout);
@@ -116,6 +124,12 @@ impl MemoryBinding {
pub fn root_namespace(&self) -> Option<&str> {
self.root.as_deref()
}
+
+ /// How long a turn waits for its own recall, when
+ /// [`recall_each_turn`](Self::recall_each_turn) is set.
+ pub fn recall_each_turn_timeout(&self) -> Option<std::time::Duration> {
+ self.recall_each_turn
+ }
}
impl AgentSpec {