Skip to content

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

feat(session_host): add support for typed message input to turns

Steven Enamakel828c3bc5e290
diff --git a/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs b/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs
index 5b0a20e592..9646e3d6ac 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime/run_loop.rs
@@ -10,6 +10,7 @@ use crate::security::prompt_injection::{
};
use anyhow::Result;
use tinyagents_harness::agent_error::AgentError;
+use tinyinference_llm::message::Message;
impl OpenHumanSessionHost {
// ─────────────────────────────────────────────────────────────────
@@ -43,6 +44,29 @@ impl OpenHumanSessionHost {
message: &str,
origin: Option<crate::agent::turn_origin::AgentTurnOrigin>,
approval: crate::security::approval::ApprovalTurnContext,
+ ) -> Result<String> {
+ self.run_single_with_input(message, None, origin, approval)
+ .await
+ }
+
+ /// Run a turn with a trusted, already-resolved typed user message.
+ pub(crate) async fn run_single_with_approval_and_message(
+ &mut self,
+ message: &str,
+ input: Message,
+ origin: Option<crate::agent::turn_origin::AgentTurnOrigin>,
+ approval: crate::security::approval::ApprovalTurnContext,
+ ) -> Result<String> {
+ self.run_single_with_input(message, Some(input), origin, approval)
+ .await
+ }
+
+ async fn run_single_with_input(
+ &mut self,
+ message: &str,
+ input: Option<Message>,
+ origin: Option<crate::agent::turn_origin::AgentTurnOrigin>,
+ approval: crate::security::approval::ApprovalTurnContext,
) -> Result<String> {
let origin = origin.or_else(|| {
crate::core::runtime::DispatchCtx::from_weak(self.host_env.core.as_ref())
@@ -103,10 +127,24 @@ impl OpenHumanSessionHost {
channel: self.event_channel().to_string(),
});
- match self
- .turn_with_approval(message, origin.as_ref(), approval)
- .await
- {
+ let turn = async {
+ match input {
+ Some(input) => {
+ self.turn_with_approval_and_message(
+ message,
+ input,
+ origin.as_ref(),
+ approval,
+ )
+ .await
+ }
+ None => {
+ self.turn_with_approval(message, origin.as_ref(), approval)
+ .await
+ }
+ }
+ };
+ match turn.await {
Ok(response) => {
let history = self.history();
let new_entries = Self::new_entries_for_turn(&history_snapshot, &history);
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs
index 9427e61ff4..6dd1497ee0 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs
@@ -1,5 +1,6 @@
use anyhow::Result;
use tinyagents_runtime::{ResumeMode, SessionTurnRequest, TurnOptions};
+use tinyinference_llm::message::Message;
use crate::agent::{
message_convert::user_message_from_text, session_host::types::OpenHumanSessionHost,
@@ -30,6 +31,30 @@ impl OpenHumanSessionHost {
user_message: &str,
origin: Option<&crate::agent::turn_origin::AgentTurnOrigin>,
approval: crate::security::approval::ApprovalTurnContext,
+ ) -> Result<String> {
+ self.turn_with_approval_input(user_message, None, origin, approval)
+ .await
+ }
+
+ /// Dispatch a turn whose media parts were resolved by the trusted host
+ /// against the exact persisted row immediately before execution.
+ pub(crate) async fn turn_with_approval_and_message(
+ &mut self,
+ user_message: &str,
+ input: Message,
+ origin: Option<&crate::agent::turn_origin::AgentTurnOrigin>,
+ approval: crate::security::approval::ApprovalTurnContext,
+ ) -> Result<String> {
+ self.turn_with_approval_input(user_message, Some(input), origin, approval)
+ .await
+ }
+
+ async fn turn_with_approval_input(
+ &mut self,
+ user_message: &str,
+ input: Option<Message>,
+ origin: Option<&crate::agent::turn_origin::AgentTurnOrigin>,
+ approval: crate::security::approval::ApprovalTurnContext,
) -> Result<String> {
// The turn's context is bound once, here, before the runtime session
// snapshots the host environment: the one ambient read at the turn
@@ -38,7 +63,12 @@ impl OpenHumanSessionHost {
self.host_env.core = crate::core::runtime::DispatchCtx::ambient().downgrade();
}
self.ensure_runtime_session()?;
- let staged = super::attachment_input::stage_turn(self, user_message, origin).await?;
+ let input = match input {
+ Some(input) => input,
+ None => user_message_from_text(
+ super::attachment_input::stage_turn(self, user_message, origin).await?.as_str(),
+ ),
+ };
let mut context = OpenHumanRunContext::new().with_host_env(&self.host_env);
context.untrusted_input_turn = self.untrusted_input;
context.origin = origin.cloned();
@@ -135,7 +165,7 @@ impl OpenHumanSessionHost {
.as_mut()
.expect("runtime session initialized")
.turn(
- SessionTurnRequest::new(user_message_from_text(staged.as_str())),
+ SessionTurnRequest::new(input),
options,
);
let outcome = Box::pin(turn)