Skip to content

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

fix(runtime_session): handle memory ingest for empty session

Steven Enamakelcfad555608a2
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 7d41abf40a..72ee586b8a 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -5,8 +5,11 @@
//! prefix reconciliation, tool snapshots, resume and persistence remain inside
//! the runtime session.
+mod memory_ingest;
mod permanent;
+pub(super) use memory_ingest::committed_tool_calls;
+
use std::sync::Arc;
use anyhow::Result;
@@ -736,39 +739,6 @@ impl OpenHumanTurnPrelude {
self.publish_committed_turn(receipt);
}
- /// Hands a committed, user-authored, threaded turn to memory's
- /// conversation ingestion (`DomainEvent::ConversationTurnCommitted`).
- /// Tool calls travel by name and id only.
- fn publish_committed_turn(&self, receipt: &CommitReceipt<OpenHumanRunContext>) {
- let user_text = self
- .mutable
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner)
- .pending_user_text
- .take();
- let (Some(user_text), Some(thread_id)) = (user_text, self.thread_id.clone()) else {
- return;
- };
- let tool_calls = committed_tool_calls(&receipt.outcome.history);
- log::debug!(
- "[session_host] conversation turn committed tool_calls={}",
- tool_calls.len()
- );
- crate::core::bus::BUS.publish(
- crate::core::events::DomainEvent::ConversationTurnCommitted {
- thread_id,
- agent_id: Some(self.agent_definition_id.clone()).filter(|id| !id.trim().is_empty()),
- workspace: Some(self.action_dir.display().to_string()),
- channel: Some(self.event_channel.clone())
- .filter(|channel| !channel.trim().is_empty()),
- user_text,
- assistant_text: receipt.outcome.output.clone().unwrap_or_default(),
- tool_calls,
- workspace_dir: self.workspace_dir.clone(),
- },
- );
- }
-
fn mirror_transcript_after_commit(&self, receipt: &CommitReceipt<OpenHumanRunContext>) {
let Some(path) = receipt
.transcript
@@ -898,29 +868,6 @@ pub(super) fn holistic_last_turn_usage(
}
}
-/// The tool calls of the last exchange in `history` (everything after the
-/// final user message), by name and id.
-pub(super) fn committed_tool_calls(
- history: &[Message],
-) -> Vec<crate::core::events::ConversationToolCall> {
- let start = history
- .iter()
- .rposition(|message| matches!(message, Message::User(_)))
- .map_or(0, |index| index + 1);
- history[start..]
- .iter()
- .filter_map(|message| match message {
- Message::Assistant(assistant) => Some(&assistant.tool_calls),
- _ => None,
- })
- .flatten()
- .map(|call| crate::core::events::ConversationToolCall {
- name: call.name.clone(),
- id: Some(call.id.clone()).filter(|id| !id.is_empty()),
- })
- .collect()
-}
-
impl OpenHumanSessionHost {
pub(super) fn update_runtime_prelude_progress(
&mut self,
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest.rs
new file mode 100644
index 0000000000..6c1b105793
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest.rs
@@ -0,0 +1,65 @@
+//! Handing committed turns to memory's conversation ingestion.
+
+use tinyagents_harness::session::CommitReceipt;
+use tinyagents_harness::Message;
+
+use super::OpenHumanSessionHost;
+use crate::agent::tinyagents::host::OpenHumanRunContext;
+
+impl OpenHumanSessionHost {
+ /// Hands a committed, user-authored, threaded turn to memory's
+ /// conversation ingestion (`DomainEvent::ConversationTurnCommitted`).
+ /// Tool calls travel by name and id only.
+ fn publish_committed_turn(&self, receipt: &CommitReceipt<OpenHumanRunContext>) {
+ let user_text = self
+ .mutable
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .pending_user_text
+ .take();
+ let (Some(user_text), Some(thread_id)) = (user_text, self.thread_id.clone()) else {
+ return;
+ };
+ let tool_calls = committed_tool_calls(&receipt.outcome.history);
+ log::debug!(
+ "[session_host] conversation turn committed tool_calls={}",
+ tool_calls.len()
+ );
+ crate::core::bus::BUS.publish(
+ crate::core::events::DomainEvent::ConversationTurnCommitted {
+ thread_id,
+ agent_id: Some(self.agent_definition_id.clone()).filter(|id| !id.trim().is_empty()),
+ workspace: Some(self.action_dir.display().to_string()),
+ channel: Some(self.event_channel.clone())
+ .filter(|channel| !channel.trim().is_empty()),
+ user_text,
+ assistant_text: receipt.outcome.output.clone().unwrap_or_default(),
+ tool_calls,
+ workspace_dir: self.workspace_dir.clone(),
+ },
+ );
+ }
+}
+
+/// The tool calls of the last exchange in `history` (everything after the
+/// final user message), by name and id.
+pub(super) fn committed_tool_calls(
+ history: &[Message],
+) -> Vec<crate::core::events::ConversationToolCall> {
+ let start = history
+ .iter()
+ .rposition(|message| matches!(message, Message::User(_)))
+ .map_or(0, |index| index + 1);
+ history[start..]
+ .iter()
+ .filter_map(|message| match message {
+ Message::Assistant(assistant) => Some(&assistant.tool_calls),
+ _ => None,
+ })
+ .flatten()
+ .map(|call| crate::core::events::ConversationToolCall {
+ name: call.name.clone(),
+ id: Some(call.id.clone()).filter(|id| !id.is_empty()),
+ })
+ .collect()
+}