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 context to agent runs

Steven Enamakel28cafa9f5e2c
diff --git a/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime.rs b/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime.rs
index 768b444abd..f206b7c98b 100644
--- a/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime.rs
+++ b/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime.rs
@@ -232,6 +232,8 @@ async fn run_member_loop(
// The member acts on memory as itself within the team: its node is
// `team:<team>/agent:<agent>`, so members share the team's node and
// never read each other's.
+ // The member acts on memory as itself, in its team: it rides the parent's
+ // host environment, so every run started from that parent keeps it.
let identity = crate::memory::scope::MemoryIdentity::team_member(team_id, agent_id);
let member_turn = with_root_parent(
parent_override,
@@ -239,7 +241,8 @@ async fn run_member_loop(
"agent_team_runtime",
"team",
"teamrun",
- |parent| async {
+ |mut parent| async {
+ parent.host_env.memory_identity = Some(identity);
drive_member(
config,
team_id,
@@ -253,7 +256,7 @@ async fn run_member_loop(
.await
},
);
- let outcome = crate::memory::scope::within(identity, Box::pin(member_turn))
+ let outcome = Box::pin(member_turn)
.await
// Flatten: outer Err = root-parent build failure, inner = drive_member result.
.unwrap_or_else(Err);
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 221b667baa..10245d1741 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -596,6 +596,7 @@ impl OpenHumanRunContext {
}
self.turn_deadline = env.turn_deadline.or(self.turn_deadline);
self.tool_call_limit = env.tool_call_limit.or(self.tool_call_limit);
+ self.memory_identity = env.memory_identity.clone().or(self.memory_identity);
self.stop_hooks
.extend(env.hooks.stop_hooks().iter().cloned());
self.tool_hooks
diff --git a/crates/openhuman-core/src/agent/turn_env.rs b/crates/openhuman-core/src/agent/turn_env.rs
index e16a84106f..95fce2f79b 100644
--- a/crates/openhuman-core/src/agent/turn_env.rs
+++ b/crates/openhuman-core/src/agent/turn_env.rs
@@ -51,6 +51,12 @@ pub struct HostTurnEnv {
///
/// [`OpenHumanRunContext::with_host_env`]: crate::agent::tinyagents::host::OpenHumanRunContext
pub approval: crate::security::approval::ApprovalTurnContext,
+ /// Who the runs this environment starts act as on memory, when the entry
+ /// point knows more than "the host itself": a team member's identity, which
+ /// a turn or sub-agent narrows with `child(<definition id>)`. `None` is the
+ /// root identity. Unlike `approval` it follows delegation, so runs started
+ /// from a parent snapshot keep the parent's team.
+ pub memory_identity: Option<crate::memory::scope::MemoryIdentity>,
}
impl std::fmt::Debug for HostTurnEnv {
@@ -64,6 +70,7 @@ impl std::fmt::Debug for HostTurnEnv {
.field("hooks_empty", &self.hooks.is_empty())
.field("fresh_tool_snapshot", &self.fresh_tool_snapshot)
.field("approval", &self.approval)
+ .field("memory_identity", &self.memory_identity)
.finish()
}
}