Skip to content

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

feat(agent): add native staged lease support

Steven Enamakel86f4b3d489e4
diff --git a/crates/openhuman-core/src/agent/host_agents.rs b/crates/openhuman-core/src/agent/host_agents.rs
index 4b702c5afc..52cb0453f1 100644
--- a/crates/openhuman-core/src/agent/host_agents.rs
+++ b/crates/openhuman-core/src/agent/host_agents.rs
@@ -105,6 +105,7 @@ impl HostAgent {
imported_history: &[tinyagents_session::transcript::TranscriptMessage],
legacy_history: Option<crate::channels::providers::relay::LegacyHistoryImport>,
staged_parts: Vec<tinychannels_bus::ContentPart>,
+ staged_lease: Option<crate::threads::attachments::NativeStagedLease>,
staged_message_id: Option<String>,
) -> anyhow::Result<String> {
let config = self.config.clone();
@@ -130,6 +131,7 @@ impl HostAgent {
message: message.to_owned(),
message_input,
native_staged_parts: staged_parts,
+ native_staged_lease: staged_lease,
native_message_id: staged_message_id,
thread_id: Some(session_key.to_owned()),
origin,
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 7b3a110055..2e1e9c702e 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -323,6 +323,8 @@ pub struct OpenHumanRunContext {
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>,
+ /// Final-owner cleanup state for root native refs; children never inherit it.
+ pub(crate) native_staged_lease: Option<crate::threads::attachments::NativeStagedLease>,
/// Provider message identity for durable post-commit claims.
pub(crate) native_message_id: Option<String>,
/// Dispatch guard shared by synchronous delegates in this run.
@@ -462,6 +464,7 @@ impl OpenHumanRunContext {
tool_result_artifact_index: None,
attachment_placeholders: Arc::new(Vec::new()),
native_staged_parts: Vec::new(),
+ native_staged_lease: None,
native_message_id: None,
dispatch: None,
task_recency_window: None,
@@ -603,6 +606,7 @@ impl OpenHumanRunContext {
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_staged_lease = env.native_staged_lease.clone();
self.native_message_id = env.native_message_id.clone();
self.stop_hooks
.extend(env.hooks.stop_hooks().iter().cloned());
@@ -631,6 +635,7 @@ impl OpenHumanRunContext {
child.resolved_route = Arc::new(Mutex::new(None));
child.memory_turn = None;
child.native_staged_parts.clear();
+ child.native_staged_lease = None;
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 72b33fc635..524c7a47b1 100644
--- a/crates/openhuman-core/src/agent/turn_env.rs
+++ b/crates/openhuman-core/src/agent/turn_env.rs
@@ -31,6 +31,8 @@ pub struct HostTurnEnv {
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>,
+ /// Root-only cleanup/commit state for the staged native refs above.
+ pub(crate) native_staged_lease: Option<crate::threads::attachments::NativeStagedLease>,
/// Exact child-process environment values supplied by the embedding host.
///
/// The map is carried through the run context so module-backed shell
diff --git a/crates/openhuman-core/src/agent/turn_host.rs b/crates/openhuman-core/src/agent/turn_host.rs
index ca06c5d047..b8150dba08 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_staged_lease: Option<crate::threads::attachments::NativeStagedLease>,
pub(crate) native_message_id: Option<String>,
pub(crate) thread_id: Option<String>,
pub(crate) origin: AgentTurnOrigin,
@@ -118,6 +119,7 @@ impl AgentTurnHost {
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_staged_lease = request.native_staged_lease;
host_env.native_message_id = request.native_message_id;
host_env.approval = request.approval.clone();
host_env.cancellation = Some(request.cancellation);
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 c6369b7088..ec2d2814c8 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_lease: Option<crate::threads::attachments::NativeStagedLease>,
pub(crate) staged_message_id: Option<String>,
/// Who asked: the channel's `ExternalChannel` origin.
pub(crate) origin: AgentTurnOrigin,
@@ -57,6 +58,7 @@ pub(crate) async fn run_host_agent_turn(
message,
message_input,
staged_parts,
+ staged_lease,
staged_message_id,
origin,
progress,
@@ -111,6 +113,7 @@ pub(crate) async fn run_host_agent_turn(
&imported_history,
legacy_history,
staged_parts,
+ staged_lease,
staged_message_id,
)
.await?;