Skip to content

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

test(agent): cover per-agent plan mode (#7032)

oxoxDevce5fd087038e
diff --git a/crates/openhuman-core/src/agent/tinyagents/run_mode_tests.rs b/crates/openhuman-core/src/agent/tinyagents/run_mode_tests.rs
index 324e52f0e1..a91f77e9a1 100644
--- a/crates/openhuman-core/src/agent/tinyagents/run_mode_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/run_mode_tests.rs
@@ -31,3 +31,27 @@ fn mode_label_round_trips() {
assert_eq!(parse_mode_label("build"), Some(RunMode::Build));
assert_eq!(parse_mode_label("nonsense"), None);
}
+
+#[tokio::test]
+async fn plan_mode_stays_with_the_agent_that_set_it() {
+ use crate::core::runtime::agent_scope::test_agent_context;
+ use crate::core::runtime::{context::CoreContext, DomainSet};
+ let root = CoreContext::for_test(DomainSet::full(), None);
+ let alpha = test_agent_context(&root, "alpha");
+ let beta = test_agent_context(&root, "beta");
+ let thread = "plan-mode-shared-thread";
+
+ CoreContext::scope(std::sync::Arc::clone(&alpha), async {
+ set_mode(thread, RunMode::Plan);
+ })
+ .await;
+
+ assert_eq!(
+ CoreContext::scope(alpha, async { get_mode(thread) }).await,
+ RunMode::Plan
+ );
+ assert_eq!(
+ CoreContext::scope(beta, async { get_mode(thread) }).await,
+ RunMode::Build
+ );
+}
diff --git a/crates/openhuman-core/src/core/runtime/agent_scope.rs b/crates/openhuman-core/src/core/runtime/agent_scope.rs
index fc33087375..683f399b22 100644
--- a/crates/openhuman-core/src/core/runtime/agent_scope.rs
+++ b/crates/openhuman-core/src/core/runtime/agent_scope.rs
@@ -167,6 +167,20 @@ pub fn current_agent_id() -> Option<String> {
CoreContext::current().and_then(|ctx| ctx.session_agent().map(str::to_owned))
}
+/// A context derived from `parent` for `agent_id`, for tests that need two
+/// agents side by side.
+#[cfg(test)]
+pub(crate) fn test_agent_context(parent: &Arc<CoreContext>, agent_id: &str) -> Arc<CoreContext> {
+ parent.derive_with(
+ super::ContextOverlay::new(
+ crate::config::Config::default(),
+ super::DomainSet::kernel(),
+ crate::tools::toolpacks::ToolGroups::none(),
+ )
+ .session_agent(agent_id),
+ )
+}
+
#[cfg(test)]
#[path = "agent_scope_tests.rs"]
mod tests;