Skip to content

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

feat(agent): emit turn stopped events and defer terminal completion

Steven Enamakel65a2594669da
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
index 4f6fc983e3..b29bff15c2 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs
@@ -709,6 +709,8 @@ async fn drive_turn(
&subagent_scope,
pause_at_cap,
turn_journal.as_ref(),
+ &sink,
+ defer_turn_completed_to_caller,
compression_mw.as_ref(),
prompt_cache_guard.as_ref(),
turn_completed_sink,
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs b/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs
index 26c17909d3..13ad7e5bc2 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_outcome.rs
@@ -10,8 +10,8 @@ use tinytools_agent::dialect::TranscriptEntry;
/// post-run close/repair and classified any wind-down stop.
#[derive(Clone)]
pub(crate) struct DeferredTurnTerminal {
- events: tinyagents_harness::events::EventSink,
- journal: Option<crate::agent::tinyagents::journal::TurnJournal>,
+ pub(crate) events: tinyagents_harness::events::EventSink,
+ pub(crate) journal: Option<crate::agent::tinyagents::journal::TurnJournal>,
}
impl DeferredTurnTerminal {
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs b/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
index 4deb044e8f..6eb149ecc8 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_run_finalize.rs
@@ -165,6 +165,25 @@ pub(super) async fn finalize_turn_outcome(
false,
hit_cap,
);
+ if let Some(stop_fact) = stop.clone() {
+ event_sink.emit(tinyagents_harness::events::AgentEvent::TurnStopped {
+ // The event uses a 1-based attempt ordinal, even when the run
+ // stopped before the first model request.
+ turn: (run.model_calls as u32).max(1),
+ stop: stop_fact,
+ });
+ }
+ let deferred_terminal = if defer_terminal_to_caller {
+ Some(crate::agent::tinyagents::turn_outcome::DeferredTurnTerminal {
+ events: event_sink.clone(),
+ journal: turn_journal.cloned(),
+ })
+ } else {
+ if let Some(journal) = turn_journal {
+ journal.finish_completed().await;
+ }
+ None
+ };
if let Some(stop) = stop.as_ref().filter(|_| turn_completed_sink.is_some()) {
tracing::debug!(
model,
@@ -278,6 +297,7 @@ pub(super) async fn finalize_turn_outcome(
}
TinyagentsTurnOutcome {
+ deferred_terminal,
text,
resolved_route,
history: crate::agent::message_convert::messages_to_history(&run.messages),