Skip to content

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

refactor(embed): pass budget explicitly instead of ambient scope

Steven Enamakelf56792eff944
diff --git a/crates/openhuman-embed/src/complete.rs b/crates/openhuman-embed/src/complete.rs
index 1e4db46008..5b6cf9b467 100644
--- a/crates/openhuman-embed/src/complete.rs
+++ b/crates/openhuman-embed/src/complete.rs
@@ -594,10 +594,6 @@ impl Completer {
request.messages.len(),
request.timeout_ms
);
- let call = openhuman_core::inference::host_runtime::ops::complete_once(
- &endpoint,
- request.into_wire(),
- );
let budget = self
.budget
.as_ref()
@@ -605,15 +601,12 @@ impl Completer {
ledger: budget.ledger.child(crate::budget::SpendLimits::default()),
call: budget.call,
});
- let call = async {
- match &budget {
- Some(budget) => {
- openhuman_core::agent::tinyagents::budget::with_budget(budget.clone(), call)
- .await
- }
- None => call.await,
- }
- };
+ // The spend ledger is an explicit argument of the call, not an ambient scope.
+ let call = openhuman_core::inference::host_runtime::ops::complete_once(
+ &endpoint,
+ request.into_wire(),
+ budget.as_ref(),
+ );
let started = std::time::Instant::now();
let response = call.await.map_err(|message| {
if let Some(source) = budget.as_ref().and_then(|budget| budget.ledger.refusal()) {
diff --git a/crates/openhuman-embed/src/fanout.rs b/crates/openhuman-embed/src/fanout.rs
index 83e290ad92..a46fdbad9e 100644
--- a/crates/openhuman-embed/src/fanout.rs
+++ b/crates/openhuman-embed/src/fanout.rs
@@ -90,9 +90,11 @@ fn call(call: LeafCall, budget: ModelBudget, leaf: bool) -> CallFuture {
.map(CallOutcome::Completion)
}),
LeafCall::Turn(turn) => Box::pin(async move {
- openhuman_core::agent::tinyagents::budget::with_spawn_depth_limit(
- if leaf { 0 } else { 1 },
- Box::pin((*turn).budget(budget).send()),
+ Box::pin(
+ (*turn)
+ .budget(budget)
+ .with_spawn_depth_limit(if leaf { 0 } else { 1 })
+ .send(),
)
.await
.map(CallOutcome::Turn)