Skip to content

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

feat(session_host): extract session API module

Steven Enamakel2b7acda9d3a0
diff --git a/crates/openhuman-core/src/agent/session_host/mod.rs b/crates/openhuman-core/src/agent/session_host/mod.rs
index 4dcd5e5308..7c7cf62e58 100644
--- a/crates/openhuman-core/src/agent/session_host/mod.rs
+++ b/crates/openhuman-core/src/agent/session_host/mod.rs
@@ -21,6 +21,7 @@
//! | [`types`] | `OpenHumanSessionHost` and `SessionHostBuilder` struct definitions (no logic). |
//! | [`builder`] | `SessionHostBuilder` fluent API + `OpenHumanSessionHost::from_config` factory. |
//! | [`runtime_session`] | Runtime session composition and public `turn()`. |
+//! | [`session_api`] | Start / read / list the durable session. |
//! | [`driver`] | OpenHuman model/harness `SessionDriver`. |
//! | [`hooks`] | Product preparation/commit/terminal hooks. |
//! | [`runtime`] | Public accessors and `run_single` / `run_interactive`. |
@@ -40,6 +41,7 @@ mod policy;
mod prefix_snapshot;
mod runtime;
mod runtime_session;
+mod session_api;
#[cfg(test)]
mod tool_progress;
mod turn;
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 194a62f1c1..e31e694491 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1369,45 +1369,6 @@ impl OpenHumanSessionHost {
.map_err(|error| anyhow::anyhow!(error.to_string()))
}
- /// Load this session's durable history now, before any turn runs.
- ///
- /// A turn resumes on its own, so this exists for hosts that want the
- /// history in hand first — checking what a thread remembers, or rendering
- /// it — and for tests that assert resume without driving a provider.
- ///
- /// Returns whether history was loaded. `false` means the session has no
- /// durable identity bound (no thread), has nothing persisted yet, or has
- /// already run a turn.
- pub async fn resume_bound_session(&mut self) -> Result<bool> {
- let Some(session) = self.session.clone() else {
- return Ok(false);
- };
- self.ensure_runtime_session()?;
-
- let mut context = OpenHumanRunContext::new();
- context.thread_id = self.thread_id.clone();
- context.workspace = self.workspace_descriptor.clone();
- let cancellation = context.cancellation.clone();
- let root_config = context.root_run_config("openhuman-session-resume");
- let options = TurnOptions {
- request_id: None,
- thread_id: self.thread_id.clone(),
- stream: false,
- session: Some(session),
- resume: ResumeMode::Session,
- cancellation,
- run_context: context.into_tinyagents(root_config),
- };
- let resumed = self
- .runtime_session
- .as_mut()
- .expect("runtime session initialized")
- .resume(&options)
- .await
- .map_err(|error| anyhow::anyhow!(error.to_string()))?;
- Ok(resumed.loaded)
- }
-
/// Dispatch one public OpenHuman turn through the neutral runtime.
pub async fn turn(&mut self, user_message: &str) -> Result<String> {
self.ensure_runtime_session()?;
diff --git a/crates/openhuman-core/src/agent/session_host/session_api.rs b/crates/openhuman-core/src/agent/session_host/session_api.rs
new file mode 100644
index 0000000000..7dbf7cd2cc
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_host/session_api.rs
@@ -0,0 +1,56 @@
+//! The host's session surface: start one, read it back, list its generations.
+//!
+//! OpenHuman does not own session mechanics. Identity, resume, transcript
+//! binding, compaction generations and persistence all live in
+//! `tinyagents-session` / `tinyagents-runtime`. What remains here is the small
+//! product-facing surface over them — starting a session (binding a thread's
+//! identity, [`super::runtime::accessors`]), reading one back, and listing the
+//! generations a long conversation has accumulated.
+
+use anyhow::Result;
+use tinyagents_runtime::{ResumeMode, TurnOptions};
+
+use crate::agent::tinyagents::host::OpenHumanRunContext;
+
+use super::OpenHumanSessionHost;
+
+impl OpenHumanSessionHost {
+ /// Load this session's durable history now, before any turn runs.
+ ///
+ /// A turn resumes on its own, so this exists for hosts that want the
+ /// history in hand first — checking what a thread remembers, or rendering
+ /// it — and for tests that assert resume without driving a provider.
+ ///
+ /// Returns whether history was loaded. `false` means the session has no
+ /// durable identity bound (no thread), has nothing persisted yet, or has
+ /// already run a turn.
+ pub async fn resume_bound_session(&mut self) -> Result<bool> {
+ let Some(session) = self.session.clone() else {
+ return Ok(false);
+ };
+ self.ensure_runtime_session()?;
+
+ let mut context = OpenHumanRunContext::new();
+ context.thread_id = self.thread_id.clone();
+ context.workspace = self.workspace_descriptor.clone();
+ let cancellation = context.cancellation.clone();
+ let root_config = context.root_run_config("openhuman-session-resume");
+ let options = TurnOptions {
+ request_id: None,
+ thread_id: self.thread_id.clone(),
+ stream: false,
+ session: Some(session),
+ resume: ResumeMode::Session,
+ cancellation,
+ run_context: context.into_tinyagents(root_config),
+ };
+ let resumed = self
+ .runtime_session
+ .as_mut()
+ .expect("runtime session initialized")
+ .resume(&options)
+ .await
+ .map_err(|error| anyhow::anyhow!(error.to_string()))?;
+ Ok(resumed.loaded)
+ }
+}