Skip to content

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

refactor(session_host): resolve transcript identity lazily

Steven Enamakela8c05044247d
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 080d3ef06e..bea715cf29 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -18,7 +18,7 @@ pub(super) use usage::{account_committed_turn_against_goal, holistic_last_turn_u
#[path = "../../memory/lifecycle/session_hooks.rs"]
mod session_hooks;
mod tool_rules;
-mod transcript;
+mod identity;
#[path = "runtime_session_turn.rs"]
mod turn;
pub(super) use turn::begin_turn_resume;
@@ -312,20 +312,20 @@ impl OpenHumanSessionHost {
// Thread-bound roots resume their deterministic transcript; other
// turns keep the per-run stem path. Reuse one locator for the initial
// binding and each resume because the runtime compares locator identity.
- let session_locator = self.session_locator();
- let resume_target = match self.session.clone() {
+ let injected_locator = self.session_history_locator.clone();
+ let resume_target = injected_locator.as_ref().map(|locator| match self.session.clone() {
Some(session) => TranscriptTarget::for_session(
- session_locator.clone(),
+ Arc::clone(locator),
session,
self.runtime_transcript_meta(),
),
None => TranscriptTarget::new(
- session_locator.clone(),
+ Arc::clone(locator),
self.runtime_transcript_stem(),
self.runtime_transcript_meta(),
)
.with_resume_agent(self.agent_definition_name.clone()),
- };
+ });
{
let mut state = self
.runtime_state
@@ -353,7 +353,7 @@ impl OpenHumanSessionHost {
);
Box::pin(async move {
Ok(ResumePreparation {
- transcript: Some(resume_target),
+ transcript: resume_target,
})
})
}
@@ -549,11 +549,19 @@ impl OpenHumanSessionHost {
.hooks(hooks)
.retain_recorded_tools(!self.host_only && !self.host_env.fresh_tool_snapshot);
let meta = self.runtime_transcript_meta();
- builder = match self.session.clone() {
- Some(session) => builder.session(session_locator, session, meta),
- None => builder
- .transcript(session_locator, self.runtime_transcript_stem(), meta)
- .resume_agent(self.agent_definition_name.clone()),
+ builder = if let Some(locator) = injected_locator {
+ match self.session.clone() {
+ Some(session) => builder.session(locator, session, meta),
+ None => builder
+ .transcript(locator, self.runtime_transcript_stem(), meta)
+ .resume_agent(self.agent_definition_name.clone()),
+ }
+ } else {
+ builder.identity_resolver(
+ self.runtime_session_key(),
+ meta,
+ Arc::new(self.session_identity_resolver()),
+ )
};
self.runtime_session = Some(
builder
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/transcript.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/transcript.rs
deleted file mode 100644
index 4219dee971..0000000000
--- a/crates/openhuman-core/src/agent/session_host/runtime_session/transcript.rs
+++ /dev/null
@@ -1,67 +0,0 @@
-//! Session transcript identity, locator and metadata construction.
-
-use super::super::types::OpenHumanSessionHost;
-use crate::storage::sessions::transcripts_or_files;
-use std::sync::Arc;
-use tinyagents_session::transcript::TranscriptMeta;
-
-impl OpenHumanSessionHost {
- pub(super) fn runtime_transcript_stem(&self) -> String {
- match &self.session_parent_prefix {
- Some(prefix) => format!("{prefix}__{}", self.session_key),
- None => self.session_key.clone(),
- }
- }
-
- pub(in crate::agent::session_host) fn session_locator(
- &self,
- ) -> Arc<dyn tinyagents_session::transcript::TranscriptLocator> {
- if let Some(injected) = self.session_history_locator.clone() {
- return injected;
- }
- self.session_history_locator_memo
- .get_or_init(|| {
- let session_agent_id = crate::storage::sessions::current_agent_key_or(
- &self.dispatch_ctx(),
- &self.agent_definition_id,
- );
- transcripts_or_files(&session_agent_id, &self.workspace_dir)
- })
- .clone()
- }
-
- pub(super) fn runtime_transcript_meta(&self) -> TranscriptMeta {
- let now = chrono::Utc::now().to_rfc3339();
- TranscriptMeta {
- agent_name: self.agent_definition_name.clone(),
- agent_id: Some(self.agent_definition_id.clone()),
- agent_type: Some(if self.session_parent_prefix.is_some() {
- "subagent".into()
- } else {
- "root".into()
- }),
- dispatcher: if self.tool_dispatcher.should_send_tool_specs() {
- "native".into()
- } else {
- "xml".into()
- },
- provider: None,
- model: Some(self.model_name.clone()),
- created: now.clone(),
- updated: now,
- turn_count: 0,
- prefix_message_count: None,
- input_tokens: 0,
- output_tokens: 0,
- cached_input_tokens: 0,
- charged_amount_usd: 0.0,
- thread_id: self.thread_id.clone(),
- task_id: None,
- session_id: self.session.as_ref().map(|session| session.session_id()),
- parent_session_id: self
- .session
- .as_ref()
- .and_then(|session| session.parent_session_id()),
- }
- }
-}