Skip to content

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

Merge upstream/main into fu-7801e-6

Steven Enamakel24461b1fe5b4
diff --cc crates/openhuman-core/src/agent/session_host/runtime_session/transcript.rs
index 033014569f,f6e1b9fde5..13e5445f6f
--- a/crates/openhuman-core/src/agent/session_host/runtime_session/transcript.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/transcript.rs
@@@ -21,11 -21,9 +21,11 @@@ impl OpenHumanSessionHost
}
self.session_history_locator_memo
.get_or_init(|| {
- let session_agent_id =
- crate::agent::session_store::current_agent_key_or(&self.agent_definition_id);
+ let session_agent_id = crate::agent::session_store::current_agent_key_or(
+ &self.dispatch_ctx(),
+ &self.agent_definition_id,
+ );
- transcripts_or_files(&self.dispatch_ctx(), &session_agent_id, &self.workspace_dir)
+ transcripts_or_files(&session_agent_id, &self.workspace_dir)
})
.clone()
}
diff --cc crates/openhuman-core/src/agent/session_store/mod.rs
index a7a57fa45d,bd3ab92adf..08c8cf5cd7
--- a/crates/openhuman-core/src/agent/session_store/mod.rs
+++ b/crates/openhuman-core/src/agent/session_store/mod.rs
@@@ -201,13 -256,25 +256,25 @@@ pub fn current(ctx: &crate::core::runti
/// serves a SaaS profile, else the context's agent, else `fallback` (the
/// session's own definition id), as before profiles existed.
#[must_use]
-pub fn current_agent_key_or(fallback: &str) -> String {
+pub fn current_agent_key_or(ctx: &crate::core::runtime::DispatchCtx, fallback: &str) -> String {
- let tenant =
- crate::core::runtime::tenant::isolated_unless_tenant(ctx.tenant(), "session_locator");
+ agent_key_for(
- &crate::core::runtime::tenant::current_tenant_or_isolated("session_locator"),
++ &crate::core::runtime::tenant::isolated_unless_tenant(ctx.tenant(), "session_locator"),
+ fallback,
+ )
+ }
+
+ /// The agent id `tenant`'s transcripts are kept under, for a caller that
+ /// already holds the request's tenant (an RPC handler's context): the
+ /// [`session_key`](crate::core::runtime::session_key) when it serves a SaaS
+ /// profile, else its agent, else `fallback` (the session's definition id).
-/// [`current_agent_key_or`] is this over the ambient tenant, so a reader that
++/// [`current_agent_key_or`] is this over a context's tenant, so a reader that
+ /// passes its tenant here resolves the same store the session host wrote to.
+ #[must_use]
+ pub fn agent_key_for(tenant: &crate::core::runtime::Tenant, fallback: &str) -> String {
if tenant.profile.is_some() {
- return crate::core::runtime::session_key(&tenant);
+ return crate::core::runtime::session_key(tenant);
}
- tenant.agent.unwrap_or_else(|| fallback.to_string())
+ tenant.agent.clone().unwrap_or_else(|| fallback.to_string())
}
/// The workspace the current [`CoreContext`](crate::core::runtime::CoreContext)
diff --cc crates/openhuman-core/src/agent/session_store/mod_tests.rs
index 97da9c0292,ea8bb8777d..e79752ec57
--- a/crates/openhuman-core/src/agent/session_store/mod_tests.rs
+++ b/crates/openhuman-core/src/agent/session_store/mod_tests.rs
@@@ -127,27 -176,10 +177,19 @@@ async fn under<T>(ctx: Arc<crate::core:
}
#[tokio::test]
- async fn desktop_session_keys_and_transcript_roots_are_unchanged() {
- let ws = std::path::Path::new("/ws");
+ async fn desktop_session_keys_are_unchanged() {
- assert_eq!(current_agent_key_or("orchestrator"), "orchestrator");
+ assert_eq!(
+ current_agent_key_or(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ "orchestrator"
+ ),
+ "orchestrator"
+ );
- assert_eq!(
- transcript_root(&crate::core::runtime::DispatchCtx::ambient(), ws),
- ws.to_path_buf()
- );
- let (key, root) = under(derived(None, Some("alpha")), || {
- (
- current_agent_key_or(
- &crate::core::runtime::DispatchCtx::ambient(),
- "orchestrator",
- ),
- transcript_root(&crate::core::runtime::DispatchCtx::ambient(), ws),
+ let key = under(derived(None, Some("alpha")), || {
- current_agent_key_or("orchestrator")
++ current_agent_key_or(
++ &crate::core::runtime::DispatchCtx::ambient(),
++ "orchestrator",
+ )
})
.await;
assert_eq!(key, "alpha");
@@@ -156,15 -187,8 +197,11 @@@
#[tokio::test]
async fn two_profiles_default_agents_keep_separate_session_keys_and_stores() {
- let ws = std::path::Path::new("/ws-profile");
- let (alice_key, alice_root) = under(derived(Some("alice"), None), || {
- (
- current_agent_key_or(
- &crate::core::runtime::DispatchCtx::ambient(),
- "orchestrator",
- ),
- transcript_root(&crate::core::runtime::DispatchCtx::ambient(), ws),
+ let alice_key = under(derived(Some("alice"), None), || {
- current_agent_key_or("orchestrator")
++ current_agent_key_or(
++ &crate::core::runtime::DispatchCtx::ambient(),
++ "orchestrator",
+ )
})
.await;
let bob_key = under(derived(Some("bob"), None), || {
diff --cc crates/openhuman-core/src/cron/scheduler/origin_delivery.rs
index 76b5b71888,e41df215e7..2a6ff1c61e
--- a/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs
+++ b/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs
@@@ -157,10 -161,11 +162,11 @@@ pub(crate) async fn deliver_to_origin
};
let text = output.trim();
- // A hosted profile's or an embedded agent's host routes the reply itself.
- let owner = ctx
- .tenant()
- .ok()
+ // The job's tenant: a hosted profile's or an embedded agent's host routes
+ // the reply itself; otherwise it keys the transcript store below.
- let tenant = crate::core::runtime::current_tenant().ok();
++ let tenant = ctx.tenant().ok();
+ let owner = tenant
+ .clone()
.filter(|tenant| tenant.profile.is_some() || tenant.agent.is_some());
if let (Some(sink), Some(owner)) = (crate::cron::host_delivery::installed(), owner) {
let thread_id = match origin {
diff --cc crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs
index 83d02496e0,ae380c0d96..50fdbc515a
--- a/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs
@@@ -250,28 -221,20 +251,32 @@@ async fn web_delivery_appends_to_the_re
agent_id: Some("orchestrator".into()),
}));
j.id = "job-1".into();
- deliver_to_origin(&cfg, &j, "run-1", "Drink water!")
- .await
- .unwrap();
- deliver_to_origin(&cfg, &j, "run-1", "Drink water!")
- .await
- .unwrap();
+ deliver_to_origin(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &cfg,
+ &j,
+ "run-1",
+ "Drink water!",
+ )
+ .await
+ .unwrap();
+ deliver_to_origin(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &cfg,
+ &j,
+ "run-1",
+ "Drink water!",
+ )
+ .await
+ .unwrap();
let head = locator.head_generation(&session);
- let path = resolve_keyed_transcript_path(&cfg.workspace_dir, &session_stem(&head)).unwrap();
- let resumed = read_transcript(&path).unwrap();
+ let resumed = locator
+ .read_session_transcript(&head)
+ .expect("the session's head is in the store")
+ .read_session()
+ .unwrap()
+ .unwrap();
assert_eq!(resumed.messages.len(), 3, "reply appended once");
let last = resumed.messages.last().unwrap();
assert_eq!(last.role, "assistant");