Skip to content

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

feat(agent): gate memory and wallet tools behind capability tiers

Steven Enamakel1d92a2b92d67
diff --git a/crates/openhuman-core/src/agent/plan_review/tool.rs b/crates/openhuman-core/src/agent/plan_review/tool.rs
index 774822d3f8..d196803145 100644
--- a/crates/openhuman-core/src/agent/plan_review/tool.rs
+++ b/crates/openhuman-core/src/agent/plan_review/tool.rs
@@ -119,7 +119,8 @@ impl RequestPlanReviewTool {
// Only interactive (WebChat) turns have a human to review the plan.
// Anything else auto-approves so background automation isn't wedged.
- let origin = turn_origin::current().unwrap_or(AgentTurnOrigin::Unknown);
+ let origin = crate::agent::tinyagents::host::run_context::turn_origin_for_tool(context)
+ .unwrap_or(AgentTurnOrigin::Unknown);
if !matches!(origin, AgentTurnOrigin::WebChat { .. }) {
tracing::debug!(
origin = ?origin,
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/tool_rules.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/tool_rules.rs
index 79691e3c82..efac2e4726 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session/tool_rules.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/tool_rules.rs
@@ -62,7 +62,10 @@ impl OpenHumanTurnPrelude {
/// Records the user text a turn begins with, for its user-side effects.
pub(super) fn begin_user_effects(&self, request: &SessionTurnRequest) {
let user_text =
- crate::agent::turn_origin::current_is_user_authored().then(|| request.input.text());
+ crate::core::runtime::DispatchCtx::ambient_turn()
+ .turn_origin()
+ .is_some_and(|origin| origin.is_user_authored())
+ .then(|| request.input.text());
self.mutable
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
diff --git a/crates/openhuman-core/src/flows/memory_tools.rs b/crates/openhuman-core/src/flows/memory_tools.rs
index 7d02ec18a0..c395b8e6bb 100644
--- a/crates/openhuman-core/src/flows/memory_tools.rs
+++ b/crates/openhuman-core/src/flows/memory_tools.rs
@@ -61,12 +61,12 @@ const FLOW_KEY_INFIX: &str = ":key:";
/// by a prompt-injected caller. Writes refuse when this is `None`; the
/// read-only recall falls back to the argument (cross-flow reads are already
/// open by design, so an argument grants no new read privilege).
-fn trusted_flow_id() -> Option<String> {
- match turn_origin::current() {
+fn trusted_flow_id(origin: Option<&AgentTurnOrigin>) -> Option<String> {
+ match origin {
Some(AgentTurnOrigin::TrustedAutomation {
job_id,
source: TrustedAutomationSource::Workflow { .. },
- }) => Some(job_id),
+ }) => Some(job_id.clone()),
_ => None,
}
}
@@ -294,6 +294,17 @@ impl Tool for FlowMemoryRecallTool {
}
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
+ self.execute_with_context(args, tinytools::ToolCallOptions::default(), None)
+ .await
+ }
+
+ async fn execute_with_context(
+ &self,
+ args: serde_json::Value,
+ _options: tinytools::ToolCallOptions,
+ tool_context: Option<&dyn tinytools::ToolRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ let origin = crate::agent::tinyagents::host::run_context::turn_origin_for_tool(tool_context);
let query = match args.get("query").and_then(|v| v.as_str()) {
Some(q) => q.trim(),
None => return Ok(ToolResult::error("Missing 'query' parameter".to_string())),
@@ -305,7 +316,7 @@ impl Tool for FlowMemoryRecallTool {
// SECURITY: inside a running flow the trusted origin wins over the
// model-supplied `flow_id` argument.
- let flow_id = match trusted_flow_id() {
+ let flow_id = match trusted_flow_id(origin.as_ref()) {
Some(trusted_id) => {
tracing::debug!(
target: "flows",
@@ -429,6 +440,17 @@ impl Tool for FlowMemoryRememberTool {
}
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
+ self.execute_with_context(args, tinytools::ToolCallOptions::default(), None)
+ .await
+ }
+
+ async fn execute_with_context(
+ &self,
+ args: serde_json::Value,
+ _options: tinytools::ToolCallOptions,
+ tool_context: Option<&dyn tinytools::ToolRunContext>,
+ ) -> anyhow::Result<ToolResult> {
+ let origin = crate::agent::tinyagents::host::run_context::turn_origin_for_tool(tool_context);
let flow_id_arg = args.get("flow_id").and_then(|v| v.as_str());
let Some(key) = args.get("key").and_then(|v| v.as_str()) else {
return Ok(ToolResult::error("Missing 'key' parameter".to_string()));
@@ -447,7 +469,7 @@ impl Tool for FlowMemoryRememberTool {
// SECURITY (T-M2): the flow comes from the trusted run origin only;
// outside a workflow run the write is refused.
- let Some(flow_id) = trusted_flow_id() else {
+ let Some(flow_id) = trusted_flow_id(origin.as_ref()) else {
tracing::warn!(
target: "flows",
requested_flow_id_chars = flow_id_arg.map_or(0, str::len),
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs b/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
index 298e4dd8d1..e090c45ff3 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
@@ -437,7 +437,9 @@ impl OpenHumanAgentRunner {
// Cancellation: the run_registry token aborts the engine future, and the
// inner turn drops with it (task-local scope unwinds cleanly).
use crate::agent::turn_origin;
- let escalated_origin = escalated_origin_for_nested_harness(turn_origin::current());
+ let escalated_origin = escalated_origin_for_nested_harness(
+ crate::core::runtime::DispatchCtx::ambient_turn().turn_origin(),
+ );
if let Some(ref escalated) = escalated_origin {
tracing::debug!(
target: "flows",
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/tier.rs b/crates/openhuman-core/src/flows/tinyflows/caps/tier.rs
index 5a2ac3f3bd..5aa708077f 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/tier.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/tier.rs
@@ -104,7 +104,10 @@ pub(crate) async fn gate_call_for_tier(
return (crate::security::approval::GateOutcome::Allow, None);
};
- match escalated_origin_for_prompt(tier_decision, turn_origin::current()) {
+ match escalated_origin_for_prompt(
+ tier_decision,
+ crate::core::runtime::DispatchCtx::ambient_turn().turn_origin(),
+ ) {
Some(escalated) => {
tracing::debug!(
target: "flows",
diff --git a/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs b/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs
index 5d1db2d475..737c528a41 100644
--- a/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs
@@ -82,7 +82,7 @@ impl OpenHumanMemory {
/// so a `scope: "flow"` node can never be pointed at another flow's
/// namespace by a crafted `=`-binding.
fn trusted_flow_id(&self) -> Result<String> {
- match turn_origin::current() {
+ match crate::core::runtime::DispatchCtx::ambient_turn().turn_origin() {
Some(AgentTurnOrigin::TrustedAutomation {
job_id,
source: TrustedAutomationSource::Workflow { .. },
diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/turn_guards.rs b/crates/openhuman-core/src/inference/host_runtime/ops/turn_guards.rs
index 16ee891c48..b911df6406 100644
--- a/crates/openhuman-core/src/inference/host_runtime/ops/turn_guards.rs
+++ b/crates/openhuman-core/src/inference/host_runtime/ops/turn_guards.rs
@@ -131,6 +131,7 @@ pub(super) fn grant_turn_cwd(config: &mut Config, root: &std::path::Path) {
/// reads `false` for it and the conversation autosave would silently drop a
/// real user message.
pub(super) fn effective_agent_chat_origin() -> crate::agent::turn_origin::AgentTurnOrigin {
- crate::agent::turn_origin::current()
+ crate::core::runtime::DispatchCtx::ambient_turn()
+ .turn_origin()
.unwrap_or(crate::agent::turn_origin::AgentTurnOrigin::DirectChat)
}
diff --git a/crates/openhuman-core/src/modules/wallet_host.rs b/crates/openhuman-core/src/modules/wallet_host.rs
index ea0cfb0d72..9efb502c92 100644
--- a/crates/openhuman-core/src/modules/wallet_host.rs
+++ b/crates/openhuman-core/src/modules/wallet_host.rs
@@ -698,7 +698,10 @@ impl WalletHost {
request: AuthorizeX402PaymentRequest,
) -> tinybus::Result<HostResponse> {
let owner_matches =
- x402_request_owner_matches(&request, crate::agent::turn_origin::current().as_ref());
+ x402_request_owner_matches(&request, crate::core::runtime::DispatchCtx::ambient_turn()
+ .turn_origin()
+ .as_ref(),
+ );
let approved = if owner_matches {
if let Some(gate) = crate::security::approval::ApprovalGate::try_global() {
matches!(