Skip to content

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

feat(agent): add turn environment for per-turn context

Steven Enamakel74452bfada11
diff --git a/crates/openhuman-core/src/agent/turn_env.rs b/crates/openhuman-core/src/agent/turn_env.rs
index 37681d78fc..e16a84106f 100644
--- a/crates/openhuman-core/src/agent/turn_env.rs
+++ b/crates/openhuman-core/src/agent/turn_env.rs
@@ -42,6 +42,15 @@ pub struct HostTurnEnv {
/// The host's tool belt for this turn is authoritative: tool declarations
/// recorded in a restored transcript must not bring a revoked tool back.
pub fresh_tool_snapshot: bool,
+ /// The approval context of the turn an entry point starts here (chat
+ /// surface, copilot flag, flow run), for the entry points that hand the
+ /// turn its environment as one value (the embed facade, `agent_chat`). The
+ /// session reads it once, for the root turn; it is never copied to
+ /// children ([`OpenHumanRunContext::with_host_env`] leaves it out), which
+ /// take theirs from their parent's run context.
+ ///
+ /// [`OpenHumanRunContext::with_host_env`]: crate::agent::tinyagents::host::OpenHumanRunContext
+ pub approval: crate::security::approval::ApprovalTurnContext,
}
impl std::fmt::Debug for HostTurnEnv {
@@ -54,6 +63,7 @@ impl std::fmt::Debug for HostTurnEnv {
.field("tool_call_limit", &self.tool_call_limit)
.field("hooks_empty", &self.hooks.is_empty())
.field("fresh_tool_snapshot", &self.fresh_tool_snapshot)
+ .field("approval", &self.approval)
.finish()
}
}
diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
index 8f5666d575..127ff43ea6 100644
--- a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
+++ b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
@@ -538,6 +538,7 @@ pub async fn agent_chat_reply_for(
}
// The host environment of this turn (budget, cancellation, deadline, hooks,
// tool-belt authority) rides the session explicitly.
+ let approval = env.host.approval.clone();
agent.set_host_env(env.host);
// Live progress for in-process embedders. `OpenHumanSessionHost::from_config` never
// attaches a sink itself, so there is nothing to clobber here; callers that
@@ -568,7 +569,7 @@ pub async fn agent_chat_reply_for(
// instead of the narrower one it asked for.
let run = crate::agent::turn_origin::with_origin(
effective_agent_chat_origin(),
- agent.run_single(message),
+ agent.run_single_with_approval(message, None, approval),
);
// `untrusted_input` was set on the session above; the turn's run context
// carries it to the security gate, so no extra scope is needed here.