Skip to content

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

test(embed): assert runtime budget stop decision

Steven Enamakel3689a95ef382
diff --git a/crates/openhuman-embed/Cargo.toml b/crates/openhuman-embed/Cargo.toml
index c6f26179d3..51a27ae96b 100644
--- a/crates/openhuman-embed/Cargo.toml
+++ b/crates/openhuman-embed/Cargo.toml
@@ -44,6 +44,7 @@ url = "2"
uuid = { version = "1", features = ["v4"] }
[dev-dependencies]
+async-trait = "0.1"
dirs = "6"
env_logger = "0.11"
wiremock = "0.6"
diff --git a/crates/openhuman-embed/tests/runtime_agents.rs b/crates/openhuman-embed/tests/runtime_agents.rs
index 7ca83be184..004deb3910 100644
--- a/crates/openhuman-embed/tests/runtime_agents.rs
+++ b/crates/openhuman-embed/tests/runtime_agents.rs
@@ -21,6 +21,29 @@ use wiremock::{Mock, ResponseTemplate};
const API_KEY: &str = "th_test_key";
+struct RecordingBudgetStopHook {
+ inner: openhuman_core::agent::stop_hooks::BudgetStopHook,
+ reason: std::sync::Arc<std::sync::Mutex<Option<String>>>,
+}
+
+#[async_trait::async_trait]
+impl openhuman_core::agent::stop_hooks::StopHook for RecordingBudgetStopHook {
+ fn name(&self) -> &str {
+ "budget"
+ }
+
+ async fn check(
+ &self,
+ state: &openhuman_core::agent::stop_hooks::TurnState<'_>,
+ ) -> openhuman_core::agent::stop_hooks::StopDecision {
+ let decision = openhuman_core::agent::stop_hooks::StopHook::check(&self.inner, state).await;
+ if let openhuman_core::agent::stop_hooks::StopDecision::Stop { reason } = &decision {
+ *self.reason.lock().expect("stop reason lock") = Some(reason.clone());
+ }
+ decision
+ }
+}
+
/// A skills fixture with one bundle.
fn skills_fixture() -> tempfile::TempDir {
let dir = tempfile::tempdir().expect("skills fixture");
@@ -259,11 +282,21 @@ fn one_runtime_hosts_independently_configured_agents() {
.await
.expect("visible turn runs");
- let budgeted_turn = budget_agent
- .run("report a metered response")
- .await
- .expect("runtime-owned agent turn returns");
+ let stop_reason = std::sync::Arc::new(std::sync::Mutex::new(None));
+ let budgeted_turn = openhuman_core::agent::stop_hooks::with_stop_hooks(
+ vec![std::sync::Arc::new(RecordingBudgetStopHook {
+ inner: openhuman_core::agent::stop_hooks::BudgetStopHook::new(1.0),
+ reason: std::sync::Arc::clone(&stop_reason),
+ })],
+ budget_agent.run("report a metered response"),
+ )
+ .await
+ .expect("budgeted runtime-owned agent turn returns");
assert_eq!(budget_provider.received_requests().await.unwrap().len(), 1);
+ assert_eq!(
+ stop_reason.lock().expect("stop reason lock").as_deref(),
+ Some("turn cost $5.0000 reached cap $1.0000")
+ );
let usage = budgeted_turn
.usage
.expect("runtime-owned agent reports turn usage");