Skip to content

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

refactor(stop-hooks): re-export stop hook types from tinyagents-harness

Steven Enamakela8442bda9635
diff --git a/crates/openhuman-core/src/agent/goals/runtime.rs b/crates/openhuman-core/src/agent/goals/runtime.rs
index e2448674d3..4c915d9652 100644
--- a/crates/openhuman-core/src/agent/goals/runtime.rs
+++ b/crates/openhuman-core/src/agent/goals/runtime.rs
@@ -26,9 +26,9 @@ use tinyagents_graph::goals::{BudgetVerdict, GoalBudgetGuard};
use super::store::{self, goals_store};
use super::{ThreadGoal, ThreadGoalStatus};
-use crate::agent::stop_hooks::{StopDecision, StopHook, TurnState};
use crate::core::bus::BUS;
use crate::core::events::DomainEvent;
+use tinyagents_harness::middleware::{StopDecision, StopHook, TurnState};
/// Load the goal for an explicitly supplied chat thread.
pub async fn load_for_thread(workspace_dir: &Path, thread_id: Option<&str>) -> Option<ThreadGoal> {
@@ -253,7 +253,7 @@ impl StopHook<crate::agent::cost::TurnCost> for GoalBudgetStopHook {
"thread_goal_budget"
}
- async fn check(&self, ctx: &TurnState<'_>) -> StopDecision {
+ async fn check(&self, ctx: &TurnState<'_, crate::agent::cost::TurnCost>) -> StopDecision {
let store = goals_store(&self.workspace_dir);
let in_flight = turn_tokens(ctx.cost.input_tokens, ctx.cost.output_tokens);
match self.guard.check(&store, in_flight).await {
diff --git a/crates/openhuman-core/src/agent/stop_hooks.rs b/crates/openhuman-core/src/agent/stop_hooks.rs
index a69ae06660..84263a8c2c 100644
--- a/crates/openhuman-core/src/agent/stop_hooks.rs
+++ b/crates/openhuman-core/src/agent/stop_hooks.rs
@@ -21,10 +21,7 @@ use crate::agent::cost::TurnCost;
use async_trait::async_trait;
use std::sync::Arc;
-pub use tinyagents_harness::middleware::library::{StopDecision, StopHook};
-
-/// Host accounting snapshot supplied to the harness-owned policy contract.
-pub type TurnState<'a> = tinyagents_harness::middleware::library::TurnState<'a, TurnCost>;
+use tinyagents_harness::middleware::{StopDecision, StopHook, TurnState};
tokio::task_local! {
static CURRENT_STOP_HOOKS: Vec<Arc<dyn StopHook<TurnCost>>>;
@@ -65,7 +62,7 @@ impl StopHook<TurnCost> for BudgetStopHook {
"budget"
}
- async fn check(&self, ctx: &TurnState<'_>) -> StopDecision {
+ async fn check(&self, ctx: &TurnState<'_, TurnCost>) -> StopDecision {
if !self.max_usd.is_finite() || self.max_usd <= 0.0 {
return StopDecision::Stop {
reason: format!("invalid budget cap configured: max_usd={}", self.max_usd),
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 8af158c0cf..8d74a7b4f7 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
@@ -2,10 +2,11 @@
//! turn-deadline wind-down, the two graceful pauses of a top-level turn.
use super::*;
-use crate::agent::stop_hooks::{BudgetStopHook, StopDecision, StopHook, TurnState};
+use crate::agent::stop_hooks::BudgetStopHook;
use crate::agent::tinyagents::TurnModelSource;
use async_trait::async_trait;
use std::sync::Arc;
+use tinyagents_harness::middleware::{StopDecision, StopHook, TurnState};
use tinyinference_llm::model::{ChatModel, ModelProfile, ModelRequest, ModelResponse};
use tinyinference_llm::tool::ToolCall;
use tinyinference_llm::usage::Usage;
@@ -82,7 +83,7 @@ impl StopHook<crate::agent::cost::TurnCost> for RecordingBudgetStopHook {
self.inner.name()
}
- async fn check(&self, state: &TurnState<'_>) -> StopDecision {
+ async fn check(&self, state: &TurnState<'_, crate::agent::cost::TurnCost>) -> StopDecision {
let decision = self.inner.check(state).await;
if let StopDecision::Stop { reason } = &decision {
*self.reason.lock().expect("stop reason lock") = Some(reason.clone());
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs
index 79b6cd948e..2ef34edb91 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs
@@ -596,9 +596,10 @@ async fn nudges_for_a_hoisting_model_add_no_system_message() {
let injector = mw.nudge_injector();
// The injector must remain in the before-model pass after a prior
// middleware requests retry control, or the queued correction is lost.
- assert!(tinyagents_harness::middleware::Middleware::is_observer(
- &injector
- ));
+ assert!(tinyagents_harness::middleware::Middleware::<
+ (),
+ crate::agent::tinyagents::host::OpenHumanRunContext,
+ >::is_observer(&injector));
run_ctx.model_profile = Some(tinyinference_llm::model::ModelProfile {
hoists_system_messages: true,
mid_conversation_system_messages: true,
diff --git a/crates/openhuman-embed/Cargo.toml b/crates/openhuman-embed/Cargo.toml
index d2875da0d3..3e28c0653c 100644
--- a/crates/openhuman-embed/Cargo.toml
+++ b/crates/openhuman-embed/Cargo.toml
@@ -67,6 +67,7 @@ tinymcp-bus = { path = "../../vendor/tinymcp/crates/tinymcp-bus" }
# The session store port (`SessionStoreProvider`) a host implements to keep
# conversations in its own database, and the in-memory provider; same path as
# the core's so one copy resolves.
+tinyagents-harness = { path = "../../vendor/tinyagents/crates/tinyagents-harness" }
tinyagents-session = { path = "../../vendor/tinyagents/crates/tinyagents-session" }
# The wire request/response types `complete` converts to; same path as the
# core's so one copy resolves.
diff --git a/crates/openhuman-embed/src/lib.rs b/crates/openhuman-embed/src/lib.rs
index 45a7388d77..ff551aebfd 100644
--- a/crates/openhuman-embed/src/lib.rs
+++ b/crates/openhuman-embed/src/lib.rs
@@ -200,9 +200,10 @@ pub mod seams {
pub use openhuman_core::agent::cost::TurnCost;
pub use openhuman_core::agent::hooks::{PostTurnHook, ToolHook};
pub use openhuman_core::agent::hooks::{ToolHookContext, ToolHookDecision, TurnContext};
- pub use openhuman_core::agent::stop_hooks::{
- BudgetStopHook, StopDecision, StopHook, TurnState,
- };
+ pub use openhuman_core::agent::stop_hooks::BudgetStopHook;
+ pub use tinyagents_harness::middleware::{StopDecision, StopHook};
+ /// Product cost snapshot passed to harness-owned stop policies.
+ pub type TurnState<'a> = tinyagents_harness::middleware::TurnState<'a, TurnCost>;
pub use openhuman_core::core::all::{ControllerExtension, DomainGroup};
pub use openhuman_core::core::server_launcher::{HostBoot, ServeRequest, ServerLauncher};
pub use openhuman_core::security::SecurityPolicy;
diff --git a/crates/openhuman-embed/tests/runtime_agents.rs b/crates/openhuman-embed/tests/runtime_agents.rs
index ff80ae99ba..5bcef482d7 100644
--- a/crates/openhuman-embed/tests/runtime_agents.rs
+++ b/crates/openhuman-embed/tests/runtime_agents.rs
@@ -27,7 +27,7 @@ struct RecordingBudgetStopHook {
}
#[async_trait::async_trait]
-impl openhuman_core::agent::stop_hooks::StopHook<openhuman_core::agent::cost::TurnCost>
+impl openhuman_embed::seams::StopHook<openhuman_core::agent::cost::TurnCost>
for RecordingBudgetStopHook
{
fn name(&self) -> &str {
@@ -36,10 +36,10 @@ impl openhuman_core::agent::stop_hooks::StopHook<openhuman_core::agent::cost::Tu
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 {
+ state: &openhuman_embed::seams::TurnState<'_>,
+ ) -> openhuman_embed::seams::StopDecision {
+ let decision = openhuman_embed::seams::StopHook::check(&self.inner, state).await;
+ if let openhuman_embed::seams::StopDecision::Stop { reason } = &decision {
*self.reason.lock().expect("stop reason lock") = Some(reason.clone());
}
decision