Skip to content

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

feat(session_host): expose runtime session accessors

Steven Enamakel5f55268c909f
diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs
index 0e95c2207e..fd77bc1ef4 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs
@@ -442,6 +442,7 @@ impl SessionHostBuilder {
event_channel,
task_recency_window: None,
autonomous_iter_cap: None,
+ host_env: crate::agent::turn_env::HostTurnEnv::default(),
thread_id: None,
agent_definition_name: agent_definition_name.clone(),
// Canonical registry id — captured here at build time
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 702a8e7396..de97dc019a 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
@@ -255,6 +255,34 @@ impl OpenHumanSessionHost {
self.task_recency_window = window;
}
+ /// Hands the host environment of the turns this session runs (shared
+ /// model budget, cancellation, deadline, hooks, tool-belt authority).
+ ///
+ /// Call it after building the session and before its first turn: the
+ /// completed-turn callbacks join the learning sink's set and the tool belt
+ /// authority is read when the runtime session is first created.
+ pub fn set_host_env(&mut self, env: crate::agent::turn_env::HostTurnEnv) {
+ for hook in env.hooks.post_turn_hooks() {
+ if !self
+ .post_turn_hooks
+ .iter()
+ .any(|existing| Arc::ptr_eq(existing, hook))
+ {
+ self.post_turn_hooks.push(Arc::clone(hook));
+ }
+ }
+ tracing::debug!(
+ env = ?env,
+ "[session_host] host turn env installed"
+ );
+ self.host_env = env;
+ }
+
+ /// The host environment installed with [`Self::set_host_env`].
+ pub fn host_env(&self) -> &crate::agent::turn_env::HostTurnEnv {
+ &self.host_env
+ }
+
/// Runs this agent as an unattended autonomous tree: sub-agent iteration
/// caps are lifted to `cap` on every later turn; `None` clears the lift.
pub fn set_autonomous_iter_cap(&mut self, cap: Option<usize>) {
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 44507c9e40..3a6fbd6deb 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1046,7 +1046,7 @@ impl OpenHumanSessionHost {
.codec(Arc::new(OpenHumanTranscriptCodec))
.hooks(hooks)
.retain_recorded_tools(
- !self.host_only && crate::agent::tool_snapshot_scope::retain_recorded_tools(),
+ !self.host_only && !self.host_env.fresh_tool_snapshot,
);
let meta = self.runtime_transcript_meta();
builder = match self.session.clone() {
diff --git a/crates/openhuman-core/src/agent/session_host/types.rs b/crates/openhuman-core/src/agent/session_host/types.rs
index da088df2ec..607eeaaf95 100644
--- a/crates/openhuman-core/src/agent/session_host/types.rs
+++ b/crates/openhuman-core/src/agent/session_host/types.rs
@@ -292,6 +292,9 @@ pub struct OpenHumanSessionHost {
/// Autonomous skill-run iteration cap handed to every turn's run context
/// (lifts sub-agent iteration caps); `None` for ordinary agents.
pub(super) autonomous_iter_cap: Option<usize>,
+ /// Per-turn host environment (budget, cancellation, deadline, hooks, ...)
+ /// handed in by the entry point; copied onto every turn's run context.
+ pub(super) host_env: crate::agent::turn_env::HostTurnEnv,
/// Backend/session thread explicitly owned by this agent run. It is kept
/// separate from event identity: CLI and worker event sessions are not
/// necessarily user conversation threads.