Skip to content

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

refactor(tinyflows): thread memory adapter through capability constructors

Steven Enamakelec712145fde0
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs b/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
index 6c011a21f7..cb73dc8938 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
@@ -452,7 +452,7 @@ impl OpenHumanAgentRunner {
// inner turn drops with it (task-local scope unwinds cleanly).
use crate::agent::turn_origin;
let escalated_origin = escalated_origin_for_nested_harness(
- crate::core::runtime::DispatchCtx::ambient_turn().turn_origin(),
+ self.ctx.turn_origin(),
);
if let Some(ref escalated) = escalated_origin {
tracing::debug!(
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/code.rs b/crates/openhuman-core/src/flows/tinyflows/caps/code.rs
index a7f1902078..b0674d722a 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/code.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/code.rs
@@ -74,6 +74,7 @@ impl CodeRunner for OpenHumanCode {
let summary = crate::security::approval::summarize_action("flows_code", &action);
let redacted = crate::security::approval::redact_args(&action);
let (gate_outcome, audit_id) = gate_call_for_tier(
+ &self.ctx,
&self.approval,
tier_decision,
"flows_code",
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/http.rs b/crates/openhuman-core/src/flows/tinyflows/caps/http.rs
index f132457efb..58ae59c39a 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/http.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/http.rs
@@ -186,7 +186,15 @@ impl HttpClient for OpenHumanHttp {
let summary = crate::security::approval::summarize_action(TOOL_NAME, &request);
let redacted = crate::security::approval::redact_args(&request);
let (outcome, audit_id) =
- gate_call_for_tier(&self.approval, tier_decision, TOOL_NAME, &summary, redacted).await;
+ gate_call_for_tier(
+ &self.ctx,
+ &self.approval,
+ tier_decision,
+ TOOL_NAME,
+ &summary,
+ redacted,
+ )
+ .await;
if let crate::security::approval::GateOutcome::Deny { reason } = outcome {
return Err(EngineError::Capability(reason));
}
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/ops.rs b/crates/openhuman-core/src/flows/tinyflows/caps/ops.rs
index 70561e5db3..825befc7e3 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/ops.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/ops.rs
@@ -691,6 +691,7 @@ pub fn build_capabilities(
approvals: None,
memory: Some(Arc::new(
crate::flows::tinyflows::memory_adapter::OpenHumanMemory {
+ ctx: ctx.clone(),
config: config.clone(),
security,
approval,
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/tier.rs b/crates/openhuman-core/src/flows/tinyflows/caps/tier.rs
index 5aa708077f..3b1d4f80c7 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/tier.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/tier.rs
@@ -92,6 +92,7 @@ pub(crate) fn enforce_node_tier_gate(
/// `intercept_audited`, forcing the real parking/HITL flow. `GateDecision::Allow`
/// (and any other origin shape) passes through unchanged — existing behavior.
pub(crate) async fn gate_call_for_tier(
+ ctx: &crate::core::runtime::DispatchCtx,
approval: &crate::security::approval::ApprovalTurnContext,
tier_decision: GateDecision,
tool_name: &str,
@@ -106,7 +107,7 @@ pub(crate) async fn gate_call_for_tier(
match escalated_origin_for_prompt(
tier_decision,
- crate::core::runtime::DispatchCtx::ambient_turn().turn_origin(),
+ ctx.turn_origin(),
) {
Some(escalated) => {
tracing::debug!(
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio.rs b/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio.rs
index bf1f7bc3ec..1f9ceb8d70 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio.rs
@@ -172,7 +172,14 @@ impl ToolBackend for ComposioToolBackend {
let (outcome, audit_id) = if tier_decision == GateDecision::Allow {
(crate::security::approval::GateOutcome::Allow, None)
} else {
- super::super::gate_call_for_tier(ctx.approval, tier_decision, slug, &summary, redacted)
+ super::super::gate_call_for_tier(
+ ctx.dispatch,
+ ctx.approval,
+ tier_decision,
+ slug,
+ &summary,
+ redacted,
+ )
.await
};
if let crate::security::approval::GateOutcome::Deny { reason } = outcome {
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/tools/native.rs b/crates/openhuman-core/src/flows/tinyflows/caps/tools/native.rs
index e7ca8050ed..1a38e7bba3 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/tools/native.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/tools/native.rs
@@ -49,6 +49,7 @@ impl ToolBackend for NativeToolBackend {
let summary = crate::security::approval::summarize_action(tool_name, &args);
let redacted = crate::security::approval::redact_args(&args);
let (outcome, audit_id) = super::super::gate_call_for_tier(
+ ctx.dispatch,
ctx.approval,
tier_decision,
tool_name,
diff --git a/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs b/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs
index 26386cb25d..bcf0b3238a 100644
--- a/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs
@@ -67,6 +67,8 @@ const LOG_PREFIX: &str = "[memory-node-host]";
/// security contract; see [`super::caps::OpenHumanAgentRunner`] for the
/// sibling adapter this one's tier-gate wiring mirrors.
pub struct OpenHumanMemory {
+ /// The context the run acts under; carries the run's trusted turn origin.
+ pub(crate) ctx: crate::core::runtime::DispatchCtx,
pub(crate) config: Arc<Config>,
pub(crate) security: Arc<SecurityPolicy>,
/// The run's approval context (flow run correlation).
@@ -84,7 +86,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 crate::core::runtime::DispatchCtx::ambient_turn().turn_origin() {
+ match self.ctx.turn_origin() {
Some(AgentTurnOrigin::TrustedAutomation {
job_id,
source: TrustedAutomationSource::Workflow { .. },
@@ -147,6 +149,7 @@ impl OpenHumanMemory {
let summary = summarize_action(&tool_name, action);
let redacted = redact_args(action);
let (outcome, audit_id) = gate_call_for_tier(
+ &self.ctx,
&self.approval,
tier_decision,
&tool_name,