Skip to content

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

feat(agent): add support for native staged parts and message IDs

Steven Enamakel6feb57ce01c3
diff --git a/crates/openhuman-core/src/agent/host_agents.rs b/crates/openhuman-core/src/agent/host_agents.rs
index 3875ea8f31..4b702c5afc 100644
--- a/crates/openhuman-core/src/agent/host_agents.rs
+++ b/crates/openhuman-core/src/agent/host_agents.rs
@@ -104,6 +104,8 @@ impl HostAgent {
turn_deadline: Option<std::time::Duration>,
imported_history: &[tinyagents_session::transcript::TranscriptMessage],
legacy_history: Option<crate::channels::providers::relay::LegacyHistoryImport>,
+ staged_parts: Vec<tinychannels_bus::ContentPart>,
+ staged_message_id: Option<String>,
) -> anyhow::Result<String> {
let config = self.config.clone();
let agent_id = self.definition.id.clone();
@@ -127,6 +129,8 @@ impl HostAgent {
crate::agent::turn_host::AgentTurnRequest {
message: message.to_owned(),
message_input,
+ native_staged_parts: staged_parts,
+ native_message_id: staged_message_id,
thread_id: Some(session_key.to_owned()),
origin,
approval: approval.clone(),
diff --git a/crates/openhuman-core/src/agent/queued_turn.rs b/crates/openhuman-core/src/agent/queued_turn.rs
index 82538846eb..bbd39776d7 100644
--- a/crates/openhuman-core/src/agent/queued_turn.rs
+++ b/crates/openhuman-core/src/agent/queued_turn.rs
@@ -59,6 +59,7 @@ pub struct QueuedPayload {
/// Host-created staged refs authorized for this exact external turn.
/// Requeued synthetic placeholders never inherit this grant.
pub(crate) native_staged_parts: Vec<tinychannels_bus::ContentPart>,
+ pub(crate) native_message_id: Option<String>,
/// A preparation failure is sent through the shared runner's terminal
/// path without invoking the model.
pub(crate) native_preparation_error: Option<String>,
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
index 73e7d08497..7b3a110055 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -321,6 +321,10 @@ pub struct OpenHumanRunContext {
pub(crate) tool_result_artifact_index: Option<Arc<ToolResultArtifactIndexStore>>,
/// Current-turn attachment placeholders forwarded to vision delegates.
pub attachment_placeholders: Arc<Vec<String>>,
+ /// Opaque native media refs issued for this exact root channel turn.
+ pub(crate) native_staged_parts: Vec<tinychannels_bus::ContentPart>,
+ /// Provider message identity for durable post-commit claims.
+ pub(crate) native_message_id: Option<String>,
/// Dispatch guard shared by synchronous delegates in this run.
pub dispatch: Option<Arc<TurnDispatchState>>,
/// Optional task recency restriction for integration tools.
@@ -457,6 +461,8 @@ impl OpenHumanRunContext {
file_state_agent_id: None,
tool_result_artifact_index: None,
attachment_placeholders: Arc::new(Vec::new()),
+ native_staged_parts: Vec::new(),
+ native_message_id: None,
dispatch: None,
task_recency_window: None,
command_environment: None,
@@ -596,6 +602,8 @@ impl OpenHumanRunContext {
self.command_environment = env.command_environment.clone().or(self.command_environment);
self.memory_identity = env.memory_identity.clone().or(self.memory_identity);
self.core = env.core.clone().or(self.core);
+ self.native_staged_parts = env.native_staged_parts.clone();
+ self.native_message_id = env.native_message_id.clone();
self.stop_hooks
.extend(env.hooks.stop_hooks().iter().cloned());
self.tool_hooks
@@ -622,6 +630,8 @@ impl OpenHumanRunContext {
child.subagent_usage = Arc::new(Mutex::new(Vec::new()));
child.resolved_route = Arc::new(Mutex::new(None));
child.memory_turn = None;
+ child.native_staged_parts.clear();
+ child.native_message_id = None;
child.response_shape = None;
child
}
diff --git a/crates/openhuman-core/src/agent/turn_env.rs b/crates/openhuman-core/src/agent/turn_env.rs
index abfe59a9c9..72b33fc635 100644
--- a/crates/openhuman-core/src/agent/turn_env.rs
+++ b/crates/openhuman-core/src/agent/turn_env.rs
@@ -27,6 +27,10 @@ use crate::agent::tinyagents::budget::ModelBudget;
/// turn exactly as it ran before any host policy existed.
#[derive(Clone, Default)]
pub struct HostTurnEnv {
+ /// Host-issued media refs belonging only to this external turn.
+ pub(crate) native_staged_parts: Vec<tinychannels_bus::ContentPart>,
+ /// Provider message identity used when binding staged media after commit.
+ pub(crate) native_message_id: Option<String>,
/// Exact child-process environment values supplied by the embedding host.
///
/// The map is carried through the run context so module-backed shell
@@ -76,6 +80,8 @@ pub struct HostTurnEnv {
impl std::fmt::Debug for HostTurnEnv {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("HostTurnEnv")
+ .field("native_staged_parts", &self.native_staged_parts.len())
+ .field("has_native_message_id", &self.native_message_id.is_some())
.field("command_environment", &self.command_environment.is_some())
.field("model_budget", &self.model_budget.is_some())
.field("spawn_depth_limit", &self.spawn_depth_limit)
diff --git a/crates/openhuman-core/src/agent/turn_host.rs b/crates/openhuman-core/src/agent/turn_host.rs
index d2c8b4ec64..ca06c5d047 100644
--- a/crates/openhuman-core/src/agent/turn_host.rs
+++ b/crates/openhuman-core/src/agent/turn_host.rs
@@ -63,6 +63,7 @@ pub(crate) struct AgentTurnRequest {
/// owning persistence boundary. `None` retains the normal text conversion.
pub(crate) message_input: Option<tinyinference_llm::message::Message>,
pub(crate) native_staged_parts: Vec<tinychannels_bus::ContentPart>,
+ pub(crate) native_message_id: Option<String>,
pub(crate) thread_id: Option<String>,
pub(crate) origin: AgentTurnOrigin,
pub(crate) approval: ApprovalTurnContext,
@@ -116,6 +117,8 @@ impl AgentTurnHost {
session.set_run_queue(request.run_queue);
session.set_thread_id(request.thread_id);
let mut host_env = request.host_env;
+ host_env.native_staged_parts = request.native_staged_parts;
+ host_env.native_message_id = request.native_message_id;
host_env.approval = request.approval.clone();
host_env.cancellation = Some(request.cancellation);
host_env.turn_deadline = request
@@ -130,12 +133,10 @@ impl AgentTurnHost {
let scoped_origin = origin.clone();
let message = request.message;
let input = request.message_input;
- let native_staged_parts = request.native_staged_parts;
let approval = request.approval;
let turn = async move {
match input {
Some(input) => {
- session.set_native_staged_parts(native_staged_parts);
session
.run_single_with_approval_and_message(
&message,
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/turn.rs
index 433787165e..c6369b7088 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/turn.rs
@@ -27,6 +27,7 @@ pub(crate) struct HostChannelTurn {
pub(crate) message_input: Option<tinyinference_llm::message::Message>,
/// Exact staged native refs issued by the host for this user turn.
pub(crate) staged_parts: Vec<tinychannels_bus::ContentPart>,
+ pub(crate) staged_message_id: Option<String>,
/// Who asked: the channel's `ExternalChannel` origin.
pub(crate) origin: AgentTurnOrigin,
/// Live progress projected through the compiled channel module.
@@ -56,6 +57,7 @@ pub(crate) async fn run_host_agent_turn(
message,
message_input,
staged_parts,
+ staged_message_id,
origin,
progress,
run_queue,
@@ -109,6 +111,7 @@ pub(crate) async fn run_host_agent_turn(
&imported_history,
legacy_history,
staged_parts,
+ staged_message_id,
)
.await?;
Ok(AgentTurnResponse::with_resolved_route(
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs
index 0d74dc3d23..5acf5d6ef7 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs
@@ -184,6 +184,7 @@ impl TurnHost<QueuedPayload> for NativeHost {
message: request.text.clone(),
message_input: request.payload.native_message_input.clone(),
staged_parts: request.payload.native_staged_parts.clone(),
+ staged_message_id: request.payload.native_message_id.clone(),
origin: trusted.origin.clone(),
progress: Some(agent_progress),
run_queue: Some(queue),
@@ -558,6 +559,7 @@ pub(crate) async fn run(
text: String,
message_input: Option<tinyinference_llm::message::Message>,
staged_parts: Vec<tinychannels_bus::ContentPart>,
+ staged_message_id: Option<String>,
preparation_error: Option<String>,
trusted: Arc<crate::agent::turn_host::TrustedAgentTurn>,
) -> NativeTurnExecution {
@@ -586,6 +588,7 @@ pub(crate) async fn run(
trusted_turn: Some(trusted),
native_message_input: message_input,
native_staged_parts: staged_parts,
+ native_message_id: staged_message_id,
native_preparation_error: preparation_error,
..Default::default()
},
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
index 437634e469..7360ccb06e 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
@@ -374,28 +374,34 @@ pub(crate) async fn process_channel_runtime_message(
}
None => None,
};
- let native_message_input = if typed_envelope_input {
- let Some(host) = selected_host.as_ref() else {
- tracing::warn!("[dispatch] typed native media has no selected host agent");
- return;
- };
+ let native_preparation = if typed_envelope_input {
+ if let Some(host) = selected_host.as_ref() {
match super::native_media::resolve_typed_message(
&ctx,
&host.config,
&envelope,
&prepared_thread_id,
+ &enriched_message,
)
.await
{
Ok(input) => input,
Err(error) => {
- tracing::warn!("[dispatch] typed native media was rejected: {error}");
- return;
+ tracing::warn!("[dispatch] typed native media was rejected safely");
+ Some(Err(error))
}
}
+ } else {
+ Some(Err("native media has no selected host agent".to_owned()))
+ }
} else {
None
};
+ let (native_message_input, native_staged_parts, native_preparation_error) = match native_preparation {
+ Some(Ok(Some(prepared))) => (Some(prepared.message), prepared.staged_parts, None),
+ Some(Ok(None)) | None => (None, Vec::new(), None),
+ Some(Err(error)) => (None, Vec::new(), Some(error)),
+ };
let channel_session = selected_host.as_ref().and_then(|host| {
let account_id = envelope
.channel
@@ -448,6 +454,9 @@ pub(crate) async fn process_channel_runtime_message(
request_id,
enriched_message.clone(),
native_message_input,
+ native_staged_parts,
+ Some(envelope.message_id.clone()),
+ native_preparation_error,
trusted,
)
.await