Skip to content

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

refactor(tinyagents): group harness host callbacks into a policy struct

Steven Enamakel357616ac00dd
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 11109eecab..48c00b2af7 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1075,8 +1075,8 @@ mod tool_surface;
#[path = "runtime_session_juice_tests.rs"]
mod juice_tests;
-#[path = "prelude_integrations.rs"]
mod parent_snapshot;
+#[path = "prelude_integrations.rs"]
mod prelude_integrations;
#[cfg(test)]
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
index 59257c192a..734070978f 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
@@ -64,16 +64,9 @@ pub(super) fn assemble_turn_harness(
context_window: Option<u64>,
early_exit_tools: &[&str],
context_mw: TurnContextMiddleware,
- stop_hooks: Vec<
- Arc<dyn tinyagents_harness::middleware::StopHook<crate::agent::cost::TurnCost>>,
- >,
- // The turn's agent/turn tool callbacks (`OpenHumanRunContext::tool_hooks`),
- // registered after the runtime's global ones, and the host's cap on real
- // tool invocations (`OpenHumanRunContext::tool_call_limit`).
- (scoped_tool_hooks, tool_call_cap): (
- Vec<Arc<dyn crate::agent::hooks::ToolHook>>,
- Option<usize>,
- ),
+ // Stop policies, scoped tool callbacks (registered after the runtime's
+ // global ones) and the host's tool-call cap, from the explicit run context.
+ host_policy: super::host::HarnessHostPolicy,
tool_policy: Option<ToolPolicyEnforcement>,
required_capabilities: Option<CapabilitySet>,
deterministic_cacheable: bool,
@@ -113,6 +106,11 @@ pub(super) fn assemble_turn_harness(
memory_turn: Option<Arc<crate::memory::lifecycle::hooks::MemoryTurn>>,
tool_rules: Option<Arc<tinyagents_harness::tool::ToolRulePolicy>>, // `OpenHumanRunContext::tool_rules`
) -> AssembledTurnHarness {
+ let super::host::HarnessHostPolicy {
+ stop_hooks,
+ tool_hooks: scoped_tool_hooks,
+ tool_call_cap,
+ } = host_policy;
let mut harness: AgentHarness<(), OpenHumanRunContext> = AgentHarness::new();
// Cross-route fallback ownership (issue #4249, Workstream 02.2): populate the
// SDK `RunPolicy.fallback` with the ordered same-family route chain for this
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly_tests.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly_tests.rs
index 93dc363596..c10aa1deb7 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly_tests.rs
@@ -85,9 +85,7 @@ fn assembled_with(
None,
&[],
TurnContextMiddleware::default(),
- Vec::new(),
- Vec::new(),
- None,
+ Default::default(),
None,
None,
false,
@@ -205,9 +203,7 @@ async fn run_slow_first_byte_turn(
None,
&[],
TurnContextMiddleware::default(),
- Vec::new(),
- Vec::new(),
- None,
+ Default::default(),
None,
None,
false,
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/mod.rs b/crates/openhuman-core/src/agent/tinyagents/host/mod.rs
index ed97e6e243..c69bbfa250 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/mod.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/mod.rs
@@ -50,7 +50,7 @@ pub use definition_registry::OpenHumanDefinitionRegistry;
pub use learning_sink::OpenHumanLearningSink;
pub use model_resolver::OpenHumanModelResolver;
pub use progress_sink::OpenHumanProgressSink;
-pub(crate) use run_context::direct_subagent_child;
+pub(crate) use run_context::{direct_subagent_child, HarnessHostPolicy};
pub use run_context::{
decide_dispatch, DispatchDecision, DispatchInputs, LastTurnUsage, OpenHumanRunContext,
OpenHumanRunExt, SubagentUsageEntry, TurnDispatchState,
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
index 9e42378d7e..392ce55e1e 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -388,6 +388,18 @@ pub struct OpenHumanRunContext {
pub(crate) memory_turn: Option<Arc<crate::memory::lifecycle::hooks::MemoryTurn>>,
}
+/// The host callbacks and caps a turn's harness assembly installs, taken from
+/// the explicit run context.
+#[derive(Clone, Default)]
+pub(crate) struct HarnessHostPolicy {
+ /// Stop policies evaluated after each model call.
+ pub(crate) stop_hooks: Vec<Arc<dyn StopHook<crate::agent::cost::TurnCost>>>,
+ /// Agent/turn tool callbacks, registered after the runtime's global ones.
+ pub(crate) tool_hooks: Vec<Arc<dyn crate::agent::hooks::ToolHook>>,
+ /// The host's cap on real tool invocations.
+ pub(crate) tool_call_cap: Option<usize>,
+}
+
/// Minimal immutable authority view exposed to shared tools through the
/// harness's typed state-view seam.
#[derive(Clone, Debug, Default)]
@@ -558,6 +570,15 @@ impl OpenHumanRunContext {
self.parent.insert(parent)
}
+ /// The callbacks and caps this turn's harness assembly installs.
+ pub(crate) fn harness_host_policy(&self) -> HarnessHostPolicy {
+ HarnessHostPolicy {
+ stop_hooks: self.stop_hooks.clone(),
+ tool_hooks: self.tool_hooks.clone(),
+ tool_call_cap: self.tool_call_limit,
+ }
+ }
+
/// The real tool invocation budget for a turn of `max_iterations`: the
/// product default, narrowed by the host's explicit cap.
pub(crate) fn tool_call_limit_for(&self, max_iterations: usize) -> usize {
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs b/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs
index a5461aa127..a35742c632 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs
@@ -276,8 +276,7 @@ pub(super) async fn run_turn_via_tinyagents_body(
context_window,
early_exit_tools,
context_mw,
- run_context.stop_hooks.clone(),
- (run_context.tool_hooks.clone(), run_context.tool_call_limit),
+ run_context.harness_host_policy(),
tool_policy.clone(),
routes::turn_required_capabilities(model),
deterministic_cacheable,
diff --git a/scripts/ci/check-openhuman-rust-layout.mjs b/scripts/ci/check-openhuman-rust-layout.mjs
index f6adc435ac..89dd929209 100644
--- a/scripts/ci/check-openhuman-rust-layout.mjs
+++ b/scripts/ci/check-openhuman-rust-layout.mjs
@@ -34,7 +34,7 @@ const LEGACY_LIMIT_ENTRIES = [
// provider, security, memory, tool and prompt policy. Generic session
// state moved to tinyagents-runtime; this remaining composition is split in
// a follow-up without reintroducing an old harness/session exception.
- ["crates/openhuman-core/src/agent/session_host/builder/factory.rs", 975],
+ ["crates/openhuman-core/src/agent/session_host/builder/factory.rs", 974],
["crates/openhuman-core/src/agent/subagent_host/lifecycle.rs", 1247],
["crates/openhuman-core/src/agent/subagent_host/ops/runner.rs", 1046],
["crates/openhuman-core/src/web_chat/progress_bridge.rs", 1261],