Skip to content

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

feat(agent): add live tool harness for tinyagents

Steven Enamakel7687aec9e9c5
diff --git a/crates/openhuman-core/src/agent/session_host/live_tools.rs b/crates/openhuman-core/src/agent/session_host/live_tools.rs
index 5b7cbaed8e..16f51e511d 100644
--- a/crates/openhuman-core/src/agent/session_host/live_tools.rs
+++ b/crates/openhuman-core/src/agent/session_host/live_tools.rs
@@ -34,6 +34,7 @@ impl OpenHumanSessionHost {
channel: self.event_channel.clone(),
}),
has_thread: self.thread_id.is_some(),
+ dispatch: crate::core::runtime::DispatchCtx::from_weak(self.host_env.core.as_ref()),
}
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/bundle.rs b/crates/openhuman-core/src/agent/tinyagents/host/bundle.rs
index 898e48f95b..09d2a75c6e 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/bundle.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/bundle.rs
@@ -192,7 +192,7 @@ impl OpenHumanHostBundleFactory {
// stays registered as the host capability with an unconsumed channel;
// nothing OpenHuman renders depends on it.
let progress = Arc::new(OpenHumanProgressSink::new(tokio::sync::mpsc::channel(1).0));
- let learning = Arc::new(OpenHumanLearningSink::new(inputs.post_turn_hooks));
+ let learning = Arc::new(OpenHumanLearningSink::new(inputs.post_turn_hooks).with_dispatch(turn.dispatch_ctx()));
let tool_outcomes = Arc::new(OpenHumanToolOutcomeClassifier::new());
let capabilities = HostCapabilities::new(
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/learning_sink.rs b/crates/openhuman-core/src/agent/tinyagents/host/learning_sink.rs
index d97958d60b..fde436bf4d 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/learning_sink.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/learning_sink.rs
@@ -34,6 +34,8 @@ use crate::agent::hooks::{self, PostTurnHook, TurnContext};
pub struct OpenHumanLearningSink {
/// Hooks fired, in parallel, for every completed turn.
hooks: Vec<Arc<dyn PostTurnHook>>,
+ /// The owning turn's dispatch context; unbound falls back to the task's.
+ dispatch: Option<std::sync::Weak<crate::core::runtime::CoreContext>>,
}
impl OpenHumanLearningSink {
@@ -44,7 +46,16 @@ impl OpenHumanLearningSink {
/// hosts to pass `None` for the capability in that case, so absence stays
/// distinguishable from a sink that ran and did nothing.
pub fn new(hooks: Vec<Arc<dyn PostTurnHook>>) -> Self {
- Self { hooks }
+ Self {
+ hooks,
+ dispatch: None,
+ }
+ }
+
+ /// Binds the owning turn's dispatch context.
+ pub fn with_dispatch(mut self, dispatch: crate::core::runtime::DispatchCtx) -> Self {
+ self.dispatch = dispatch.downgrade();
+ self
}
/// Appends one more hook.
@@ -112,10 +123,9 @@ impl LearningSink for OpenHumanLearningSink {
self.hooks.len()
);
- // Transitional (#7801): the learning sink is built without a context.
hooks::fire_hooks(
&self.hooks,
- &crate::core::runtime::DispatchCtx::ambient(),
+ &crate::core::runtime::DispatchCtx::from_weak(self.dispatch.as_ref()),
Self::turn_context_from(summary),
);
Ok(())
diff --git a/crates/openhuman-core/src/agent/tinyagents/live_harness.rs b/crates/openhuman-core/src/agent/tinyagents/live_harness.rs
index f0b1b8ef92..969b85de6d 100644
--- a/crates/openhuman-core/src/agent/tinyagents/live_harness.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/live_harness.rs
@@ -53,6 +53,8 @@ pub(crate) struct LiveToolSurface {
/// The session's agent/turn tool callbacks, registered after the
/// runtime's global ones.
pub(crate) tool_hooks: Vec<Arc<dyn crate::agent::hooks::ToolHook>>,
+ /// The context the session acts under (its embedder hooks come from it).
+ pub(crate) dispatch: crate::core::runtime::DispatchCtx,
}
/// Builds the live session's tool harness.
@@ -65,6 +67,7 @@ pub(crate) fn assemble_live_tool_harness(
tool_policy,
has_thread,
tool_hooks,
+ dispatch,
} = surface;
let mut harness: AgentHarness<(), OpenHumanRunContext> = AgentHarness::new();
harness.with_policy(run_policy_for(LIVE_MAX_TOOL_CALLS, false));
@@ -122,7 +125,7 @@ pub(crate) fn assemble_live_tool_harness(
),
));
let mut embedder_tool_hooks =
- crate::agent::hooks::embedder_tool_hooks_in(&crate::core::runtime::DispatchCtx::ambient());
+ crate::agent::hooks::embedder_tool_hooks_in(&dispatch);
embedder_tool_hooks.extend(tool_hooks);
if !embedder_tool_hooks.is_empty() {
harness.push_middleware(Arc::new(
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
index c711535979..8483c5f23e 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
@@ -519,6 +519,7 @@ async fn drive_turn(
required_capabilities: routes::turn_required_capabilities(model),
deterministic_cacheable,
has_route_fallback,
+ dispatch: run_context.dispatch_ctx(),
hosted_security_gate,
pause_at_cap,
run_mode: run_context.thread_id.as_deref().map(|thread_id| {
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs b/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
index bd4f0d821a..ed67a44d02 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_middleware.rs
@@ -133,6 +133,7 @@ pub(super) fn install_turn_middleware(
required_capabilities,
deterministic_cacheable,
has_route_fallback,
+ dispatch,
hosted_security_gate,
pause_at_cap,
run_mode,
@@ -563,7 +564,7 @@ pub(super) fn install_turn_middleware(
// reverse-order `after_tool` chain is safe — it cannot perturb the
// summarization/cap or tool-outcome capture layers.
let mut embedder_tool_hooks =
- crate::agent::hooks::embedder_tool_hooks_in(&crate::core::runtime::DispatchCtx::ambient());
+ crate::agent::hooks::embedder_tool_hooks_in(&dispatch);
embedder_tool_hooks.extend(scoped_tool_hooks);
if !embedder_tool_hooks.is_empty() {
harness.push_middleware(Arc::new(