Skip to content

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

refactor(session_host): extract driver loop into helper

Steven Enamakelf00048a2771a
diff --git a/crates/openhuman-core/src/agent/session_host/driver.rs b/crates/openhuman-core/src/agent/session_host/driver.rs
index 917a3cf336..829c0fef07 100644
--- a/crates/openhuman-core/src/agent/session_host/driver.rs
+++ b/crates/openhuman-core/src/agent/session_host/driver.rs
@@ -431,6 +431,26 @@ impl SessionDriver<OpenHumanRunContext> for OpenHumanSessionDriver {
}
}
+/// Input and output tokens of the turn's final model call.
+///
+/// The grounded close and the required-output repair both run after the
+/// harness loop, in that order, so the newest of them that reached the
+/// provider made the final call; without either, the loop's last answered
+/// call did.
+fn final_call_tokens(
+ loop_last_call: Option<(u64, u64)>,
+ close: Option<&grounded_close::RepairUsage>,
+ repair: Option<&grounded_close::RepairUsage>,
+) -> (u64, u64) {
+ [repair, close]
+ .into_iter()
+ .flatten()
+ .find(|usage| usage.last_call_input_tokens > 0)
+ .map(|usage| (usage.last_call_input_tokens, usage.last_call_output_tokens))
+ .or(loop_last_call)
+ .unwrap_or_default()
+}
+
fn system_prefix_len(history: &[Message]) -> usize {
history
.iter()