Skip to content

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

feat(threads): add transcript key accessor for session host

Steven Enamakel33ff85c17981
diff --git a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
index bf88800aa6..09116701d7 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
@@ -302,6 +302,20 @@ impl OpenHumanSessionHost {
self.sync_runtime_tool_surface();
}
+ /// Route this session's transcripts to `locator` instead of the store its
+ /// agent key resolves to. Must be set before the first turn: the session
+ /// binds its transcript target once.
+ pub fn set_session_history_locator(
+ &mut self,
+ locator: std::sync::Arc<dyn tinyagents_session::transcript::TranscriptLocator>,
+ ) {
+ if self.runtime_session.is_some() {
+ tracing::warn!("cannot change the transcript store after runtime session initialization");
+ return;
+ }
+ self.session_history_locator = Some(locator);
+ }
+
/// Bind the OpenHuman conversation thread for the next and subsequent
/// turns. Empty input intentionally clears the binding.
///
diff --git a/crates/openhuman-core/src/threads/store/mod.rs b/crates/openhuman-core/src/threads/store/mod.rs
index 14256ef165..d63aec580d 100644
--- a/crates/openhuman-core/src/threads/store/mod.rs
+++ b/crates/openhuman-core/src/threads/store/mod.rs
@@ -66,6 +66,7 @@ impl From<types::ConversationPurgeStats> for ConversationPurgeStats {
#[cfg(feature = "channels")]
pub(crate) use bus::claim_channel_turn;
pub use bus::register_conversation_persistence_subscriber;
+pub(crate) use transcript_key::bind_transcript_key;
pub use store::{
append_message, delete_messages_from, delete_thread, ensure_thread, get_messages, list_threads,
purge_threads, update_message, update_thread_labels, update_thread_title,
diff --git a/crates/openhuman-core/src/threads/store/transcript_key.rs b/crates/openhuman-core/src/threads/store/transcript_key.rs
index 1717a09ee1..f346130f16 100644
--- a/crates/openhuman-core/src/threads/store/transcript_key.rs
+++ b/crates/openhuman-core/src/threads/store/transcript_key.rs
@@ -111,6 +111,32 @@ impl ConversationStore {
}
}
+/// The key a session for `thread_id` must write its transcripts under: the
+/// one already recorded with the thread, else `rule_key` (what the session host
+/// would derive now), which is recorded as the thread's key. A store that
+/// cannot be reached degrades to `rule_key` without recording.
+pub(crate) async fn bind_transcript_key(
+ ctx: &crate::core::runtime::DispatchCtx,
+ workspace_dir: &std::path::Path,
+ thread_id: &str,
+ rule_key: String,
+) -> String {
+ match super::blocking::record_transcript_key(
+ ctx.clone(),
+ workspace_dir.to_path_buf(),
+ thread_id.to_string(),
+ rule_key.clone(),
+ )
+ .await
+ {
+ Ok(key) => key,
+ Err(error) => {
+ log::warn!("{LOG_PREFIX} bind failed, using the current rule: {error}");
+ rule_key
+ }
+ }
+}
+
#[cfg(test)]
#[path = "transcript_key_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/web_chat/session.rs b/crates/openhuman-core/src/web_chat/session.rs
index 8ef81a7d0d..586a544c03 100644
--- a/crates/openhuman-core/src/web_chat/session.rs
+++ b/crates/openhuman-core/src/web_chat/session.rs
@@ -471,6 +471,8 @@ pub(crate) async fn checkout_session_agent(
),
};
+ bind_transcript_store(ctx, config, thread_id, &fingerprint.target_agent_id, &mut agent).await;
+
// Every checkout re-arms the reply language from this turn's locale: a
// reused agent may have been built under a different one, and `None`
// (English, or no locale sent) must clear a stale instruction.