Skip to content

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

test(tinyagents): add golden transcripts for turn stop behaviour

Steven Enamakelc455542baab3
diff --git a/crates/openhuman-core/src/agent/tinyagents/budget_stop_turn_tests.rs b/crates/openhuman-core/src/agent/tinyagents/budget_stop_turn_tests.rs
index 44ec9b93ce..6d9534b78f 100644
--- a/crates/openhuman-core/src/agent/tinyagents/budget_stop_turn_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/budget_stop_turn_tests.rs
@@ -337,3 +337,123 @@ fn a_turn_before_its_wind_down_point_runs_to_its_final_answer() {
.join()
.expect("test thread panicked");
}
+
+#[derive(Clone, Copy)]
+enum GoldenStop {
+ Finishes,
+ BudgetCap,
+ DeadlineWindDown,
+}
+
+/// Run one scripted turn and render everything observable about how it
+/// stopped as a stable JSON object.
+async fn golden_turn(label: &str, stop: GoldenStop) -> serde_json::Value {
+ let tool_calls = Arc::new(std::sync::atomic::AtomicUsize::new(0));
+ let model_calls = Arc::new(std::sync::atomic::AtomicUsize::new(0));
+ let model: Arc<dyn ChatModel<()>> = Arc::new(BudgetedToolModel(model_calls.clone()));
+ let models = TurnModelSource::from_model(model)
+ .build("claude-sonnet-4-6", 0.0, None, None)
+ .expect("scripted turn models build");
+ let (tx, _rx) = tokio::sync::mpsc::channel(64);
+ let mut context = root_context(label, &format!("/tmp/{label}"), tx);
+ let stop_reason = Arc::new(std::sync::Mutex::new(None));
+ match stop {
+ GoldenStop::Finishes => {}
+ GoldenStop::BudgetCap => context.stop_hooks.push(Arc::new(RecordingBudgetStopHook {
+ inner: BudgetStopHook::new(1.0),
+ reason: Arc::clone(&stop_reason),
+ })),
+ GoldenStop::DeadlineWindDown => {
+ context.turn_deadline = Some(tinyagents_harness::turn_deadline::TurnDeadline::new(
+ std::time::Instant::now() - std::time::Duration::from_secs(800),
+ std::time::Duration::from_secs(900),
+ ));
+ }
+ }
+ let sidecar = context.session_sidecar.clone();
+ let outcome = run_root_turn_via_hosted_agent(
+ context,
+ hosted_base(),
+ "main".to_string(),
+ models,
+ "test".to_string(),
+ "claude-sonnet-4-6",
+ root_messages(label),
+ vec![Arc::new(vec![
+ Box::new(LimitedTool(tool_calls.clone())) as Box<dyn Tool>
+ ])],
+ None,
+ 50,
+ None,
+ None,
+ &[],
+ matches!(stop, GoldenStop::Finishes | GoldenStop::DeadlineWindDown),
+ None,
+ TurnContextMiddleware::default(),
+ None,
+ true,
+ )
+ .await
+ .expect("scripted turn returns its outcome");
+ let wind_down = sidecar
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .wind_down;
+ serde_json::json!({
+ "scenario": label,
+ "model_calls": outcome.model_calls,
+ "tool_calls": outcome.tool_calls,
+ "text": outcome.text,
+ "hit_cap": outcome.hit_cap,
+ "tool_outcomes": outcome.tool_outcomes.len(),
+ "stop_reason": stop_reason.lock().expect("stop reason lock").clone(),
+ "wind_down_recorded": wind_down,
+ "history": outcome
+ .history
+ .iter()
+ .map(|m| format!("{m:?}"))
+ .collect::<Vec<_>>(),
+ })
+}
+
+/// Pins the observable stop behaviour of a scripted turn over the host's
+/// driver path: final answer, budget-cap pause (with its stop reason) and
+/// deadline wind-down. Regenerate with `UPDATE_TURN_STOP_GOLDEN=1` only when a
+/// behaviour change is intended.
+#[test]
+fn turn_stop_transcripts_match_golden() {
+ std::thread::Builder::new()
+ .stack_size(crate::core::runtime::AGENT_WORKER_STACK_BYTES)
+ .spawn(|| {
+ tokio::runtime::Builder::new_current_thread()
+ .enable_all()
+ .build()
+ .expect("test runtime")
+ .block_on(async {
+ let out = vec![
+ golden_turn("golden-final", GoldenStop::Finishes).await,
+ golden_turn("golden-budget", GoldenStop::BudgetCap).await,
+ golden_turn("golden-wind-down", GoldenStop::DeadlineWindDown).await,
+ ];
+ let actual =
+ serde_json::to_string_pretty(&serde_json::Value::Array(out)).unwrap()
+ + "\n";
+ let path = concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/src/agent/tinyagents/fixtures/turn_stop_golden.json"
+ );
+ if std::env::var_os("UPDATE_TURN_STOP_GOLDEN").is_some() {
+ std::fs::write(path, &actual).unwrap();
+ return;
+ }
+ assert_eq!(
+ actual,
+ include_str!("fixtures/turn_stop_golden.json"),
+ "turn stop transcript changed"
+ );
+ });
+ })
+ .expect("test thread")
+ .join()
+ .expect("test thread panicked");
+}
diff --git a/crates/openhuman-core/src/agent/tinyagents/fixtures/turn_stop_golden.json b/crates/openhuman-core/src/agent/tinyagents/fixtures/turn_stop_golden.json
new file mode 100644
index 0000000000..fe51488c70
--- /dev/null
+++ b/crates/openhuman-core/src/agent/tinyagents/fixtures/turn_stop_golden.json
@@ -0,0 +1 @@
+[]