Skip to content

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

feat(tinyagents): add operation and run context types

Steven Enamakel72e58c229292
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/operation_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/operation_context.rs
index 377a8fce3c..f9d9030802 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/operation_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/operation_context.rs
@@ -9,6 +9,9 @@ use tinyagents_definition::SandboxMode;
#[derive(Clone, Debug, Default)]
pub(crate) struct HostOperationContext {
pub(crate) origin: Option<AgentTurnOrigin>,
+ /// Where this run's approvals are surfaced; see
+ /// [`OpenHumanRunContext::approval`](super::OpenHumanRunContext::approval).
+ pub(crate) approval: crate::security::approval::ApprovalTurnContext,
pub(crate) sandbox_mode: Option<SandboxMode>,
/// The agent definition the run's parent execution context belongs to, for
/// tools that act on behalf of the spawning agent when no memory identity
@@ -43,3 +46,19 @@ pub(crate) fn sandbox_mode_for_tool(
.and_then(|context| context.state::<HostOperationContext>())
.and_then(|host| host.sandbox_mode)
}
+
+/// Reads the run's approval context from the explicit tool carrier. Direct tool
+/// dispatch (CLI, JSON-RPC, tests) has none, so a tool called that way sees the
+/// non-interactive default.
+pub(crate) fn approval_for_tool(
+ context: Option<&dyn tinytools::ToolRunContext>,
+) -> crate::security::approval::ApprovalTurnContext {
+ context
+ .and_then(tinytools::ToolRunContext::host_extension)
+ .and_then(|extension| {
+ extension.downcast_ref::<tinyagents_harness::tool::ToolExecutionContext>()
+ })
+ .and_then(|context| context.state::<HostOperationContext>())
+ .map(|host| host.approval.clone())
+ .unwrap_or_default()
+}
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 24ed24171b..a270e83a05 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -281,6 +281,11 @@ pub struct OpenHumanRunContext {
pub max_spawn_depth: Option<usize>,
/// Trust/routing source used by OpenHuman approval and attribution policy.
pub origin: Option<AgentTurnOrigin>,
+ /// Where this turn's approvals are surfaced (chat thread/client), whether
+ /// it is the flow copilot, and which flow run it belongs to. Inline
+ /// children inherit it through [`Self::child`]; a detached child starts
+ /// without it ([`Self::detached_child`]).
+ pub approval: crate::security::approval::ApprovalTurnContext,
/// UI/event progress receiver for this turn tree.
pub progress: Option<Sender<AgentProgress>>,
/// Stop policies evaluated after each model call.
@@ -403,7 +408,7 @@ pub(crate) struct HarnessHostPolicy {
}
pub(crate) use super::operation_context::{
- parent_agent_id_for_tool, sandbox_mode_for_tool, HostOperationContext,
+ approval_for_tool, parent_agent_id_for_tool, sandbox_mode_for_tool, HostOperationContext,
};
/// OpenHuman product values that tools read from the run through
@@ -452,6 +457,7 @@ impl OpenHumanRunContext {
response_shape: None,
max_spawn_depth: None,
origin: None,
+ approval: Default::default(),
progress: None,
stop_hooks: Vec::new(),
tool_hooks: Vec::new(),
@@ -624,6 +630,10 @@ impl OpenHumanRunContext {
/// request that only stopped the interactive turn.
pub fn detached_child(&self) -> Self {
let mut child = self.child();
+ // The chat surface belongs to the turn that started it. A detached
+ // child's parks route through the origin and are marked detached, so
+ // their cards survive the parent turn's end (#5499).
+ child.approval = Default::default();
child.dispatch = None;
child.subagent_usage = Arc::new(Mutex::new(Vec::new()));
child.parent_subagent_usage = None;
@@ -660,6 +670,7 @@ impl OpenHumanRunContext {
};
let host_operations = Arc::new(HostOperationContext {
origin: self.origin.clone(),
+ approval: self.approval.clone(),
sandbox_mode: self.sandbox_mode,
parent_agent_id: self
.parent