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(embed): use named lookup for post-turn hooks
Steven Enamakel957f71cdcfbb
diff --git a/crates/openhuman-embed/src/runtime/seams.rs b/crates/openhuman-embed/src/runtime/seams.rsindex ba1894a75d..580def01a9 100644--- a/crates/openhuman-embed/src/runtime/seams.rs+++ b/crates/openhuman-embed/src/runtime/seams.rs@@ -23,9 +23,10 @@use std::sync::Arc;use openhuman_core::agent::hooks::{- LearningSink, ToolHook, embedder_post_turn_hooks, embedder_tool_hooks,+ embedder_post_turn_hook_named, embedder_post_turn_hooks, embedder_tool_hooks,replace_embedder_post_turn_hook, replace_embedder_tool_hook,};+use crate::seams::{LearningSink, OpenHumanRunContext, ToolHook};use openhuman_core::agent::tinyagents::discovery::{clear_tool_ranker, install_tool_ranker, installed_tool_ranker,};@@ -156,11 +157,15 @@ impl HostSeams {let post_turn_hooks = self.post_turn_hooks.into_iter()- .map(|hook| {- let name = hook.name().to_string();- let previous = embedder_post_turn_hooks()- .into_iter()- .find(|existing| existing.name() == name);+ .enumerate()+ .map(|(index, hook)| {+ static NEXT_LEARNING_SINK: std::sync::atomic::AtomicU64 =+ std::sync::atomic::AtomicU64::new(0);+ let name = format!(+ "embedder.learning_sink.{:020}",+ NEXT_LEARNING_SINK.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + index as u64+ );+ let previous = embedder_post_turn_hook_named(&name);replace_embedder_post_turn_hook(&name, Some(Arc::clone(&hook)));log::debug!("[embed][seams] post-turn hook installed name={name} replaced={}",@@ -256,19 +261,13 @@ impl InstalledSeams {.rposition(|installed| installed.name == name){let installed = self.post_turn_hooks.remove(index);- let current = embedder_post_turn_hooks()- .into_iter()- .find(|hook| hook.name() == name);+ let current = embedder_post_turn_hook_named(name);if current.is_some_and(|current| Arc::ptr_eq(¤t, &installed.ours)) {replace_embedder_post_turn_hook(name, installed.previous);}}if let Some(hook) = hook {- let hook: Arc<dyn LearningSink> =- Arc::new(super::live_hooks::NamedPostTurnHook(name.to_owned(), hook));- let previous = embedder_post_turn_hooks()- .into_iter()- .find(|hook| hook.name() == name);+ let previous = embedder_post_turn_hook_named(name);replace_embedder_post_turn_hook(name, Some(hook.clone()));self.post_turn_hooks.push(InstalledHook {name: name.to_owned(),@@ -374,9 +373,7 @@ impl Drop for InstalledSeams {// over the original. And only while ours still holds the name, so a// hook installed after build is not clobbered.while let Some(hook) = self.post_turn_hooks.pop() {- let current = embedder_post_turn_hooks()- .into_iter()- .find(|existing| existing.name() == hook.name);+ let current = embedder_post_turn_hook_named(&hook.name);if current.is_some_and(|now| Arc::ptr_eq(&now, &hook.ours)) {replace_embedder_post_turn_hook(&hook.name, hook.previous);log::debug!("[embed][seams] post-turn hook restored name={}", hook.name);@@ -425,8 +422,8 @@ impl RuntimeBuilder {}/// A hook every agent session runs after each turn. Replaces a- /// registered hook of the same [`name`](LearningSink::name); removed (and- /// the replaced one restored) when the runtime drops.+ /// learning sink installed by this builder; removed (and a replaced sink+ /// restored) when the runtime drops.pub fn post_turn_hook(mut self, hook: Arc<dyn LearningSink>) -> Self {self.seams.post_turn_hooks.push(hook);self