Skip to content

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

test(tinyagents): add coverage for journal, reasoning, run mode, and plan exit

Steven Enamakel6c123adf3f8b
diff --git a/crates/openhuman-core/src/agent/tinyagents/journal_tests.rs b/crates/openhuman-core/src/agent/tinyagents/journal_tests.rs
index f6f46801ec..0c35a4de43 100644
--- a/crates/openhuman-core/src/agent/tinyagents/journal_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/journal_tests.rs
@@ -9,16 +9,16 @@ async fn request_journal_runs_stay_with_the_agent_that_registered_them() {
let beta = test_agent_context(&root, "beta");
CoreContext::scope(std::sync::Arc::clone(&alpha), async {
- register_request_journal_run("req-shared", "run-alpha");
+ register_request_journal_run(&crate::core::runtime::DispatchCtx::ambient(), "req-shared", "run-alpha");
})
.await;
assert_eq!(
- CoreContext::scope(beta, async { take_request_journal_run("req-shared") }).await,
+ CoreContext::scope(beta, async { take_request_journal_run(&crate::core::runtime::DispatchCtx::ambient(), "req-shared") }).await,
None
);
assert_eq!(
- CoreContext::scope(alpha, async { take_request_journal_run("req-shared") }).await,
+ CoreContext::scope(alpha, async { take_request_journal_run(&crate::core::runtime::DispatchCtx::ambient(), "req-shared") }).await,
Some("run-alpha".to_string())
);
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rs b/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rs
index 5814d3f6c0..2abbfab92f 100644
--- a/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rs
@@ -83,20 +83,20 @@ fn thread_choice_wins_over_config_and_clears_back_to_it() {
let mut config = Config::default();
config.runtime.reasoning_effort = Some("low".into());
- apply_requested_effort(thread, Some("high")).expect("valid effort");
+ apply_requested_effort(&crate::core::runtime::DispatchCtx::ambient(), thread, Some("high")).expect("valid effort");
assert_eq!(
- turn_reasoning(Some(thread), Some(&config)),
+ turn_reasoning(&crate::core::runtime::DispatchCtx::ambient(), Some(thread), Some(&config)),
Some(ReasoningConfig::effort(ReasoningEffort::High))
);
// Absent leaves the thread's choice untouched.
- apply_requested_effort(thread, None).expect("absent is fine");
- assert_eq!(thread_effort(thread), Some(ReasoningEffort::High));
+ apply_requested_effort(&crate::core::runtime::DispatchCtx::ambient(), thread, None).expect("absent is fine");
+ assert_eq!(thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread), Some(ReasoningEffort::High));
- apply_requested_effort(thread, Some("default")).expect("clear");
- assert_eq!(thread_effort(thread), None);
+ apply_requested_effort(&crate::core::runtime::DispatchCtx::ambient(), thread, Some("default")).expect("clear");
+ assert_eq!(thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread), None);
assert_eq!(
- turn_reasoning(Some(thread), Some(&config)),
+ turn_reasoning(&crate::core::runtime::DispatchCtx::ambient(), Some(thread), Some(&config)),
Some(ReasoningConfig::effort(ReasoningEffort::Low))
);
}
@@ -104,39 +104,39 @@ fn thread_choice_wins_over_config_and_clears_back_to_it() {
#[test]
fn unknown_requested_effort_is_rejected_and_keeps_the_prior_choice() {
let thread = "reasoning-test-thread-reject";
- apply_requested_effort(thread, Some("off")).expect("valid effort");
- assert!(apply_requested_effort(thread, Some("turbo")).is_err());
- assert_eq!(thread_effort(thread), Some(ReasoningEffort::None));
- set_thread_effort(thread, None);
+ apply_requested_effort(&crate::core::runtime::DispatchCtx::ambient(), thread, Some("off")).expect("valid effort");
+ assert!(apply_requested_effort(&crate::core::runtime::DispatchCtx::ambient(), thread, Some("turbo")).is_err());
+ assert_eq!(thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread), Some(ReasoningEffort::None));
+ set_thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread, None);
}
#[test]
fn turn_without_thread_or_config_has_no_reasoning() {
- assert_eq!(turn_reasoning(None, None), None);
+ assert_eq!(turn_reasoning(&crate::core::runtime::DispatchCtx::ambient(), None, None), None);
}
#[test]
fn root_turn_follows_the_thread_choice() {
let thread = "reasoning-test-thread-root";
- set_thread_effort(thread, Some(ReasoningEffort::High));
+ set_thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread, Some(ReasoningEffort::High));
let mut ctx = crate::agent::tinyagents::host::OpenHumanRunContext::new();
ctx.thread_id = Some(thread.to_string());
assert_eq!(
turn_reasoning_for(&ctx, None, None),
Some(ReasoningConfig::effort(ReasoningEffort::High))
);
- set_thread_effort(thread, None);
+ set_thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread, None);
}
#[test]
fn subagent_turn_keeps_the_provider_default() {
let thread = "reasoning-test-thread-subagent";
- set_thread_effort(thread, Some(ReasoningEffort::High));
+ set_thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread, Some(ReasoningEffort::High));
let mut ctx = crate::agent::tinyagents::host::OpenHumanRunContext::new();
ctx.thread_id = Some(thread.to_string());
ctx.spawn_depth = 1;
assert_eq!(turn_reasoning_for(&ctx, None, None), None);
- set_thread_effort(thread, None);
+ set_thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread, None);
}
#[test]
@@ -156,7 +156,7 @@ fn root_turn_reasoning_reserves_output_room_with_a_budget() {
// the whole output cap and return `length` with no tool call. A capped
// turn now also carries a thinking budget of about 55% of that cap.
let thread = "reasoning-test-thread-budget";
- set_thread_effort(thread, Some(ReasoningEffort::High));
+ set_thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread, Some(ReasoningEffort::High));
let mut ctx = crate::agent::tinyagents::host::OpenHumanRunContext::new();
ctx.thread_id = Some(thread.to_string());
let reasoning = turn_reasoning_for(
@@ -164,7 +164,7 @@ fn root_turn_reasoning_reserves_output_room_with_a_budget() {
None,
Some(crate::inference::provider::AGENT_TURN_MAX_OUTPUT_TOKENS),
);
- set_thread_effort(thread, None);
+ set_thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread, None);
assert_eq!(
reasoning,
Some(ReasoningConfig {
@@ -239,16 +239,16 @@ async fn reasoning_effort_stays_with_the_agent_that_chose_it() {
let thread = "effort-shared-thread";
CoreContext::scope(std::sync::Arc::clone(&alpha), async {
- set_thread_effort(thread, Some(ReasoningEffort::High));
+ set_thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread, Some(ReasoningEffort::High));
})
.await;
assert_eq!(
- CoreContext::scope(alpha, async { thread_effort(thread) }).await,
+ CoreContext::scope(alpha, async { thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread) }).await,
Some(ReasoningEffort::High)
);
assert_eq!(
- CoreContext::scope(beta, async { thread_effort(thread) }).await,
+ CoreContext::scope(beta, async { thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread) }).await,
None
);
}
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 a91f77e9a1..586ef93d3c 100644
--- a/crates/openhuman-core/src/agent/tinyagents/run_mode_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/run_mode_tests.rs
@@ -3,23 +3,23 @@ use super::*;
#[test]
fn defaults_to_build_mode_for_an_unseen_thread() {
let thread_id = format!("run-mode-test-{}", uuid::Uuid::new_v4());
- assert_eq!(get_mode(&thread_id), RunMode::Build);
+ assert_eq!(get_mode(&crate::core::runtime::DispatchCtx::ambient(), &thread_id), RunMode::Build);
}
#[test]
fn set_mode_is_observed_through_a_fresh_handle_lookup() {
let thread_id = format!("run-mode-test-{}", uuid::Uuid::new_v4());
- set_mode(&thread_id, RunMode::Plan);
- assert_eq!(get_mode(&thread_id), RunMode::Plan);
- set_mode(&thread_id, RunMode::Build);
- assert_eq!(get_mode(&thread_id), RunMode::Build);
+ set_mode(&crate::core::runtime::DispatchCtx::ambient(), &thread_id, RunMode::Plan);
+ assert_eq!(get_mode(&crate::core::runtime::DispatchCtx::ambient(), &thread_id), RunMode::Plan);
+ set_mode(&crate::core::runtime::DispatchCtx::ambient(), &thread_id, RunMode::Build);
+ assert_eq!(get_mode(&crate::core::runtime::DispatchCtx::ambient(), &thread_id), RunMode::Build);
}
#[test]
fn handle_for_thread_shares_state_with_set_mode() {
let thread_id = format!("run-mode-test-{}", uuid::Uuid::new_v4());
- let handle = handle_for_thread(&thread_id);
- set_mode(&thread_id, RunMode::Plan);
+ let handle = handle_for_thread(&crate::core::runtime::DispatchCtx::ambient(), &thread_id);
+ set_mode(&crate::core::runtime::DispatchCtx::ambient(), &thread_id, RunMode::Plan);
assert_eq!(handle.get(), RunMode::Plan);
}
@@ -42,16 +42,16 @@ async fn plan_mode_stays_with_the_agent_that_set_it() {
let thread = "plan-mode-shared-thread";
CoreContext::scope(std::sync::Arc::clone(&alpha), async {
- set_mode(thread, RunMode::Plan);
+ set_mode(&crate::core::runtime::DispatchCtx::ambient(), thread, RunMode::Plan);
})
.await;
assert_eq!(
- CoreContext::scope(alpha, async { get_mode(thread) }).await,
+ CoreContext::scope(alpha, async { get_mode(&crate::core::runtime::DispatchCtx::ambient(), thread) }).await,
RunMode::Plan
);
assert_eq!(
- CoreContext::scope(beta, async { get_mode(thread) }).await,
+ CoreContext::scope(beta, async { get_mode(&crate::core::runtime::DispatchCtx::ambient(), thread) }).await,
RunMode::Build
);
}
diff --git a/crates/openhuman-core/src/agent/tools/plan_exit_tests.rs b/crates/openhuman-core/src/agent/tools/plan_exit_tests.rs
index e51267b970..9778bb5e42 100644
--- a/crates/openhuman-core/src/agent/tools/plan_exit_tests.rs
+++ b/crates/openhuman-core/src/agent/tools/plan_exit_tests.rs
@@ -17,6 +17,7 @@ impl ToolRunContext for ThreadContext {
async fn plan_exit_does_not_flip_while_a_review_is_parked() {
let thread_id = "plan-exit-parked-thread";
crate::agent::tinyagents::run_mode::set_mode(
+ &crate::core::runtime::DispatchCtx::ambient(),
thread_id,
tinyagents_harness::middleware::RunMode::Plan,
);
@@ -46,7 +47,7 @@ async fn plan_exit_does_not_flip_while_a_review_is_parked() {
.unwrap();
assert!(!result.is_error);
assert_eq!(
- crate::agent::tinyagents::run_mode::get_mode(thread_id),
+ crate::agent::tinyagents::run_mode::get_mode(&crate::core::runtime::DispatchCtx::ambient(), thread_id),
tinyagents_harness::middleware::RunMode::Plan,
"plan_exit must not flip to Build while a review is still parked"
);
@@ -69,7 +70,7 @@ async fn plan_exit_does_not_flip_while_a_review_is_parked() {
.unwrap();
assert!(!result.is_error);
assert_eq!(
- crate::agent::tinyagents::run_mode::get_mode(thread_id),
+ crate::agent::tinyagents::run_mode::get_mode(&crate::core::runtime::DispatchCtx::ambient(), thread_id),
tinyagents_harness::middleware::RunMode::Build
);
}