Skip to content

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

refactor(agent): parameterize tool hooks by run context

Steven Enamakel418f9b640039
diff --git a/crates/openhuman-core/src/agent/host_overrides.rs b/crates/openhuman-core/src/agent/host_overrides.rs
index 2c09b43bf3..d7940fdedc 100644
--- a/crates/openhuman-core/src/agent/host_overrides.rs
+++ b/crates/openhuman-core/src/agent/host_overrides.rs
@@ -8,6 +8,7 @@ use std::collections::BTreeMap;
use std::sync::{Arc, RwLock};
use crate::agent::hooks::{PostTurnHook, ToolHook};
+use crate::agent::tinyagents::host::OpenHumanRunContext;
use tinyinference_llm::model::ChatModel;
/// Runtime or agent host adapters, shared by every context derived from it.
@@ -20,7 +21,7 @@ pub struct HostOverrides {
/// Approval registration barrier owned by this agent instance.
pub approval_scope: Option<Arc<crate::security::approval::ApprovalScope>>,
post_turn_hooks: RwLock<BTreeMap<String, Arc<dyn PostTurnHook>>>,
- tool_hooks: RwLock<BTreeMap<String, Arc<dyn ToolHook>>>,
+ tool_hooks: RwLock<BTreeMap<String, Arc<dyn ToolHook<OpenHumanRunContext>>>>,
/// Native inference used by this agent instead of config-routed inference.
pub model: Option<Arc<dyn ChatModel<()>>>,
/// Role-specific native models; absent roles use `model` or config routing.
@@ -84,7 +85,7 @@ impl HostOverrides {
}
/// Add or replace an agent-local tool hook by name; `None` removes it.
- pub fn tool_hook(&self, name: &str, hook: Option<Arc<dyn ToolHook>>) {
+ pub fn tool_hook(&self, name: &str, hook: Option<Arc<dyn ToolHook<OpenHumanRunContext>>>) {
let mut hooks = self
.tool_hooks
.write()
@@ -113,7 +114,7 @@ impl HostOverrides {
}
/// Snapshot the agent-local tool hooks for a new turn.
- pub fn tool_hooks(&self) -> Vec<Arc<dyn ToolHook>> {
+ pub fn tool_hooks(&self) -> Vec<Arc<dyn ToolHook<OpenHumanRunContext>>> {
let mut hooks = self
.parent
.as_ref()
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 b6fb57f138..c53b73b394 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -291,7 +291,7 @@ pub struct OpenHumanRunContext {
/// Stop policies evaluated after each model call.
pub stop_hooks: Vec<Arc<dyn StopHook<tinyagents_harness::cost::TurnCost>>>,
/// Agent/turn tool callbacks, registered after the runtime's global ones.
- pub tool_hooks: Vec<Arc<dyn crate::agent::hooks::ToolHook>>,
+ pub tool_hooks: Vec<Arc<dyn crate::agent::hooks::ToolHook<OpenHumanRunContext>>>,
/// Host cap on real tool invocations for this turn tree; `None` leaves the
/// product default. Inherited by children.
pub tool_call_limit: Option<usize>,