The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(agent): route embedder hooks through shared hook registry
Steven Enamakel5ff7caecf891
diff --git a/crates/openhuman-core/src/agent/hooks.rs b/crates/openhuman-core/src/agent/hooks.rsindex 31c21abd8b..d9f8e27d01 100644--- a/crates/openhuman-core/src/agent/hooks.rs+++ b/crates/openhuman-core/src/agent/hooks.rs@@ -248,6 +248,18 @@ pub trait ToolHook: Send + Sync {}}+ /// [`before_tool_decision`](ToolHook::before_tool_decision) for the call+ /// `dispatch` runs for: the context of the turn that raised it. A hook that+ /// reads the acting tenant or profile overrides this and takes it from+ /// `dispatch`; the default ignores it.+ async fn before_tool_decision_in(+ &self,+ _dispatch: &crate::core::runtime::DispatchCtx,+ context: &ToolHookContext,+ ) -> ToolHookDecision {+ self.before_tool_decision(context).await+ }+/// Observe a completed tool and optionally append text to its result, which/// the model then sees. Defaults to [`after_tool`](ToolHook::after_tool)/// with no appended text.diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rsindex f91c2edb14..654bb520c9 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rs@@ -90,8 +90,9 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>agent_id,cwd,};+ let dispatch = ctx.data.dispatch_ctx();for hook in &self.hooks {- match hook.before_tool_decision(&context).await {+ match hook.before_tool_decision_in(&dispatch, &context).await {crate::agent::hooks::ToolHookDecision::Proceed => {}// A rewrite is applied to the live call *and* to the context// handed to later hooks, so a chain of hooks each narrowing the@@ -171,8 +172,9 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>agent_id,cwd,};+ let dispatch = ctx.data.dispatch_ctx();for hook in &self.hooks {- let refusal = match hook.before_tool_decision(&context).await {+ let refusal = match hook.before_tool_decision_in(&dispatch, &context).await {crate::agent::hooks::ToolHookDecision::Proceed => continue,crate::agent::hooks::ToolHookDecision::ProceedWith(_) => {"rewrites the call, which a nested call cannot apply".to_string()diff --git a/crates/openhuman-core/src/profiles/capabilities.rs b/crates/openhuman-core/src/profiles/capabilities.rsindex 37c7f36501..9fa60cdbf3 100644--- a/crates/openhuman-core/src/profiles/capabilities.rs+++ b/crates/openhuman-core/src/profiles/capabilities.rs@@ -265,12 +265,20 @@ impl ToolHook for ProfilePermission {Ok(())}async fn before_tool_decision(&self, context: &ToolHookContext) -> ToolHookDecision {- // The hook runs inside the turn's own task, so its tenant is the ambient one.- let dispatch = DispatchCtx::ambient();+ // A caller that raised the call without a turn context: the calling+ // task's own, as every call before the context was passed explicitly.+ self.before_tool_decision_in(&DispatchCtx::from_weak(None), context)+ .await+ }+ async fn before_tool_decision_in(+ &self,+ dispatch: &DispatchCtx,+ context: &ToolHookContext,+ ) -> ToolHookDecision {let tenant = dispatch.tenant().ok().and_then(|tenant| tenant.profile);if tenant.as_deref() != Some(self.profile.as_str())|| self.fence.check_local(super::lease::now_ms()).is_err()- || !self.capabilities.admits(&dispatch, &context.tool_name)+ || !self.capabilities.admits(dispatch, &context.tool_name){return ToolHookDecision::Deny("tool is outside the hosted profile capability boundary".into(),@@ -278,7 +286,7 @@ impl ToolHook for ProfilePermission {}match &self.capabilities.permission {Some(permission) => {- let binding = super::provider_settings::ProfileProviderSettings::in_ctx(&dispatch);+ let binding = super::provider_settings::ProfileProviderSettings::in_ctx(dispatch);let canonical = binding.as_ref().and_then(|binding| binding.canonical_role_name(&context.tool_name));diff --git a/crates/openhuman-embed/src/runtime/live_hooks.rs b/crates/openhuman-embed/src/runtime/live_hooks.rsindex 6ec4be273c..70b0e23e9b 100644--- a/crates/openhuman-embed/src/runtime/live_hooks.rs+++ b/crates/openhuman-embed/src/runtime/live_hooks.rs@@ -28,6 +28,13 @@ impl ToolHook for NamedToolHook {async fn before_tool_decision(&self, context: &ToolHookContext) -> ToolHookDecision {self.1.before_tool_decision(context).await}+ async fn before_tool_decision_in(+ &self,+ dispatch: &openhuman_core::core::runtime::DispatchCtx,+ context: &ToolHookContext,+ ) -> ToolHookDecision {+ self.1.before_tool_decision_in(dispatch, context).await+ }async fn after_tool_context(&self, context: &ToolHookContext) -> Option<String> {self.1.after_tool_context(context).await}