Skip to content

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

refactor(session_host): move post-commit finalization into a sink

Steven Enamakel9c6a288ded45
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 6dd2b90afc..ac9be9ff7a 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -502,34 +502,7 @@ impl OpenHumanSessionHost {
Ok(())
})
},
- {
- let state = self.runtime_state.clone();
- let post_turn_hooks = self.post_turn_hooks.clone();
- let session_id = self.event_session_id.clone();
- let agent_id = self.agent_definition_id.clone();
- let channel = self.event_channel.clone();
- move |receipt| {
- let state = state.clone();
- let post_turn_hooks = post_turn_hooks.clone();
- let session_id = session_id.clone();
- let agent_id = agent_id.clone();
- let channel = channel.clone();
- Box::pin(async move {
- post_commit::finalize_committed_turn(
- &state,
- &post_turn_hooks,
- post_commit::TurnIdentity {
- session_id,
- agent_id,
- channel,
- },
- receipt,
- )
- .await;
- Ok(())
- })
- }
- },
+ |_| Box::pin(async { Ok(()) }),
{
let state = self.runtime_state.clone();
move |terminal| {
@@ -549,6 +522,15 @@ impl OpenHumanSessionHost {
let mut builder = SessionBuilder::new(driver)
.codec(Arc::new(OpenHumanTranscriptCodec))
.hooks(hooks)
+ .post_commit_sink(Arc::new(post_commit::OpenHumanPostCommitSink {
+ state: self.runtime_state.clone(),
+ hooks: self.post_turn_hooks.clone(),
+ identity: post_commit::TurnIdentityOwned {
+ session_id: self.event_session_id.clone(),
+ agent_id: self.agent_definition_id.clone(),
+ channel: self.event_channel.clone(),
+ },
+ }))
.retain_recorded_tools(!self.host_only && !self.host_env.fresh_tool_snapshot);
let meta = self.runtime_transcript_meta();
builder = if let Some(locator) = injected_locator {
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit.rs
index 5290d1a782..7dfdda3162 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/post_commit.rs
@@ -26,6 +26,43 @@ use std::time::{Duration, Instant};
use tinyinference_llm::message::Message;
+pub(super) struct OpenHumanPostCommitSink {
+ pub(super) state: std::sync::Arc<std::sync::Mutex<super::OpenHumanSessionState>>,
+ pub(super) hooks: std::sync::Arc<Vec<std::sync::Arc<dyn tinyagents_harness::host::LearningSink>>>,
+ pub(super) identity: TurnIdentityOwned,
+}
+
+pub(super) struct TurnIdentityOwned {
+ pub(super) session_id: String,
+ pub(super) agent_id: String,
+ pub(super) channel: String,
+}
+
+#[async_trait::async_trait]
+impl tinyagents_runtime::PostCommitSink<crate::agent::tinyagents::host::OpenHumanRunContext>
+ for OpenHumanPostCommitSink
+{
+ async fn after_commit(
+ &self,
+ observation: &tinyagents_runtime::PostCommitObservation<
+ crate::agent::tinyagents::host::OpenHumanRunContext,
+ >,
+ ) -> Result<(), tinyagents_runtime::RuntimeError> {
+ finalize_committed_turn(
+ &self.state,
+ &self.hooks,
+ TurnIdentity {
+ session_id: self.identity.session_id.clone(),
+ agent_id: self.identity.agent_id.clone(),
+ channel: self.identity.channel.clone(),
+ },
+ observation.receipt.clone(),
+ )
+ .await;
+ Ok(())
+ }
+}
+
pub(super) fn take_terminal_sidecar(
state: &std::sync::Arc<std::sync::Mutex<super::OpenHumanSessionState>>,
terminal: tinyagents_runtime::SessionTerminal,