Skip to content

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

refactor(agent): parameterize hook scope with run context and turn cost

Steven Enamakeld7c00b47bb47
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle_outcome.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle_outcome.rs
index 8833831a0c..6c5f26356f 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_outcome.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_outcome.rs
@@ -10,9 +10,36 @@ pub(super) fn host_outcome_to_neutral(
definition: &crate::agent_registry::host_definition::AgentDefinition,
options: &SubagentRunOptions,
) -> SubagentOutcome {
+ let usage_cost = outcome.usage.cost();
+ let mut extensions = std::collections::BTreeMap::from_iter([
+ ("agent_id".into(), serde_json::json!(definition.id)),
+ (
+ "worker_thread_id".into(),
+ serde_json::json!(options.worker_thread_id),
+ ),
+ (
+ "skill_filter_override".into(),
+ serde_json::json!(options.skill_filter_override),
+ ),
+ (
+ "model_override".into(),
+ serde_json::json!(options.model_override),
+ ),
+ (
+ "elapsed_ms".into(),
+ serde_json::json!(outcome.elapsed.as_millis() as u64),
+ ),
+ (
+ "artifact_paths".into(),
+ serde_json::json!(outcome.artifact_paths),
+ ),
+ ]);
let status = match outcome.status {
SubagentRunStatus::Completed => SubagentOutcomeKind::Completed,
- SubagentRunStatus::AwaitingUser { question, .. } => {
+ SubagentRunStatus::AwaitingUser {
+ question, options, ..
+ } => {
+ extensions.insert("options".into(), serde_json::json!(options));
SubagentOutcomeKind::AwaitingInput(SubagentPause {
reason: question,
resume: SubagentResume {
@@ -47,6 +74,12 @@ pub(super) fn host_outcome_to_neutral(
};
SubagentOutcome {
task_id: outcome.task_id,
+ worker_thread_id: options.worker_thread_id.clone(),
+ tier: None,
+ model_override: options.model_override.clone(),
+ cost_usd: usage_cost.usd(),
+ cost_source: Some(usage_cost.source),
+ extensions: std::mem::take(&mut extensions),
output: outcome.output,
history: outcome
.final_history
diff --git a/crates/openhuman-core/src/agent/turn_env_tests.rs b/crates/openhuman-core/src/agent/turn_env_tests.rs
index 89dd58f928..6b5c7476d0 100644
--- a/crates/openhuman-core/src/agent/turn_env_tests.rs
+++ b/crates/openhuman-core/src/agent/turn_env_tests.rs
@@ -6,7 +6,7 @@ use std::time::Duration;
fn full_env() -> (HostTurnEnv, CancellationToken) {
let token = CancellationToken::new();
- let mut hooks = HookScope::default();
+ let mut hooks = tinyagents_hooks::scope::HookScope::<crate::agent::tinyagents::host::OpenHumanRunContext, tinyagents_harness::cost::TurnCost>::default();
hooks.push_stop(Arc::new(BudgetStopHook::new(2.0)));
let env = HostTurnEnv {
spawn_depth_limit: Some(1),
diff --git a/crates/openhuman-embed/src/agent/mod.rs b/crates/openhuman-embed/src/agent/mod.rs
index eb95b6e3d7..67c9bc9608 100644
--- a/crates/openhuman-embed/src/agent/mod.rs
+++ b/crates/openhuman-embed/src/agent/mod.rs
@@ -135,7 +135,7 @@ pub(crate) struct AgentInner {
/// The agent's own in-process tools, rebuilt per turn. See
/// [`AgentSpec::tools`](super::AgentSpec::tools) for why it is a factory.
pub(crate) host_tools: Option<openhuman_core::agent::HostTools>,
- pub(crate) hooks: openhuman_core::agent::hooks::HookScope,
+ pub(crate) hooks: tinyagents_hooks::scope::HookScope<openhuman_core::agent::tinyagents::host::OpenHumanRunContext, tinyagents_harness::cost::TurnCost>,
pub(crate) lifecycle: lifecycle::Lifecycle,
/// Built from [`ToolScopeSpec::HostOnly`]: every turn's session is built
/// from the host tools alone.
diff --git a/crates/openhuman-embed/src/agent/spec.rs b/crates/openhuman-embed/src/agent/spec.rs
index e7f96657d4..9bcf45b692 100644
--- a/crates/openhuman-embed/src/agent/spec.rs
+++ b/crates/openhuman-embed/src/agent/spec.rs
@@ -58,7 +58,7 @@ pub struct AgentSpec {
composio: Option<ComposioHostCredential>,
config_fn: Option<ConfigEdit>,
host_tools: Option<openhuman_core::agent::HostTools>,
- hooks: openhuman_core::agent::hooks::HookScope,
+ hooks: tinyagents_hooks::scope::HookScope<openhuman_core::agent::tinyagents::host::OpenHumanRunContext, tinyagents_harness::cost::TurnCost>,
memory: Option<MemoryBinding>,
subagents: Vec<(String, AgentDefinitionSpec)>,
}
@@ -500,7 +500,7 @@ pub(crate) struct AgentSpecParts {
pub(crate) composio: Option<ComposioHostCredential>,
pub(crate) config_fn: Option<ConfigEdit>,
pub(crate) host_tools: Option<openhuman_core::agent::HostTools>,
- pub(crate) hooks: openhuman_core::agent::hooks::HookScope,
+ pub(crate) hooks: tinyagents_hooks::scope::HookScope<openhuman_core::agent::tinyagents::host::OpenHumanRunContext, tinyagents_harness::cost::TurnCost>,
pub(crate) memory: Option<MemoryBinding>,
pub(crate) subagents: Vec<(String, AgentDefinitionSpec)>,
}
diff --git a/crates/openhuman-embed/src/turn.rs b/crates/openhuman-embed/src/turn.rs
index 28a36ea4e7..920db257e3 100644
--- a/crates/openhuman-embed/src/turn.rs
+++ b/crates/openhuman-embed/src/turn.rs
@@ -98,7 +98,7 @@ pub struct Turn {
control_deadline: Option<tokio::time::Instant>,
observer: Option<Arc<dyn crate::observe::TurnObserver>>,
trace_content: crate::observe::TraceContent,
- hooks: openhuman_core::agent::hooks::HookScope,
+ hooks: tinyagents_hooks::scope::HookScope<openhuman_core::agent::tinyagents::host::OpenHumanRunContext, tinyagents_harness::cost::TurnCost>,
tools: Option<openhuman_core::agent::HostTools>,
tool_env: Option<tinytools_std::timeout::CommandEnvironment>,
}
@@ -143,7 +143,7 @@ impl Turn {
self
}
- pub(crate) fn with_hooks(mut self, hooks: openhuman_core::agent::hooks::HookScope) -> Self {
+ pub(crate) fn with_hooks(mut self, hooks: tinyagents_hooks::scope::HookScope<openhuman_core::agent::tinyagents::host::OpenHumanRunContext, tinyagents_harness::cost::TurnCost>) -> Self {
self.hooks = hooks;
self
}