The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(subagent): propagate operation context to subagent runs
Steven Enamakel0e223f31095c
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rsindex d085ffd56b..24c6d82ed9 100644--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs@@ -234,16 +234,9 @@ pub(crate) async fn run_subagent_direct(max_depth,})?;options.run_context.spawn_depth = attempted_depth;- // The sub-agent acts on memory as a child of its parent: same team,- // its own definition. Explicit on the run, never an ambient scope.- options.run_context.memory_identity = Some(- options- .run_context- .memory_identity- .clone()- .unwrap_or_default()- .child(&definition.id),- );+ // Acts on memory as a child of its parent: same team, own definition.+ let acting = options.run_context.memory_identity.take().unwrap_or_default();+ options.run_context.memory_identity = Some(acting.child(&definition.id));// Runtime spawn-hierarchy (tier) gate — defense-in-depth alongside the// depth gate above. The loader validates *declared* `subagents` pairs@@ -331,17 +324,14 @@ pub(crate) async fn run_subagent_direct(}let run_result = Box::pin(with_run_depth(RunDepth { depth: attempted_depth, max_depth }, async {with_file_state_agent_id(task_id.clone(), async {- async {- Box::pin(run_typed_mode(- definition,- task_prompt,- &options,- &parent_for_subagent,- &task_id,- &loaded_config,- ))- .await- }+ Box::pin(run_typed_mode(+ definition,+ task_prompt,+ &options,+ &parent_for_subagent,+ &task_id,+ &loaded_config,+ )).await}).awaitdiff --git a/crates/openhuman-core/src/agent/tinyagents/host/operation_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/operation_context.rsindex 01782c21f2..903eda75f7 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/operation_context.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/operation_context.rs@@ -95,20 +95,3 @@ pub(crate) fn tool_context_with_approval(tinyagents_harness::ids::CallId::new("approval-test-call"),)}--/// A tool execution context for a run that acts on memory as `identity`: what-/// the harness hands a tool dispatched inside that run.-#[cfg(test)]-pub(crate) fn tool_context_with_memory_identity(- identity: crate::memory::scope::MemoryIdentity,-) -> tinyagents_harness::tool::ToolExecutionContext {- let mut host = super::OpenHumanRunContext::new();- host.memory_identity = Some(identity);- let run = host.into_tinyagents(tinyagents_harness::context::RunConfig::new(- "memory-identity-test",- ));- tinyagents_harness::tool::ToolExecutionContext::from_run_context(- &run,- tinyagents_harness::ids::CallId::new("memory-identity-test-call"),- )-}diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rsindex a2829b82b0..5031ff4fe1 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs@@ -307,12 +307,9 @@ pub struct OpenHumanRunContext {pub parent: Option<ParentExecutionContext>,/// Context-preparation sources already consumed in this turn.pub prepared_context_sources: Arc<Vec<AgentContextPreparedSource>>,- /// Who this run acts as on memory: its agent definition and team. Set by- /// the entry point that starts the run (`MemoryIdentity::root().child(id)`- /// for a top-level turn, `MemoryIdentity::team_member` for a team member)- /// and derived with `child(definition id)` for each sub-agent; read by the- /// memory tool and the turn's memory hooks. `None` means the host acts for- /// itself (the root identity).+ /// Who this run acts as on memory (agent definition and team): set by the+ /// entry point, narrowed with `child(id)` per sub-agent, read by the memory+ /// tool and hooks. `None` is the root identity.pub memory_identity: Option<crate::memory::scope::MemoryIdentity>,/// File-state identity used to detect stale parent reads after child writes.pub file_state_agent_id: Option<String>,@@ -419,9 +416,7 @@ pub(crate) use super::operation_context::{HostOperationContext,};#[cfg(test)]-pub(crate) use super::operation_context::{- tool_context_with_approval, tool_context_with_memory_identity,-};+pub(crate) use super::operation_context::tool_context_with_approval;/// OpenHuman product values that tools read from the run through/// `ToolExecutionContext::host::<OpenHumanRunExt>()`, installed bydiff --git a/crates/openhuman-core/src/memory/tools_agent_tests.rs b/crates/openhuman-core/src/memory/tools_agent_tests.rsindex 1c577e7f17..49a022c2c1 100644--- a/crates/openhuman-core/src/memory/tools_agent_tests.rs+++ b/crates/openhuman-core/src/memory/tools_agent_tests.rs@@ -52,3 +52,37 @@ async fn turn_citations_stay_with_the_agent_that_recorded_them() {["beta-cite"]);}++/// A tool context for a run that acts on memory as `identity`.+fn tool_context_acting_as(+ identity: crate::memory::scope::MemoryIdentity,+) -> tinyagents_harness::tool::ToolExecutionContext {+ let mut host = crate::agent::tinyagents::host::OpenHumanRunContext::new();+ host.memory_identity = Some(identity);+ let run = host.into_tinyagents(tinyagents_harness::context::RunConfig::new("identity-test"));+ tinyagents_harness::tool::ToolExecutionContext::from_run_context(+ &run,+ tinyagents_harness::ids::CallId::new("identity-test-call"),+ )+}++/// The memory tool acts as the identity its run carries, not as whatever task+/// it happens to be polled on: a team member's learnings land in the team's+/// layout under the member's own memory agent id.+#[test]+fn gather_acts_as_the_identity_the_run_carries() {+ let config = Config::default();+ let context = tool_context_acting_as(crate::memory::scope::MemoryIdentity::team_member("acme", "scout"));+ let facts = CallFacts::gather(&config, Some(&context));+ assert_eq!(facts.agent_id.as_deref(), Some("scout"));+ assert_eq!(facts.reach, Reach::subtree("team:acme".parse().unwrap()));+ assert_eq!(facts.namespace.to_string(), "team:acme");++ // A run that carries none, and direct dispatch, act as the root.+ let bare = CallFacts::gather(&config, None);+ assert_eq!(+ bare.agent_id.as_deref(),+ Some(super::super::scope::DEFAULT_AGENT_ID)+ );+ assert!(bare.reach.at.is_root());+}diff --git a/crates/openhuman-core/src/memory/tools_tests.rs b/crates/openhuman-core/src/memory/tools_tests.rsindex 83fddae041..94e7c4f0cb 100644--- a/crates/openhuman-core/src/memory/tools_tests.rs+++ b/crates/openhuman-core/src/memory/tools_tests.rs@@ -732,26 +732,3 @@ async fn memory_activity_carries_the_calling_turns_chat() {);assert_eq!(seen["unrouted marker question"], (None, None));}--/// The memory tool acts as the identity its run carries, not as whatever task-/// it happens to be polled on: a team member's learnings land in the team's-/// layout under the member's own memory agent id.-#[test]-fn gather_acts_as_the_identity_the_run_carries() {- let config = Config::default();- let context = crate::agent::tinyagents::host::run_context::tool_context_with_memory_identity(- MemoryIdentity::team_member("acme", "scout"),- );- let facts = CallFacts::gather(&config, Some(&context));- assert_eq!(facts.agent_id.as_deref(), Some("scout"));- assert_eq!(facts.reach, Reach::subtree("team:acme".parse().unwrap()));- assert_eq!(facts.namespace.to_string(), "team:acme");-- // A run that carries none, and direct dispatch, act as the root.- let bare = CallFacts::gather(&config, None);- assert_eq!(- bare.agent_id.as_deref(),- Some(super::super::scope::DEFAULT_AGENT_ID)- );- assert!(bare.reach.at.is_root());-}