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
chore: files changed crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs,crates/openhuman
Steven Enamakel83774af026f9
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rsindex 6157478ec4..9090c746fe 100644--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs@@ -24,7 +24,7 @@ use crate::agent::tinyagents::host::OpenHumanRunContext;use crate::agent::tinyagents::middleware::{self, TurnContextMiddleware};use crate::agent::tinyagents::model::TurnChatModel;use crate::agent::tinyagents::observability::{- IterationCursor, ProviderUsageCarry, SubagentScope, ToolFailureMap, ToolNameMap,+ ProviderUsageCarry, SubagentScope, ToolFailureMap, ToolNameMap,};use crate::agent::tinyagents::routes;use crate::agent::tinyagents::stop_hooks;@@ -157,7 +157,7 @@ pub(super) fn assemble_turn_harness(}let mut capability_registry: CapabilityRegistry<()> = CapabilityRegistry::new();- let cursor: IterationCursor = Arc::default();+ let cursor: tinyagents_harness::events::IterationCursor = Arc::default();// Shared `call_id → tool_name` map: the forwarder records the name on// tool-call start (the crate `ToolDelta` carries none), the bridge reads it// to label the argument fragments now streamed via `MessageDelta.tool_call`.diff --git a/crates/openhuman-core/src/agent/tinyagents/observability.rs b/crates/openhuman-core/src/agent/tinyagents/observability.rsindex 0b02f0c62f..b7a15d9d98 100644--- a/crates/openhuman-core/src/agent/tinyagents/observability.rs+++ b/crates/openhuman-core/src/agent/tinyagents/observability.rs@@ -25,7 +25,7 @@ use tinyinference_llm::usage::Usage;use crate::agent::progress::AgentProgress;pub(crate) use cap_pauser::{- CapPauser, IterationCursor, ProviderUsageCarry, SubagentScope, ToolFailureMap, ToolNameMap,+ ProviderUsageCarry, SubagentScope, ToolFailureMap, ToolNameMap,};pub(crate) use event_bridge::OpenhumanEventBridge;pub(crate) use event_projection::surface_cache_layout_events;diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rsindex 8318aeb0d2..4d6b815621 100644--- a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs+++ b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs@@ -13,9 +13,8 @@ use crate::agent::progress::AgentProgress;use crate::inference::provider::BilledUsage;use tinytools::humanize_tool_name;-use super::cap_pauser::{- IterationCursor, ProviderUsageCarry, SubagentScope, ToolFailureMap, ToolNameMap,-};+use super::cap_pauser::{ProviderUsageCarry, SubagentScope, ToolFailureMap, ToolNameMap};+use tinyagents_harness::events::{CallDedupe, IterationCursor, OrderedSender};#[derive(Default)]pub(super) struct BridgeState {@@ -82,7 +81,7 @@ pub(crate) struct OpenhumanEventBridge {/// delivered to this bridge. Keyed on the run-scoped model-call identity (the/// iteration cursor, bumped once per `ModelStarted`) so a given call's usage/// is recorded exactly once. See [`OpenhumanEventBridge::record_usage`].- pub(super) recorded_iterations: Mutex<std::collections::HashSet<u32>>,+ pub(super) recorded_iterations: CallDedupe,/// Per-iteration figures resolved by `record_usage` (see/// [`ResolvedCallFigures`]); taken by the `ModelCompleted` arm.pub(super) resolved_calls: Mutex<std::collections::HashMap<u32, ResolvedCallFigures>>,@@ -113,15 +112,7 @@ pub(crate) struct OpenhumanEventBridge {/// `try_send` can never jump ahead of an earlier spilled event and scramble/// start/completed ordering (which would leave a tool row stuck `running`/// when a `ToolCallCompleted` overtakes its `ToolCallStarted`) (#4466).- pub(super) overflow: Arc<Mutex<OverflowState>>,-}--/// Backpressure overflow state guarded by a single mutex so the "are we-/// draining?" decision and the queue mutation stay atomic together.-#[derive(Default)]-pub(super) struct OverflowState {- queue: std::collections::VecDeque<AgentProgress>,- draining: bool,+ pub(super) sender: OrderedSender<AgentProgress>,}impl OpenhumanEventBridge {@@ -165,7 +156,7 @@ impl OpenhumanEventBridge {tool_sets: Vec<Arc<Vec<Box<dyn tinytools::Tool>>>>,) -> Arc<Self> {Arc::new(Self {- on_progress,+ sender: OrderedSender::new(on_progress),model: model.into(),provider_id: provider_id.into(),max_iterations: max_iterations as u32,@@ -174,13 +165,12 @@ impl OpenhumanEventBridge {tool_names,failure_map,usage_carry,- recorded_iterations: Mutex::new(std::collections::HashSet::new()),+ recorded_iterations: CallDedupe::default(),resolved_calls: Mutex::new(std::collections::HashMap::new()),tool_started_at: Mutex::new(std::collections::HashMap::new()),unknown_calls: Mutex::new(std::collections::HashMap::new()),tool_sets,state: Mutex::new(BridgeState::default()),- overflow: Arc::default(),})}@@ -263,63 +253,13 @@ impl OpenhumanEventBridge {/// `Closed` channel means the receiver is gone (turn tore down), where/// dropping is correct.pub(super) fn send(&self, progress: AgentProgress) {- use tokio::sync::mpsc::error::TrySendError;- let Some(tx) = &self.on_progress else {- return;- };- // Hold the overflow lock across the ordering decision so "are we- // draining?" and the queue mutation are atomic (try_send is- // non-blocking, so holding a std mutex across it is fine).- let mut ov = self.overflow.lock().unwrap_or_else(|p| p.into_inner());- if ov.draining {- // Already spilling: queue in order; the single forwarder delivers it.- ov.queue.push_back(progress);- return;- }- match tx.try_send(progress) {- Ok(()) => {}- Err(TrySendError::Closed(_)) => {}- Err(TrySendError::Full(progress)) => {- // Backpressure, not capacity loss. Enter ordered-drain mode:- // queue this event and spawn ONE forwarder that awaits `send()`- // per event in FIFO order. `draining` stays set (so every later- // event also queues here) until the buffer fully drains — that is- // what stops a later `try_send` from overtaking a spilled earlier- // event and scrambling start/completed ordering.- if let Ok(handle) = tokio::runtime::Handle::try_current() {- ov.queue.push_back(progress);- ov.draining = true;- let overflow = Arc::clone(&self.overflow);- let tx = tx.clone();- drop(ov);- handle.spawn(async move {- loop {- let next = {- let mut ov = overflow.lock().unwrap_or_else(|p| p.into_inner());- match ov.queue.pop_front() {- Some(item) => item,- None => {- ov.draining = false;- break;- }- }- };- if tx.send(next).await.is_err() {- // Receiver gone: stop draining, discard the rest.- let mut ov = overflow.lock().unwrap_or_else(|p| p.into_inner());- ov.queue.clear();- ov.draining = false;- break;- }- }- });- } else {- tracing::debug!(- model = %self.model,- "[tinyagents] progress channel full and no runtime to defer send; dropping one delta"- );- }- }+ use tinyagents_harness::events::SendFailure;+ match self.sender.send(progress) {+ Ok(()) | Err(SendFailure::Closed(_)) => {}+ Err(SendFailure::Backpressure(_)) => tracing::debug!(+ model = %self.model,+ "[tinyagents] progress channel full and could not defer send; dropping one delta"+ ),}}@@ -342,20 +282,14 @@ impl OpenhumanEventBridge {// bridge instance is per-run (parent or child scope), so the set is// naturally (run, turn)-scoped. First writer for an iteration records;// any later `UsageRecorded` for the same iteration is a duplicate.- {- let mut seen = self- .recorded_iterations- .lock()- .unwrap_or_else(|p| p.into_inner());- if !seen.insert(iteration) {- tracing::debug!(- iteration,- model = %self.model,- child = self.scope.is_some(),- "[budget] duplicate UsageRecorded for model call — skipping double record"- );- return;- }+ if !self.recorded_iterations.first_claim(iteration) {+ tracing::debug!(+ iteration,+ model = %self.model,+ child = self.scope.is_some(),+ "[budget] duplicate UsageRecorded for model call — skipping double record"+ );+ return;}// Drain the provider-usage side-channel the model adapter fed for this// model call (FIFO, one push per provider response). The crate `Usage`diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs b/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rsindex 744e57695e..4c438e6b03 100644--- a/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs+++ b/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs@@ -17,7 +17,7 @@ impl EventListener for OpenhumanEventBridge {fn on_event(&self, record: &EventRecord) {match &record.event {AgentEvent::ModelStarted { .. } => {- let iteration = self.cursor.fetch_add(1, Ordering::SeqCst) + 1;+ let iteration = tinyagents_harness::events::advance_iteration(&self.cursor);match &self.scope {None => self.send(AgentProgress::IterationStarted {iteration,diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs b/crates/openhuman-core/src/agent/tinyagents/turn_runner.rsindex f5278bfb6d..250adda016 100644--- a/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs+++ b/crates/openhuman-core/src/agent/tinyagents/turn_runner.rs@@ -20,7 +20,7 @@ use crate::agent::tinyagents::harness_assembly::{assemble_turn_harness, Assembleuse crate::agent::tinyagents::host::steering::shared_steering_registry;use crate::agent::tinyagents::host::OpenHumanRunContext;use crate::agent::tinyagents::middleware::TurnContextMiddleware;-use crate::agent::tinyagents::observability::{CapPauser, OpenhumanEventBridge, SubagentScope};+use crate::agent::tinyagents::observability::{OpenhumanEventBridge, SubagentScope};use crate::agent::tinyagents::turn_models::TurnModels;use crate::agent::tinyagents::turn_outcome::TinyagentsTurnOutcome;use crate::agent::tinyagents::turn_policy::effective_max_iterations;@@ -515,12 +515,24 @@ pub(super) async fn run_turn_via_tinyagents_body(.is_none().then(|| run_context.dispatch.clone()).flatten();- events.subscribe(CapPauser::new(+ let recorder: Option<tinyagents_harness::events::PauseRecorder> =+ dispatch_guard.map(|guard| {+ Arc::new(move |completed: u64, cap: u64| {+ guard.record_pause_requested(completed, cap)+ }) as tinyagents_harness::events::PauseRecorder+ });+ match tinyagents_harness::events::CapPauser::with_recorder(handle.clone(),max_iterations,ctx.run_id().as_str(),- dispatch_guard,- ));+ recorder,+ ) {+ Ok(pauser) => events.subscribe(pauser),+ Err(err) => tracing::warn!(+ error = %err,+ "[tinyagents] model-call cap pauser not installed"+ ),+ }}}