Skip to content

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

feat(embed): add session_store builder option

Steven Enamakeld70ba955d12e
diff --git a/Cargo.lock b/Cargo.lock
index 011b0c62a1..7c9caa5ef5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5927,6 +5927,7 @@ dependencies = [
"tinymcp-bus",
"tinymemory-api",
"tinymemory-tools",
+ "tinystoragedrivers-testkit",
"tinytools 0.6.0",
"tokio",
"tokio-stream",
diff --git a/crates/openhuman-embed/Cargo.toml b/crates/openhuman-embed/Cargo.toml
index 367012b589..28d83b59f4 100644
--- a/crates/openhuman-embed/Cargo.toml
+++ b/crates/openhuman-embed/Cargo.toml
@@ -104,6 +104,8 @@ uuid = { version = "1", features = ["v4"] }
[dev-dependencies]
async-trait = "0.1"
tinymemory-api = { path = "../../vendor/tinymemory/crates/tinymemory-api", features = ["conformance"] }
+tinyagents-session = { path = "../../vendor/tinyagents/crates/tinyagents-session", features = ["testkit"] }
+tinystoragedrivers-testkit = { path = "../../vendor/tinystoragedrivers/crates/tinystoragedrivers-testkit" }
dirs = "6"
zeroize = "1"
# `cron_tests` builds core `CronJob`s, whose schedule types live in the
diff --git a/crates/openhuman-embed/src/harness/builder.rs b/crates/openhuman-embed/src/harness/builder.rs
index 5da75a5a80..0c9e056316 100644
--- a/crates/openhuman-embed/src/harness/builder.rs
+++ b/crates/openhuman-embed/src/harness/builder.rs
@@ -8,6 +8,7 @@
//! environment.
use std::path::PathBuf;
+use std::sync::Arc;
use super::access::Access;
use super::error::HarnessError;
@@ -38,6 +39,7 @@ pub struct HarnessBuilder {
host_kind: HostKind,
config: Option<Config>,
session: Option<Session>,
+ session_store: Option<Arc<dyn crate::SessionStoreProvider>>,
backend_url: Option<String>,
}
@@ -67,6 +69,7 @@ impl HarnessBuilder {
host_kind: HostKind::Library,
config: None,
session: None,
+ session_store: None,
backend_url: None,
}
}
@@ -228,6 +231,16 @@ impl HarnessBuilder {
self
}
+ /// Keep the harness agent's conversation state in a host-owned store.
+ ///
+ /// The provider is asked for the stores of the fixed `harness` agent. Pair
+ /// this with [`Workspace::Stateless`] when the harness must leave no
+ /// durable session data on disk.
+ pub fn session_store(mut self, provider: Arc<dyn crate::SessionStoreProvider>) -> Self {
+ self.session_store = Some(provider);
+ self
+ }
+
/// Start from a caller-supplied [`Config`] instead of the default.
///
/// Every other builder method is applied **on top** of it, so this is the
@@ -302,6 +315,9 @@ impl HarnessBuilder {
if let Some(session) = self.session {
runtime = runtime.session(session);
}
+ if let Some(session_store) = self.session_store {
+ runtime = runtime.session_store(session_store);
+ }
let runtime = runtime.build().await?;
let mut spec = AgentSpec::new(HARNESS_AGENT_ID)
diff --git a/crates/openhuman-embed/tests/harness_embed.rs b/crates/openhuman-embed/tests/harness_embed.rs
index 19003fb469..a207ee961a 100644
--- a/crates/openhuman-embed/tests/harness_embed.rs
+++ b/crates/openhuman-embed/tests/harness_embed.rs
@@ -21,7 +21,9 @@ mod common;
use common::gated_provider::GatedProvider;
use common::{offline_config, runtime};
-use openhuman_embed::{Access, Harness, Provider, Workspace};
+use openhuman_embed::{
+ Access, Harness, InMemorySessionStores, Provider, SessionStoreProvider, Workspace,
+};
use serde_json::json;
use wiremock::matchers::any;
use wiremock::{Mock, MockServer, ResponseTemplate};
@@ -129,6 +131,7 @@ fn a_harness_runs_a_turn_against_the_provider_it_was_given() {
// Answers at once until the overlap proof arms its gate.
let provider_server = GatedProvider::start(REPLY).await;
+ let session_store = std::sync::Arc::new(InMemorySessionStores::new());
let harness = std::sync::Arc::new(
bounded(
@@ -137,6 +140,7 @@ fn a_harness_runs_a_turn_against_the_provider_it_was_given() {
.config(config)
.workspace(Workspace::Ephemeral)
.backend_url(backend.uri())
+ .session_store(session_store.clone())
.provider(
Provider::openai_compatible(
format!("{}/v1", provider_server.uri()),
@@ -322,10 +326,7 @@ fn a_harness_runs_a_turn_against_the_provider_it_was_given() {
// The first session's transcript landed in the harness agent's
// own store under the workspace (the path-based transcript files
// are gone). A harness session id is its thread id.
- let transcripts =
- tinyagents_session::port::WorkspaceStores::open(&workspace_dir, "harness")
- .expect("the harness agent's workspace store")
- .transcripts();
+ let transcripts = session_store.for_agent("harness").transcripts;
assert!(
transcripts.root_for_thread(&first.session_id).is_some(),
"the first session's transcript was not persisted"
diff --git a/crates/openhuman-embed/tests/isolation_state.rs b/crates/openhuman-embed/tests/isolation_state.rs
index 3a6fa9b841..27b6a1ba0b 100644
--- a/crates/openhuman-embed/tests/isolation_state.rs
+++ b/crates/openhuman-embed/tests/isolation_state.rs
@@ -10,7 +10,8 @@ use common::{
tool_call_completion, tool_results,
};
use openhuman_embed::{
- Access, Agent, AgentDefinitionSpec, AgentSpec, Runtime, ToolScopeSpec, Workspace,
+ Access, Agent, AgentDefinitionSpec, AgentSpec, InMemorySessionStores, Runtime,
+ SessionStoreProvider, ToolScopeSpec, Workspace,
};
use serde_json::json;
@@ -32,10 +33,10 @@ fn transcript_files(dir: &std::path::Path) -> Vec<std::path::PathBuf> {
/// Whether `agent` has a root transcript for the test thread in its own store
/// under the workspace.
-fn has_transcript(agent: &Agent) -> bool {
- tinyagents_session::port::WorkspaceStores::open(agent.workspace_dir(), agent.id())
- .expect("the agent's workspace store")
- .transcripts()
+fn has_transcript(store: &dyn SessionStoreProvider, agent: &Agent) -> bool {
+ store
+ .for_agent(agent.id())
+ .transcripts
.root_for_thread(SESSION)
.is_some()
}
@@ -59,10 +60,12 @@ fn agents_on_one_workspace_keep_their_own_state() {
runtime().block_on(async {
tokio::spawn(async move {
let backend = stub_backend().await;
+ let session_store = std::sync::Arc::new(InMemorySessionStores::new());
let runtime = Runtime::builder()
.config(offline_config())
.workspace(Workspace::Ephemeral)
.backend_url(backend.uri())
+ .session_store(session_store.clone())
.access(Access::full())
.build()
.await
@@ -123,8 +126,14 @@ fn agents_on_one_workspace_keep_their_own_state() {
assert_ne!(a.transcripts_dir(), b.transcripts_dir());
assert!(a.transcripts_dir().starts_with(a.home_dir()));
assert!(b.transcripts_dir().starts_with(b.home_dir()));
- assert!(has_transcript(&a), "a's turns are stored under a");
- assert!(has_transcript(&b), "b's turns are stored under b");
+ assert!(
+ has_transcript(session_store.as_ref(), &a),
+ "a's turns are stored under a"
+ );
+ assert!(
+ has_transcript(session_store.as_ref(), &b),
+ "b's turns are stored under b"
+ );
assert!(
transcript_files(&a.workspace_dir().join("session_raw")).is_empty(),
"nothing is written to the shared transcript directory"
diff --git a/crates/openhuman-embed/tests/profile_cron_sweep.rs b/crates/openhuman-embed/tests/profile_cron_sweep.rs
index 54f21d2622..434914c9a0 100644
--- a/crates/openhuman-embed/tests/profile_cron_sweep.rs
+++ b/crates/openhuman-embed/tests/profile_cron_sweep.rs
@@ -64,7 +64,7 @@ async fn scenario() {
.await;
PointedInference::install(&inference.uri());
// The shared backend every sweeper would contend on.
- openhuman_core::storage::install(Arc::new(openhuman_core::storage::MemoryStorage::new()));
+ openhuman_core::storage::install(Arc::new(tinystoragedrivers_testkit::MemoryBackend::new()));
let root = tempfile::tempdir().unwrap();
let recorder = Arc::new(Recorder::default());
diff --git a/crates/openhuman-embed/tests/profile_operator_tools.rs b/crates/openhuman-embed/tests/profile_operator_tools.rs
index 5dae147bf0..b0f7e163b2 100644
--- a/crates/openhuman-embed/tests/profile_operator_tools.rs
+++ b/crates/openhuman-embed/tests/profile_operator_tools.rs
@@ -119,7 +119,7 @@ async fn scenario() {
.mount(&managed)
.await;
PointedInference::install(&managed.uri());
- openhuman_core::storage::install(Arc::new(openhuman_core::storage::MemoryStorage::new()));
+ openhuman_core::storage::install(Arc::new(tinystoragedrivers_testkit::MemoryBackend::new()));
let root = tempfile::tempdir().unwrap();
let recorder = Arc::new(Recorder::default());
diff --git a/crates/openhuman-embed/tests/profile_refused_tool_generation.rs b/crates/openhuman-embed/tests/profile_refused_tool_generation.rs
index b5760668fa..57688eef1f 100644
--- a/crates/openhuman-embed/tests/profile_refused_tool_generation.rs
+++ b/crates/openhuman-embed/tests/profile_refused_tool_generation.rs
@@ -105,7 +105,7 @@ async fn scenario() {
.mount(&managed)
.await;
PointedInference::install(&managed.uri());
- openhuman_core::storage::install(Arc::new(openhuman_core::storage::MemoryStorage::new()));
+ openhuman_core::storage::install(Arc::new(tinystoragedrivers_testkit::MemoryBackend::new()));
let root = tempfile::tempdir().unwrap();
let store = Arc::new(InMemorySessionStores::new());
diff --git a/crates/openhuman-embed/tests/profile_turn_serialization.rs b/crates/openhuman-embed/tests/profile_turn_serialization.rs
index 22b2756cf1..581c8032f3 100644
--- a/crates/openhuman-embed/tests/profile_turn_serialization.rs
+++ b/crates/openhuman-embed/tests/profile_turn_serialization.rs
@@ -83,7 +83,7 @@ async fn scenario() {
.mount(&inference)
.await;
PointedInference::install(&inference.uri());
- openhuman_core::storage::install(Arc::new(openhuman_core::storage::MemoryStorage::new()));
+ openhuman_core::storage::install(Arc::new(tinystoragedrivers_testkit::MemoryBackend::new()));
let root = tempfile::tempdir().unwrap();
let runtime = ProfileRuntime::builder(SaasConfig::new(root.path()))
diff --git a/crates/openhuman-embed/tests/runtime_agents.rs b/crates/openhuman-embed/tests/runtime_agents.rs
index f0b2288357..541e158bab 100644
--- a/crates/openhuman-embed/tests/runtime_agents.rs
+++ b/crates/openhuman-embed/tests/runtime_agents.rs
@@ -13,8 +13,9 @@ mod common;
use common::{chat_completion, offline_config, runtime, stub_backend};
use openhuman_embed::{
- Access, AgentDefinitionSpec, AgentError, AgentSpec, HostTurnTools, MemoryBinding, Provider,
- Runtime, SandboxModeSpec, ToolScopeSpec, Workspace,
+ Access, AgentDefinitionSpec, AgentError, AgentSpec, HostTurnTools, InMemorySessionStores,
+ MemoryBinding, Provider, Runtime, SandboxModeSpec, SessionStoreProvider, ToolScopeSpec,
+ Workspace,
};
use wiremock::matchers::{header, method, path};
use wiremock::{Mock, ResponseTemplate};
@@ -114,6 +115,7 @@ fn one_runtime_hosts_independently_configured_agents() {
#[allow(unused_variables)]
let skills = skills_fixture();
let beta_action = tempfile::tempdir().expect("beta action dir");
+ let session_store = std::sync::Arc::new(InMemorySessionStores::new());
// The core carries no hosted provider; supply the managed one the
// way the TinyHumans layer does, pointed at the mock.
@@ -125,6 +127,7 @@ fn one_runtime_hosts_independently_configured_agents() {
.workspace(Workspace::Ephemeral)
.backend_url(backend.uri())
.api_key(API_KEY)
+ .session_store(session_store.clone())
.build()
.await
.expect("runtime builds"),
@@ -411,9 +414,9 @@ fn one_runtime_hosts_independently_configured_agents() {
// Transcripts are keyed by agent and live in the agent's own store
// under the workspace, and a thread resumes its own history.
let listing = |agent_id: &str, session_id: &str| -> Vec<String> {
- tinyagents_session::port::WorkspaceStores::open(&workspace_dir, agent_id)
- .expect("the agent's workspace store")
- .transcripts()
+ session_store
+ .for_agent(agent_id)
+ .transcripts
.thread_transcripts(session_id, None)
.map(|found| found.roots.into_iter().map(|root| root.stem).collect())
.unwrap_or_default()