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-embed/src/turn_control.rs
Steven Enamakel60b1675eb954
diff --git a/crates/openhuman-embed/src/turn_control.rs b/crates/openhuman-embed/src/turn_control.rsindex 1fc3852b2d..0602faaf1a 100644--- a/crates/openhuman-embed/src/turn_control.rs+++ b/crates/openhuman-embed/src/turn_control.rs@@ -24,17 +24,8 @@ impl Turn {/// that is a build/composition fact, not a failure, and a host should hide/// the surface rather than report an error.pub async fn send(mut self) -> Result<TurnOutcome, CoreError> {- let hooks = std::mem::take(&mut self.hooks);let environment = self.tool_env.take();- let fresh_tools = self.tools.is_some();- let dispatch = hooks.scope(Box::pin(self.send_scoped()));- let dispatch = async move {- if fresh_tools {- openhuman_core::agent::tool_snapshot_scope::with_fresh_snapshot(dispatch).await- } else {- dispatch.await- }- };+ let dispatch = Box::pin(self.send_scoped());match environment {Some(environment) => environment.scope(dispatch).await,None => dispatch.await,@@ -77,7 +68,11 @@ impl Turn {native.cancel();}))});- openhuman_core::agent::host_overrides::with_cancellation(token, self.send_traced()).await+ // The native token is minted here and travels as an explicit value:+ // the relay above fires it, and `send_inner` hands it to the core on+ // the turn's host environment.+ self.native_cancellation = Some(token);+ self.send_traced().await}async fn send_traced(mut self) -> Result<TurnOutcome, CoreError> {@@ -127,7 +122,7 @@ impl Turn {success: false,};let forward = self.progress.take();- let token = openhuman_core::agent::host_overrides::current_cancellation();+ let token = self.native_cancellation.clone().unwrap_or_default();let acknowledgement = self.cancellation.clone();let deadline = self.control_deadline;let (tx, mut rx) = tokio::sync::mpsc::channel(64);@@ -194,7 +189,7 @@ impl Turn {Box::pin(async move {let deadline = self.control_deadline;let token = self.token_cancellation.clone();- let native = openhuman_core::agent::host_overrides::current_cancellation();+ let native = self.native_cancellation.clone().unwrap_or_default();let cancellation = self.cancellation.take().or_else(|| {(deadline.is_some() || token.is_some()).then(crate::TurnCancellation::default)});@@ -335,7 +330,25 @@ impl Turn {},}})?;+ let budget = self.budget.take().map(|budget| crate::budget::ModelBudget {+ ledger: budget.ledger.child(crate::budget::SpendLimits::default()),+ call: budget.call,+ });+ // Everything the core honours for this turn rides one explicit value;+ // nothing is recovered from an ambient scope below this point.+ let chat_env = openhuman_core::inference::host_runtime::ops::AgentChatEnv {+ progress: self.progress.take(),+ host: openhuman_core::agent::turn_env::HostTurnEnv {+ model_budget: budget.clone(),+ spawn_depth_limit: self.spawn_depth_limit,+ cancellation: self.native_cancellation.clone(),+ hooks: std::mem::take(&mut self.hooks),+ fresh_tool_snapshot: self.tools.is_some(),+ ..Default::default()+ },+ };let options = AgentTurnOptions {+ chat_env,// Captured here, before the dispatch can hop to a core worker that// does not inherit task locals; the core re-establishes it around// the turn.@@ -361,36 +374,11 @@ impl Turn {tools: self.tools.take(),attachments: std::mem::take(&mut self.attachments),};- let budget = self.budget.take().map(|budget| crate::budget::ModelBudget {- ledger: budget.ledger.child(crate::budget::SpendLimits::default()),- call: budget.call,- });let dispatch = dispatch(self.target, self.request, self.seed.take(), usage, options);- let dispatch = async {- match &budget {- Some(budget) => {- openhuman_core::agent::tinyagents::budget::with_budget(budget.clone(), dispatch)- .await- }- None => dispatch.await,- }- };- let reply = match (self.origin, self.progress) {- (Some(origin), Some(sink)) => {- openhuman_core::agent::progress_sink::with_progress_sink(- sink,- openhuman_core::agent::turn_origin::with_origin(origin, dispatch),- )- .await- }- (Some(origin), None) => {- openhuman_core::agent::turn_origin::with_origin(origin, dispatch).await- }- (None, Some(sink)) => {- openhuman_core::agent::progress_sink::with_progress_sink(sink, dispatch).await- }- (None, None) => dispatch.await,+ let reply = match self.origin {+ Some(origin) => openhuman_core::agent::turn_origin::with_origin(origin, dispatch).await,+ None => dispatch.await,}.inspect_err(|err| {// Log a redacted failure event so dispatch errors are visible in