Skip to content

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

feat(agent): add concurrent turn diagnostics to session and turn execution

Steven Enamakeld708ee5d78d9
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index d4952936b5..fbf906a01d 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -41,8 +41,8 @@ pub(super) fn concurrent_turn_diagnostic(stage: usize) {
if std::env::var_os("OH_DIAG_CONCURRENT").is_none() {
return;
}
- static COUNTS: [std::sync::atomic::AtomicUsize; 5] =
- [const { std::sync::atomic::AtomicUsize::new(0) }; 5];
+ static COUNTS: [std::sync::atomic::AtomicUsize; 14] =
+ [const { std::sync::atomic::AtomicUsize::new(0) }; 14];
let count = COUNTS[stage].fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
eprintln!("OpenHuman concurrent diagnostic stage={stage} count={count}");
}
@@ -411,6 +411,7 @@ impl OpenHumanSessionHost {
.effective_context_window(&prelude.model_name)
.await
.unwrap_or_default();
+ concurrent_turn_diagnostic(5);
options
.run_context
.data
@@ -441,12 +442,14 @@ impl OpenHumanSessionHost {
origin,
)),
);
+ concurrent_turn_diagnostic(6);
options.run_context.data.memory_turn = memory_turn;
request.input = user_message_from_text(&enriched);
let mut preparation =
prelude.prepare(new_session).await.map_err(|error| {
tinyagents_runtime::RuntimeError::Driver(error.to_string())
})?;
+ concurrent_turn_diagnostic(7);
prelude.refresh_permanent_prefix(&mut preparation, view.prefix);
if turn.overrides.suppress_tools {
// One-off tool-less turn: must not become the
@@ -496,6 +499,7 @@ impl OpenHumanSessionHost {
.unwrap_or_else(|poisoned| poisoned.into_inner())
.required_output
.clone();
+ concurrent_turn_diagnostic(8);
Ok(preparation)
})
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
index d045a5fb8a..614d74b219 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
@@ -10,6 +10,16 @@
use std::collections::{BTreeSet, HashSet};
use std::sync::Arc;
+fn concurrent_turn_diagnostic(stage: usize) {
+ if std::env::var_os("OH_DIAG_CONCURRENT").is_none() {
+ return;
+ }
+ static COUNTS: [std::sync::atomic::AtomicUsize; 4] =
+ [const { std::sync::atomic::AtomicUsize::new(0) }; 4];
+ let count = COUNTS[stage].fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
+ eprintln!("turn_exec concurrent diagnostic stage={stage} count={count}");
+}
+
use anyhow::Result;
use tinyagents_harness::runtime::{AgentInvocation, AgentTurnRequest, InvocationRuntime};
use tinyagents_harness::store::{InMemoryStore as ToolResultArtifactIndexStore, StoreRegistry};
@@ -139,6 +149,7 @@ async fn drive_turn(
)>,
native_subagent: Option<NativeSubagentRunContext>,
) -> Result<TinyagentsTurnOutcome> {
+ concurrent_turn_diagnostic(0);
let TurnSpec {
mut run_context,
turn_models,
@@ -525,6 +536,7 @@ async fn drive_turn(
stream: streaming,
controls,
};
+ concurrent_turn_diagnostic(1);
let mut prepared = driver.prepare(request).await.map_err(|failure| {
tracing::error!(error = %failure.error, "[tinyagents] turn driver could not prepare the turn");
anyhow::anyhow!("{}", failure.error)
@@ -624,6 +636,7 @@ async fn drive_turn(
tools = tool_count,
"[tinyagents] turn harness assembled"
);
+ concurrent_turn_diagnostic(2);
// Heap-allocate the harness drive future. It is large (it owns the whole run
// context, middleware stack, and loop state), and a sub-agent turn runs
@@ -632,6 +645,7 @@ async fn drive_turn(
// pointer on the stack at each level.
let resolved_route_slot = run_context.resolved_route.clone();
let (run_result, early_exit) = if let Some((base, agent_id)) = hosted_root {
+ concurrent_turn_diagnostic(3);
let tool_sets = hosted_tool_sets.expect("hosted root retained its tool sets");
let mut host_bundle =
crate::agent::tinyagents::host::OpenHumanHostBundleFactory::build_for_invocation(