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
fix(agent): preserve typed run context inheritance
Steven Enamakelcdb24208f24f
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rsindex d166d67404..d0a1ce4c24 100644--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs@@ -159,8 +159,7 @@ pub(super) fn assemble_turn_harness("[cache] response cache attached (deterministic internal run)");}- let mut capability_registry: CapabilityRegistry<OpenHumanRunContext> =- CapabilityRegistry::new();+ let mut capability_registry: CapabilityRegistry<()> = CapabilityRegistry::new();let cursor: IterationCursor = Arc::default();// Shared `call_id → tool_name` map: the forwarder records the name ondiff --git a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs b/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rsindex ad3d55f254..76765da299 100644--- a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs+++ b/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs@@ -31,7 +31,7 @@ use crate::agent::tinyagents::turn_policy::is_subagent_spawn_or_delegate_tool;#[allow(clippy::too_many_arguments)]pub(super) fn register_turn_tools_and_agents(harness: &mut AgentHarness<(), OpenHumanRunContext>,- capability_registry: &mut CapabilityRegistry<OpenHumanRunContext>,+ capability_registry: &mut CapabilityRegistry<()>,tool_sets: &[Arc<Vec<Box<dyn tinytools::Tool>>>],allowed: &Option<HashSet<String>>,early_exit_set: &HashSet<&str>,@@ -172,7 +172,7 @@ pub(super) fn register_turn_tools_and_agents(// into that stream. The harness is deliberately NOT switched over to these// projections yet — that glue swap is explicitly deferred.let projected_models = capability_registry.to_model_registry();- let projected_tools = capability_registry.to_tool_registry::<()>();+ let projected_tools = capability_registry.to_tool_registry::<OpenHumanRunContext>();tracing::debug!(models = projected_models.names().len(),tools = projected_tools.names().len(),diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rsindex dff5fbe783..7b616c2831 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs@@ -88,6 +88,7 @@ impl OpenHumanRunContext {let mut context = Self::new();context.origin = crate::agent::turn_origin::current();context.progress = crate::agent::progress_sink::current_progress_sink();+ context.stop_hooks = crate::agent::stop_hooks::current_stop_hooks();context.dispatch = crate::agent::harness::turn_dispatch_guard::current();context.thread_id = crate::agent::tinyagents::thread_context::current_thread_id();if let Some(slot) = crate::agent::tinyagents::current_route_slot() {diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rsindex 63505c5345..ba6f891b20 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs@@ -48,6 +48,21 @@ fn child_inherits_tree_handles_but_isolates_observations_and_usage() {assert!(child.cancellation.is_cancelled());}+#[tokio::test]+async fn snapshots_scoped_stop_hooks_into_the_explicit_carrier() {+ let hooks: Vec<std::sync::Arc<dyn crate::agent::stop_hooks::StopHook>> =+ vec![std::sync::Arc::new(+ crate::agent::stop_hooks::MaxIterationsStopHook::new(3),+ )];++ crate::agent::stop_hooks::with_stop_hooks(hooks, async {+ let captured = OpenHumanRunContext::from_current_scopes();+ assert_eq!(captured.stop_hooks.len(), 1);+ assert_eq!(captured.stop_hooks[0].name(), "max_iterations");+ })+ .await;+}+#[tokio::test]async fn snapshots_live_root_scopes_before_child_dispatch() {let root = tempfile::tempdir().expect("workspace");diff --git a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rsindex 801bbddf29..0493153634 100644--- a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs+++ b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs@@ -57,9 +57,9 @@ use async_trait::async_trait;use sha2::{Digest, Sha256};use std::collections::{HashMap, HashSet, VecDeque};use std::sync::{Arc, LazyLock, Mutex};-use tinyagents_harness::context::RunContext;+use tinyagents_harness::context::{RunConfig, RunContext};use tinyagents_harness::runtime::{AgentHarness, InvalidArgsPolicy, RunPolicy, UnknownToolPolicy};-use tinyagents_harness::subagent::SubAgent;+use tinyinference_llm::message::Message;use tracing::{debug, info, warn};use crate::agent::harness::definition::{AgentDefinition, PromptSource};@@ -323,7 +323,7 @@ impl PayloadSummarizer for SubagentPayloadSummarizer {// Checked before the breaker: a summary we already have costs nothing,// so a broken summarizer is no reason to withhold it.let cache_key = summary_cache_key(- parent_ctx.thread_id().map(str::to_owned).as_deref(),+ parent_ctx.thread_id().map(|thread| thread.as_str()),tool_name,parent_task_hint,raw,@@ -368,6 +368,23 @@ impl PayloadSummarizer for SubagentPayloadSummarizer {}}+/// Create the internal summarizer's child context without rebuilding any of+/// the parent's live capabilities. This deliberately pairs TinyAgents'+/// canonical `RunContext::child` with OpenHuman's host-state `child` rule.+fn unary_child_context(+ parent_ctx: &RunContext<OpenHumanRunContext>,+ agent_id: &str,+ max_iterations: usize,+ max_output_tokens: u32,+) -> tinyagents_harness::Result<RunContext<OpenHumanRunContext>> {+ let child_config = RunConfig::new(format!("{agent_id}-summary"))+ .with_max_model_calls(max_iterations)+ .with_max_tool_calls(max_iterations.saturating_mul(8).max(8))+ .with_max_depth(parent_ctx.config.max_depth())+ .with_max_turn_output_tokens(max_output_tokens);+ parent_ctx.child(child_config, parent_ctx.data.child())+}+impl SubagentPayloadSummarizer {async fn invoke_tinyagents_summarizer_in_parent(&self,@@ -411,13 +428,7 @@ impl SubagentPayloadSummarizer {.register_model(&model, Arc::new(provider_model)).set_default_model(&model);- let child = SubAgent::new(- self.definition.id.clone(),- self.definition.when_to_use.clone(),- Arc::new(harness),- )- .with_system_prompt(system_prompt);- // Run the summarizer UNARY (non-streaming), not via `invoke_in_parent`.+ // Run the summarizer UNARY (non-streaming), not via `SubAgent::invoke_in_parent`.//// `invoke_in_parent` inherits `parent.streaming`, which is `true` for a// chat turn, so the child runs the streaming loop and its per-token@@ -430,25 +441,23 @@ impl SubagentPayloadSummarizer {// summarizer: it exists to compress a payload for the ORCHESTRATOR'S// CONTEXT, and its only consumer here is `run.text()` below.//- // `invoke_with_events` runs the child through the unary path- // (`run_child(.., streaming = false)`), which per its own contract- // "leav[es] the parent's event stream unchanged", while still sharing- // the sink so the sub-agent lifecycle events (started/completed) keep- // reaching observers. Mirrors `silent_completion`, which is- // likewise deliberately silent about an internal repair call.- //- // Two bits of config that `invoke_in_parent` threaded are dropped by- // this entry point and neither matters here: the child `thread_id` (only- // used to attribute events we no longer stream) and the inherited- // `max_turn_output_tokens` (already enforced independently by the- // `MaxTokensModel` wrapper above).- let run = child- .invoke_with_events(+ // `RunContext::child` is the canonical inheritance operation: it keeps+ // the parent cancellation, workspace, stores, events, steering, thread,+ // and run lineage, while `OpenHumanRunContext::child` isolates the host+ // route and usage observations. Calling `invoke_in_context` then pins+ // this internal turn to TinyAgents' unary path, so summary text cannot+ // become a user-visible streaming delta.+ let child_context = unary_child_context(+ parent_ctx,+ &self.definition.id,+ self.definition.max_iterations,+ max_output_tokens,+ )?;+ let run = harness+ .invoke_in_context(&(),- parent_ctx.data.child(),- parent_ctx.depth(),- prompt,- &parent_ctx.events,+ child_context,+ vec![Message::system(system_prompt), Message::user(prompt)],).await?;Ok(run.text().unwrap_or_default())diff --git a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer_tests.rs b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer_tests.rsindex 4b302526e3..a4a83115c8 100644--- a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer_tests.rs@@ -2,6 +2,11 @@ use super::*;use crate::agent::harness::definition::{AgentDefinition, DefinitionSource, ModelSpec, PromptSource, SandboxMode, ToolScope,};+use async_trait::async_trait;+use std::sync::atomic::{AtomicBool, Ordering};+use std::sync::Arc;+use tinyinference_llm::message::Message;+use tinyinference_llm::model::{ChatModel, ModelRequest, ModelResponse, ModelStream};fn dummy_definition() -> AgentDefinition {AgentDefinition {@@ -50,6 +55,70 @@ fn dummy_parent_ctx() -> RunContext<crate::agent::tinyagents::host::OpenHumanRun)}+#[test]+fn unary_summarizer_child_inherits_cancellation_workspace_and_lineage() {+ let cancellation = tinyagents_harness::cancel::CancellationToken::new();+ let workspace = tinytools::WorkspaceDescriptor::new("/work/action");+ let parent = crate::agent::tinyagents::host::OpenHumanRunContext::new()+ .with_cancellation(cancellation.clone())+ .with_workspace(workspace.clone())+ .into_tinyagents(+ tinyagents_harness::context::RunConfig::new("parent").with_thread("thread-a"),+ );++ let child = unary_child_context(&parent, "summarizer", 1, 128).expect("child context");++ assert_eq!(child.workspace, Some(workspace));+ assert_eq!(child.thread_id().map(|id| id.as_str()), Some("thread-a"));+ assert_eq!(child.depth(), 1);+ assert_eq!(child.data.spawn_depth, 1);+ cancellation.cancel();+ assert!(child.cancellation.is_cancelled());+}++struct UnaryOnlyModel(AtomicBool);++#[async_trait]+impl ChatModel<()> for UnaryOnlyModel {+ async fn invoke(+ &self,+ _state: &(),+ _request: ModelRequest,+ ) -> tinyinference_llm::Result<ModelResponse> {+ self.0.store(true, Ordering::SeqCst);+ Ok(ModelResponse::assistant("condensed summary"))+ }++ async fn stream(+ &self,+ _state: &(),+ _request: ModelRequest,+ ) -> tinyinference_llm::Result<ModelStream> {+ panic!("a payload summary must not stream into the user-visible parent turn")+ }+}++#[tokio::test]+async fn unary_summarizer_child_keeps_summary_output_off_the_streaming_path() {+ let parent = crate::agent::tinyagents::host::OpenHumanRunContext::new()+ .into_tinyagents(tinyagents_harness::context::RunConfig::new("parent"));+ let child = unary_child_context(&parent, "summarizer", 1, 128).expect("child context");+ let model = Arc::new(UnaryOnlyModel(AtomicBool::new(false)));+ let mut harness: AgentHarness<(), crate::agent::tinyagents::host::OpenHumanRunContext> =+ AgentHarness::new();+ harness+ .register_model("summary", model.clone())+ .set_default_model("summary");++ let run = harness+ .invoke_in_context(&(), child, vec![Message::user("summarize this")])+ .await+ .expect("unary summary run");++ assert!(model.0.load(Ordering::SeqCst));+ assert_eq!(run.text().as_deref(), Some("condensed summary"));+}+#[tokio::test]async fn below_threshold_is_not_needed_not_unavailable() {let summarizer =diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs b/crates/openhuman-core/src/agent/tinyagents/turn_runner.rsindex 8e9d7eebd2..e95b948127 100644--- a/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs+++ b/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs@@ -17,8 +17,6 @@ use anyhow::Result;use futures::StreamExt;use tinyagents_harness::agent_loop::AgentStreamItem;use tinyagents_harness::context::RunConfig;-#[cfg(test)]-use tinyagents_harness::context::RunContext;use tinyagents_harness::events::EventSink;use tinyagents_harness::store::StoreRegistry;use tinyagents_registry::DiagnosticSeverity;diff --git a/gitbooks/developing/architecture/agent-harness.md b/gitbooks/developing/architecture/agent-harness.mdindex bb03fd94e5..a7a942f9d4 100644--- a/gitbooks/developing/architecture/agent-harness.md+++ b/gitbooks/developing/architecture/agent-harness.md@@ -490,7 +490,7 @@ When the backend doesn't surface a charged amount (older builds, providers that`OpenHumanRunContext` is now the live carrier at the shared chat, channel, andsub-agent turn seam. Roots snapshot their currently scoped origin, progress,-dispatch state, thread, route slot, cancellation token, and workspace grant,+stop hooks, dispatch state, thread, route slot, cancellation token, and workspace grant,then pass an owned context to the runner; a recursive sub-agent forks it with`child()`, preserving shared cancellation/policy handles while isolating routeobservation and usage accounting. The shared runner createsdiff --git a/scripts/ci/agent-runtime-boundary-baseline.json b/scripts/ci/agent-runtime-boundary-baseline.jsonindex f81753b0e1..9d2cd90f0a 100644--- a/scripts/ci/agent-runtime-boundary-baseline.json+++ b/scripts/ci/agent-runtime-boundary-baseline.json@@ -79,21 +79,21 @@{"rule": "openhuman-runtime-bridge","path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",- "line": 29,+ "line": 27,"text": "use crate::agent::tinyagents::harness_assembly::{assemble_turn_harness, AssembledTurnHarness};","occurrence": 1},{"rule": "openhuman-runtime-bridge","path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",- "line": 201,+ "line": 199,"text": "pub(crate) async fn run_turn_via_tinyagents_shared(","occurrence": 1},{"rule": "openhuman-runtime-bridge","path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",- "line": 259,+ "line": 257,"text": "} = assemble_turn_harness(","occurrence": 1},@@ -1297,35 +1297,35 @@{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",- "line": 91,+ "line": 92,"text": "context.dispatch = crate::agent::harness::turn_dispatch_guard::current();","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",- "line": 92,+ "line": 93,"text": "context.thread_id = crate::agent::tinyagents::thread_context::current_thread_id();","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",- "line": 93,+ "line": 94,"text": "if let Some(slot) = crate::agent::tinyagents::current_route_slot() {","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",- "line": 96,+ "line": 97,"text": "if let Some(cancellation) = crate::agent::tinyagents::current_run_cancellation() {","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/tinyagents/host/run_context.rs",- "line": 99,+ "line": 100,"text": "context.workspace = crate::agent::turn_workspace::current()","occurrence": 1},@@ -1507,28 +1507,28 @@{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",- "line": 34,+ "line": 32,"text": "use crate::agent::tinyagents::run_cancellation_context::with_run_cancellation;","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",- "line": 589,+ "line": 587,"text": "let run_result = crate::agent::tinyagents::with_route_slot(run_route_slot, async move {","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",- "line": 590,+ "line": 588,"text": "crate::agent::tinyagents::thread_context::with_thread_id(run_thread_id, async move {","occurrence": 1},{"rule": "openhuman-task-local","path": "crates/openhuman-core/src/agent/tinyagents/turn_runner.rs",- "line": 591,+ "line": 589,"text": "with_run_cancellation(cancellation.clone(), async {","occurrence": 1},