Skip to content

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

refactor(seams): rename PostTurnHook to LearningSink and parameterize ToolHook

Steven Enamakel629cd2bceffa
diff --git a/crates/openhuman-embed/examples/hooks.rs b/crates/openhuman-embed/examples/hooks.rs
index 3606fd8c3f..d73d7020c4 100644
--- a/crates/openhuman-embed/examples/hooks.rs
+++ b/crates/openhuman-embed/examples/hooks.rs
@@ -41,7 +41,7 @@ async fn run() -> anyhow::Result<()> {
struct Counter(std::sync::Arc<std::sync::atomic::AtomicUsize>);
#[async_trait::async_trait]
-impl openhuman_embed::seams::PostTurnHook for Counter {
+impl openhuman_embed::seams::LearningSink for Counter {
fn name(&self) -> &str {
"example-counter"
}
diff --git a/crates/openhuman-embed/examples/runtime_events.rs b/crates/openhuman-embed/examples/runtime_events.rs
index 7bfc21afc1..317346e5c7 100644
--- a/crates/openhuman-embed/examples/runtime_events.rs
+++ b/crates/openhuman-embed/examples/runtime_events.rs
@@ -72,7 +72,7 @@ async fn run() -> anyhow::Result<()> {
}
struct Counter(Arc<AtomicUsize>);
#[async_trait::async_trait]
-impl openhuman_embed::seams::PostTurnHook for Counter {
+impl openhuman_embed::seams::LearningSink for Counter {
fn name(&self) -> &str {
"live-counter"
}
diff --git a/crates/openhuman-embed/src/agent/mod.rs b/crates/openhuman-embed/src/agent/mod.rs
index 67c9bc9608..17d6b34bce 100644
--- a/crates/openhuman-embed/src/agent/mod.rs
+++ b/crates/openhuman-embed/src/agent/mod.rs
@@ -305,12 +305,12 @@ impl Agent {
}
/// Add, replace, or remove an agent-local post-turn hook by name.
- pub fn post_turn_hook(&self, name: &str, hook: Option<Arc<dyn crate::seams::PostTurnHook>>) {
+ pub fn post_turn_hook(&self, name: &str, hook: Option<Arc<dyn crate::seams::LearningSink>>) {
self.inner.overrides.post_turn_hook(name, hook);
}
/// Add, replace, or remove an agent-local tool hook by name.
- pub fn tool_hook(&self, name: &str, hook: Option<Arc<dyn crate::seams::ToolHook>>) {
+ pub fn tool_hook(&self, name: &str, hook: Option<Arc<dyn crate::seams::ToolHook<crate::seams::OpenHumanRunContext>>>) {
self.inner.overrides.tool_hook(name, hook);
}
diff --git a/crates/openhuman-embed/src/agent/spec.rs b/crates/openhuman-embed/src/agent/spec.rs
index 9bcf45b692..bc24323ce7 100644
--- a/crates/openhuman-embed/src/agent/spec.rs
+++ b/crates/openhuman-embed/src/agent/spec.rs
@@ -34,8 +34,8 @@ pub(crate) enum SkillsDest {
/// Description of an agent to instantiate on a [`Runtime`](crate::Runtime).
pub struct AgentSpec {
id: String,
- post_turn_hooks: Vec<std::sync::Arc<dyn crate::seams::PostTurnHook>>,
- tool_hooks: Vec<std::sync::Arc<dyn crate::seams::ToolHook>>,
+ post_turn_hooks: Vec<std::sync::Arc<dyn crate::seams::LearningSink>>,
+ tool_hooks: Vec<std::sync::Arc<dyn crate::seams::ToolHook<crate::seams::OpenHumanRunContext>>>,
session_store: Option<std::sync::Arc<dyn crate::SessionStoreProvider>>,
approval_handler: Option<std::sync::Arc<dyn crate::ApprovalHandler>>,
definition: AgentDefinitionSpec,
@@ -147,13 +147,13 @@ impl AgentSpec {
}
/// Register a post-turn hook local to this agent, in addition to runtime hooks.
- pub fn post_turn_hook(mut self, hook: std::sync::Arc<dyn crate::seams::PostTurnHook>) -> Self {
+ pub fn post_turn_hook(mut self, hook: std::sync::Arc<dyn crate::seams::LearningSink>) -> Self {
self.post_turn_hooks.push(hook);
self
}
/// Register a tool hook local to this agent, in addition to runtime hooks.
- pub fn tool_hook(mut self, hook: std::sync::Arc<dyn crate::seams::ToolHook>) -> Self {
+ pub fn tool_hook(mut self, hook: std::sync::Arc<dyn crate::seams::ToolHook<crate::seams::OpenHumanRunContext>>) -> Self {
self.tool_hooks.push(hook);
self
}
@@ -476,8 +476,8 @@ impl AgentSpec {
/// The spec's fields, destructured for [`super::build::instantiate`].
pub(crate) struct AgentSpecParts {
pub(crate) id: String,
- pub(crate) post_turn_hooks: Vec<std::sync::Arc<dyn crate::seams::PostTurnHook>>,
- pub(crate) tool_hooks: Vec<std::sync::Arc<dyn crate::seams::ToolHook>>,
+ pub(crate) post_turn_hooks: Vec<std::sync::Arc<dyn crate::seams::LearningSink>>,
+ pub(crate) tool_hooks: Vec<std::sync::Arc<dyn crate::seams::ToolHook<crate::seams::OpenHumanRunContext>>>,
pub(crate) session_store: Option<std::sync::Arc<dyn crate::SessionStoreProvider>>,
pub(crate) approval_handler: Option<std::sync::Arc<dyn crate::ApprovalHandler>>,
pub(crate) definition: AgentDefinitionSpec,
diff --git a/crates/openhuman-embed/src/profiles/host.rs b/crates/openhuman-embed/src/profiles/host.rs
index 32c8d87d21..fe45e1debc 100644
--- a/crates/openhuman-embed/src/profiles/host.rs
+++ b/crates/openhuman-embed/src/profiles/host.rs
@@ -12,7 +12,7 @@ use std::sync::Arc;
pub(super) struct ProfileHostOptions {
tools: Option<HostTools>,
scope: Option<ToolScopeSpec>,
- permission: Option<Arc<dyn ToolHook>>,
+ permission: Option<Arc<dyn ToolHook<OpenHumanRunContext>>>,
channels: HashMap<String, PermissionLevel>,
memory: Option<Arc<dyn tinymemory_api::MemoryEngine>>,
system_prompt: Option<String>,
diff --git a/crates/openhuman-embed/src/runtime/live_hooks.rs b/crates/openhuman-embed/src/runtime/live_hooks.rs
index 70b0e23e9b..6fdade6d7a 100644
--- a/crates/openhuman-embed/src/runtime/live_hooks.rs
+++ b/crates/openhuman-embed/src/runtime/live_hooks.rs
@@ -1,11 +1,11 @@
//! Tracked runtime hooks, composed with agent-local hooks.
use super::Runtime;
-use crate::seams::{PostTurnHook, ToolHook, ToolHookContext, ToolHookDecision, TurnContext};
+use crate::seams::{LearningSink, ToolHook, ToolHookContext, ToolHookDecision, TurnContext};
use std::sync::Arc;
-pub(super) struct NamedPostTurnHook(pub String, pub Arc<dyn PostTurnHook>);
+pub(super) struct NamedPostTurnHook(pub String, pub Arc<dyn LearningSink>);
#[async_trait::async_trait]
-impl PostTurnHook for NamedPostTurnHook {
+impl LearningSink for NamedPostTurnHook {
fn name(&self) -> &str {
&self.0
}
@@ -13,9 +13,9 @@ impl PostTurnHook for NamedPostTurnHook {
self.1.on_turn_complete(context).await
}
}
-pub(super) struct NamedToolHook(pub String, pub Arc<dyn ToolHook>);
+pub(super) struct NamedToolHook(pub String, pub Arc<dyn ToolHook<OpenHumanRunContext>>);
#[async_trait::async_trait]
-impl ToolHook for NamedToolHook {
+impl ToolHook<OpenHumanRunContext> for NamedToolHook {
fn name(&self) -> &str {
&self.0
}
@@ -43,7 +43,7 @@ impl Runtime {
/// Add, replace, or remove a runtime-wide post-turn hook by name.
/// This also replaces hooks installed by the builder. Changes apply to
/// subsequently assembled turns; removal restores any predecessor hook.
- pub fn post_turn_hook(&self, name: &str, hook: Option<Arc<dyn crate::seams::PostTurnHook>>) {
+ pub fn post_turn_hook(&self, name: &str, hook: Option<Arc<dyn crate::seams::LearningSink>>) {
let context = self.core_runtime().context().clone();
openhuman_core::core::runtime::CoreContext::sync_scope(context.clone(), || {
let mut seams = self
@@ -61,7 +61,7 @@ impl Runtime {
/// Add, replace, or remove a runtime-wide tool hook by name.
/// This also replaces hooks installed by the builder. Changes apply to
/// subsequently assembled turns; removal restores any predecessor hook.
- pub fn tool_hook(&self, name: &str, hook: Option<Arc<dyn crate::seams::ToolHook>>) {
+ pub fn tool_hook(&self, name: &str, hook: Option<Arc<dyn crate::seams::ToolHook<crate::seams::OpenHumanRunContext>>>) {
let context = self.core_runtime().context().clone();
openhuman_core::core::runtime::CoreContext::sync_scope(context.clone(), || {
let mut seams = self
diff --git a/crates/openhuman-embed/src/runtime/seams.rs b/crates/openhuman-embed/src/runtime/seams.rs
index 1eee9072b6..ba1894a75d 100644
--- a/crates/openhuman-embed/src/runtime/seams.rs
+++ b/crates/openhuman-embed/src/runtime/seams.rs
@@ -23,7 +23,7 @@
use std::sync::Arc;
use openhuman_core::agent::hooks::{
- PostTurnHook, ToolHook, embedder_post_turn_hooks, embedder_tool_hooks,
+ LearningSink, ToolHook, embedder_post_turn_hooks, embedder_tool_hooks,
replace_embedder_post_turn_hook, replace_embedder_tool_hook,
};
use openhuman_core::agent::tinyagents::discovery::{
@@ -81,8 +81,8 @@ impl From<Arc<dyn StorageBackend>> for StorageSource {
pub(crate) struct HostSeams {
pub(crate) controller_extensions: Vec<ControllerExtension>,
pub(crate) tool_ranker: Option<Arc<dyn ToolRanker>>,
- pub(crate) post_turn_hooks: Vec<Arc<dyn PostTurnHook>>,
- pub(crate) tool_hooks: Vec<Arc<dyn ToolHook>>,
+ pub(crate) post_turn_hooks: Vec<Arc<dyn LearningSink>>,
+ pub(crate) tool_hooks: Vec<Arc<dyn ToolHook<OpenHumanRunContext>>>,
pub(crate) server_launcher: Option<ServerLauncher>,
pub(crate) live_policy: Option<Arc<SecurityPolicy>>,
pub(crate) storage: Option<StorageSource>,
@@ -241,15 +241,15 @@ pub(crate) struct InstalledSeams {
storage: Option<InstalledStorage>,
ranker: Option<InstalledRanker>,
/// Our hooks, in install order, each with the same-named hook it replaced.
- post_turn_hooks: Vec<InstalledHook<dyn PostTurnHook>>,
- tool_hooks: Vec<InstalledHook<dyn ToolHook>>,
+ post_turn_hooks: Vec<InstalledHook<dyn LearningSink>>,
+ tool_hooks: Vec<InstalledHook<dyn ToolHook<OpenHumanRunContext>>>,
/// Installed only once the core has booted.
live_policy: Option<Arc<SecurityPolicy>>,
restore: bool,
}
impl InstalledSeams {
- pub(crate) fn post_turn_hook(&mut self, name: &str, hook: Option<Arc<dyn PostTurnHook>>) {
+ pub(crate) fn post_turn_hook(&mut self, name: &str, hook: Option<Arc<dyn LearningSink>>) {
while let Some(index) = self
.post_turn_hooks
.iter()
@@ -264,7 +264,7 @@ impl InstalledSeams {
}
}
if let Some(hook) = hook {
- let hook: Arc<dyn PostTurnHook> =
+ let hook: Arc<dyn LearningSink> =
Arc::new(super::live_hooks::NamedPostTurnHook(name.to_owned(), hook));
let previous = embedder_post_turn_hooks()
.into_iter()
@@ -277,7 +277,7 @@ impl InstalledSeams {
});
}
}
- pub(crate) fn tool_hook(&mut self, name: &str, hook: Option<Arc<dyn ToolHook>>) {
+ pub(crate) fn tool_hook(&mut self, name: &str, hook: Option<Arc<dyn ToolHook<OpenHumanRunContext>>>) {
while let Some(index) = self
.tool_hooks
.iter()
@@ -292,7 +292,7 @@ impl InstalledSeams {
}
}
if let Some(hook) = hook {
- let hook: Arc<dyn ToolHook> =
+ let hook: Arc<dyn ToolHook<OpenHumanRunContext>> =
Arc::new(super::live_hooks::NamedToolHook(name.to_owned(), hook));
let previous = embedder_tool_hooks()
.into_iter()
@@ -425,16 +425,16 @@ impl RuntimeBuilder {
}
/// A hook every agent session runs after each turn. Replaces a
- /// registered hook of the same [`name`](PostTurnHook::name); removed (and
+ /// registered hook of the same [`name`](LearningSink::name); removed (and
/// the replaced one restored) when the runtime drops.
- pub fn post_turn_hook(mut self, hook: Arc<dyn PostTurnHook>) -> Self {
+ pub fn post_turn_hook(mut self, hook: Arc<dyn LearningSink>) -> Self {
self.seams.post_turn_hooks.push(hook);
self
}
/// A hook every agent session runs around each tool call. Same
/// replacement and restore rules as [`post_turn_hook`](Self::post_turn_hook).
- pub fn tool_hook(mut self, hook: Arc<dyn ToolHook>) -> Self {
+ pub fn tool_hook(mut self, hook: Arc<dyn ToolHook<OpenHumanRunContext>>) -> Self {
self.seams.tool_hooks.push(hook);
self
}
diff --git a/crates/openhuman-embed/src/runtime/seams_tests.rs b/crates/openhuman-embed/src/runtime/seams_tests.rs
index 7558f3b742..60c26e7d71 100644
--- a/crates/openhuman-embed/src/runtime/seams_tests.rs
+++ b/crates/openhuman-embed/src/runtime/seams_tests.rs
@@ -28,7 +28,7 @@ impl ToolRanker for NamedRanker {
struct NamedPostTurn(&'static str);
#[async_trait::async_trait]
-impl PostTurnHook for NamedPostTurn {
+impl LearningSink for NamedPostTurn {
fn name(&self) -> &str {
self.0
}
@@ -42,7 +42,7 @@ struct NamedToolHook(&'static str);
#[test]
fn live_replacement_and_removal_update_builder_hooks_and_restore_predecessors() {
let name = "seams-live-builder-hook";
- let original: Arc<dyn PostTurnHook> = Arc::new(NamedPostTurn(name));
+ let original: Arc<dyn LearningSink> = Arc::new(NamedPostTurn(name));
replace_embedder_post_turn_hook(name, Some(original.clone()));
let mut seams = HostSeams {
post_turn_hooks: vec![Arc::new(NamedPostTurn(name))],
@@ -91,7 +91,7 @@ fn live_replacement_and_removal_update_builder_hooks_and_restore_predecessors()
}
#[async_trait::async_trait]
-impl ToolHook for NamedToolHook {
+impl ToolHook<OpenHumanRunContext> for NamedToolHook {
fn name(&self) -> &str {
self.0
}
@@ -214,7 +214,7 @@ fn post_turn_hooks_are_removed_and_a_replaced_one_restored() {
#[test]
fn same_named_hooks_unwind_newest_first() {
- let original: Arc<dyn PostTurnHook> = Arc::new(NamedPostTurn("seams-dup-hook"));
+ let original: Arc<dyn LearningSink> = Arc::new(NamedPostTurn("seams-dup-hook"));
replace_embedder_post_turn_hook("seams-dup-hook", Some(Arc::clone(&original)));
let seams = HostSeams {
post_turn_hooks: vec![
@@ -247,7 +247,7 @@ fn a_hook_replaced_after_build_is_left_alone() {
}
.install()
.expect("install");
- let later: Arc<dyn ToolHook> = Arc::new(NamedToolHook("seams-late-hook"));
+ let later: Arc<dyn ToolHook<OpenHumanRunContext>> = Arc::new(NamedToolHook("seams-late-hook"));
replace_embedder_tool_hook("seams-late-hook", Some(Arc::clone(&later)));
drop(seams);
diff --git a/crates/openhuman-embed/src/turn.rs b/crates/openhuman-embed/src/turn.rs
index 920db257e3..9eef15bef8 100644
--- a/crates/openhuman-embed/src/turn.rs
+++ b/crates/openhuman-embed/src/turn.rs
@@ -150,7 +150,7 @@ impl Turn {
/// Add a tool callback for this turn only, after runtime and agent hooks.
/// Does not change the agent or any other concurrent turn.
- pub fn tool_hook(mut self, hook: Arc<dyn crate::seams::ToolHook>) -> Self {
+ pub fn tool_hook(mut self, hook: Arc<dyn crate::seams::ToolHook<crate::seams::OpenHumanRunContext>>) -> Self {
self.hooks.push_tool(hook);
self
}
@@ -210,7 +210,7 @@ impl Turn {
/// Add a completed-turn callback for this turn only. The callback runs
/// asynchronously with an owned snapshot after the turn completes.
- pub fn post_turn_hook(mut self, hook: Arc<dyn crate::seams::PostTurnHook>) -> Self {
+ pub fn post_turn_hook(mut self, hook: Arc<dyn crate::seams::LearningSink>) -> Self {
self.hooks.push_learning(hook);
self
}
diff --git a/crates/openhuman-embed/tests/runtime_observation.rs b/crates/openhuman-embed/tests/runtime_observation.rs
index 7e50adcc3d..a95f60aae2 100644
--- a/crates/openhuman-embed/tests/runtime_observation.rs
+++ b/crates/openhuman-embed/tests/runtime_observation.rs
@@ -2,7 +2,7 @@
mod common;
use async_trait::async_trait;
use openhuman_embed::providers::{ChatModel, ModelRequest, ModelResponse};
-use openhuman_embed::seams::{PostTurnHook, TurnContext};
+use openhuman_embed::seams::{LearningSink, TurnContext};
use openhuman_embed::{
Access, AgentDefinitionSpec, AgentSpec, InMemorySessionStores, ModelDefaults, Provider,
Runtime, RuntimeEventKind, SessionStoreProvider, StreamEvent,
@@ -29,7 +29,7 @@ struct Hook {
seen: tokio::sync::mpsc::UnboundedSender<String>,
}
#[async_trait]
-impl PostTurnHook for Hook {
+impl LearningSink for Hook {
fn name(&self) -> &str {
self.name
}
diff --git a/crates/openhuman-embed/tests/scoped_hooks.rs b/crates/openhuman-embed/tests/scoped_hooks.rs
index 88b1c28d43..084ff38205 100644
--- a/crates/openhuman-embed/tests/scoped_hooks.rs
+++ b/crates/openhuman-embed/tests/scoped_hooks.rs
@@ -9,7 +9,7 @@ use common::{
chat_completion, eventually, offline_config, route, runtime, scripted_provider, stub_backend,
tool_call_completion,
};
-use openhuman_embed::seams::{PostTurnHook, ToolHook, ToolHookContext, TurnContext};
+use openhuman_embed::seams::{LearningSink, ToolHook, ToolHookContext, TurnContext};
use openhuman_embed::{
AgentDefinitionSpec, AgentSpec, HostTurnTools, Runtime, Tool, ToolScopeSpec, Workspace,
};
@@ -44,7 +44,7 @@ impl Observer {
}
#[async_trait::async_trait]
-impl ToolHook for Observer {
+impl ToolHook<OpenHumanRunContext> for Observer {
fn name(&self) -> &str {
"same-policy-name"
}
@@ -65,7 +65,7 @@ impl ToolHook for Observer {
}
#[async_trait::async_trait]
-impl PostTurnHook for Observer {
+impl LearningSink for Observer {
fn name(&self) -> &str {
"same-policy-name"
}
diff --git a/crates/openhuman-embed/tests/seams_runtime.rs b/crates/openhuman-embed/tests/seams_runtime.rs
index 9583519e74..789e7d89cc 100644
--- a/crates/openhuman-embed/tests/seams_runtime.rs
+++ b/crates/openhuman-embed/tests/seams_runtime.rs
@@ -13,7 +13,7 @@ use std::sync::Arc;
use common::{offline_config, runtime, stub_backend};
use openhuman_core::core::all::{ControllerFuture, RegisteredController};
use openhuman_core::core::ControllerSchema;
-use openhuman_embed::seams::{ControllerExtension, DomainGroup, PostTurnHook, SecurityPolicy};
+use openhuman_embed::seams::{ControllerExtension, DomainGroup, LearningSink, SecurityPolicy};
use openhuman_embed::{schema_for_rpc_method, Runtime, Workspace};
use serde_json::{json, Map, Value};
@@ -44,7 +44,7 @@ fn extension() -> ControllerExtension {
struct ProbeHook;
#[async_trait::async_trait]
-impl PostTurnHook for ProbeHook {
+impl LearningSink for ProbeHook {
fn name(&self) -> &str {
"embed-seam-runtime-hook"
}
diff --git a/crates/openhuman-embed/tests/tool_hook_context.rs b/crates/openhuman-embed/tests/tool_hook_context.rs
index 4b1ea6af21..30fdcabc01 100644
--- a/crates/openhuman-embed/tests/tool_hook_context.rs
+++ b/crates/openhuman-embed/tests/tool_hook_context.rs
@@ -13,7 +13,7 @@ use std::sync::{Arc, Mutex};
struct Capture(Arc<Mutex<Vec<Value>>>);
#[async_trait::async_trait]
-impl ToolHook for Capture {
+impl ToolHook<OpenHumanRunContext> for Capture {
fn name(&self) -> &str {
"context-probe"
}
diff --git a/crates/openhuman-tinyhumans/src/runtime.rs b/crates/openhuman-tinyhumans/src/runtime.rs
index 03b8aaabe5..10584c01df 100644
--- a/crates/openhuman-tinyhumans/src/runtime.rs
+++ b/crates/openhuman-tinyhumans/src/runtime.rs
@@ -25,7 +25,7 @@ use std::path::PathBuf;
use std::sync::Arc;
use openhuman_embed::seams::{
- ControllerExtension, PostTurnHook, SecurityPolicy, ServerLauncher, ToolHook,
+ ControllerExtension, LearningSink, SecurityPolicy, ServerLauncher, ToolHook,
};
use tinytools::ToolRanker;
@@ -197,7 +197,7 @@ impl RuntimeBuilder {
);
forward!(
/// See [`openhuman_embed::RuntimeBuilder::post_turn_hook`].
- post_turn_hook(hook: Arc<dyn PostTurnHook>)
+ post_turn_hook(hook: Arc<dyn LearningSink>)
);
forward!(
/// See [`openhuman_embed::RuntimeBuilder::tool_hook`].