Skip to content

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

fix(embed): keep managed runtime paths within the turn environment

Steven Enamakel35ffc9db90cb
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rs
index 90792af54b..f91c2edb14 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/embedder_hooks.rs
@@ -31,6 +31,37 @@ impl EmbedderToolHooksMiddleware {
}
}
+fn hook_identity(
+ data: &crate::agent::tinyagents::host::OpenHumanRunContext,
+) -> (Option<String>, Option<String>, Option<std::path::PathBuf>) {
+ let session_id = data
+ .thread_id
+ .clone()
+ .or_else(|| data.parent.as_ref().map(|parent| parent.session_id.clone()));
+ let agent_id = data
+ .parent
+ .as_ref()
+ .map(|parent| parent.agent_definition_id.clone());
+ let cwd = data
+ .workspace
+ .as_ref()
+ .map(|workspace| workspace.root.clone())
+ .or_else(|| {
+ data.parent.as_ref().and_then(|parent| {
+ parent
+ .workspace_descriptor
+ .as_ref()
+ .map(|workspace| workspace.root.clone())
+ })
+ })
+ .or_else(|| {
+ crate::core::runtime::CoreContext::with_current_embedder_config(|config| {
+ config.action_dir.clone()
+ })
+ });
+ (session_id, agent_id, cwd)
+}
+
#[async_trait]
impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
for EmbedderToolHooksMiddleware
@@ -45,6 +76,7 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
_state: &(),
call: &mut TaToolCall,
) -> TaResult<()> {
+ let (session_id, agent_id, cwd) = hook_identity(&ctx.data);
let mut context = crate::agent::hooks::ToolHookContext {
event: crate::agent::hooks::ToolHookEvent::PreToolUse,
call_id: call.id.clone(),
@@ -54,32 +86,9 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
duration_ms: None,
output: None,
error: None,
- session_id: ctx
- .data
- .thread_id
- .clone()
- .or_else(|| ctx.data.parent.as_ref().map(|p| p.session_id.clone())),
- agent_id: ctx
- .data
- .parent
- .as_ref()
- .map(|p| p.agent_definition_id.clone()),
- cwd: ctx
- .data
- .workspace
- .as_ref()
- .map(|w| w.root.clone())
- .or_else(|| {
- ctx.data
- .parent
- .as_ref()
- .and_then(|p| p.workspace_descriptor.as_ref().map(|w| w.root.clone()))
- })
- .or_else(|| {
- crate::core::runtime::CoreContext::with_current_embedder_config(|config| {
- config.action_dir.clone()
- })
- }),
+ session_id,
+ agent_id,
+ cwd,
};
for hook in &self.hooks {
match hook.before_tool_decision(&context).await {
@@ -148,6 +157,7 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
_state: &(),
call: &TaToolCall,
) -> TaResult<()> {
+ let (session_id, agent_id, cwd) = hook_identity(&ctx.data);
let context = crate::agent::hooks::ToolHookContext {
event: crate::agent::hooks::ToolHookEvent::PreToolUse,
call_id: call.id.clone(),
@@ -157,32 +167,9 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
duration_ms: None,
output: None,
error: None,
- session_id: ctx
- .data
- .thread_id
- .clone()
- .or_else(|| ctx.data.parent.as_ref().map(|p| p.session_id.clone())),
- agent_id: ctx
- .data
- .parent
- .as_ref()
- .map(|p| p.agent_definition_id.clone()),
- cwd: ctx
- .data
- .workspace
- .as_ref()
- .map(|w| w.root.clone())
- .or_else(|| {
- ctx.data
- .parent
- .as_ref()
- .and_then(|p| p.workspace_descriptor.as_ref().map(|w| w.root.clone()))
- })
- .or_else(|| {
- crate::core::runtime::CoreContext::with_current_embedder_config(|config| {
- config.action_dir.clone()
- })
- }),
+ session_id,
+ agent_id,
+ cwd,
};
for hook in &self.hooks {
let refusal = match hook.before_tool_decision(&context).await {
@@ -226,6 +213,7 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
.expect("embedder tool-hook arguments poisoned")
.remove(&call_id)
.unwrap_or(serde_json::Value::Null);
+ let (session_id, agent_id, cwd) = hook_identity(&ctx.data);
let context = crate::agent::hooks::ToolHookContext {
event: crate::agent::hooks::ToolHookEvent::PostToolUse,
call_id,
@@ -239,32 +227,9 @@ impl Middleware<(), crate::agent::tinyagents::host::OpenHumanRunContext>
error: result
.is_error
.then(|| crate::agent::tinyagents::middleware::tool_result_text(result)),
- session_id: ctx
- .data
- .thread_id
- .clone()
- .or_else(|| ctx.data.parent.as_ref().map(|p| p.session_id.clone())),
- agent_id: ctx
- .data
- .parent
- .as_ref()
- .map(|p| p.agent_definition_id.clone()),
- cwd: ctx
- .data
- .workspace
- .as_ref()
- .map(|w| w.root.clone())
- .or_else(|| {
- ctx.data
- .parent
- .as_ref()
- .and_then(|p| p.workspace_descriptor.as_ref().map(|w| w.root.clone()))
- })
- .or_else(|| {
- crate::core::runtime::CoreContext::with_current_embedder_config(|config| {
- config.action_dir.clone()
- })
- }),
+ session_id,
+ agent_id,
+ cwd,
};
for hook in &self.hooks {
// Text a hook returns is appended to the result the model reads —
diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rs
index fa01b5648c..d18e96635d 100644
--- a/crates/openhuman-core/src/tools/impl/system/shell.rs
+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs
@@ -662,7 +662,7 @@ impl ShellTool {
} else {
Some(prepend_path_dirs(
prepend_dirs.iter().map(|p| p.as_path()),
- &std::env::var("PATH").unwrap_or_default(),
+ &crate::tools::timeout::CommandEnvironment::var("PATH").unwrap_or_default(),
))
}
}
diff --git a/crates/openhuman-core/src/tools/impl/system/shell_tests_runtime_and_sandbox_tests.rs b/crates/openhuman-core/src/tools/impl/system/shell_tests_runtime_and_sandbox_tests.rs
index ef4fc9bedc..e52242571c 100644
--- a/crates/openhuman-core/src/tools/impl/system/shell_tests_runtime_and_sandbox_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/system/shell_tests_runtime_and_sandbox_tests.rs
@@ -313,3 +313,38 @@ fn managed_path_restoration_preserves_cmd_syntax_and_unmanaged_commands() {
unmanaged_command
);
}
+
+#[cfg(unix)]
+#[tokio::test]
+async fn managed_python_path_keeps_the_turn_path_without_daemon_inheritance() {
+ use crate::runtime::python::{PythonSource, ResolvedPython};
+ use crate::tools::timeout::CommandEnvironment;
+ let python = Arc::new(PythonBootstrap::new(Arc::new(
+ crate::config::Config::default(),
+ )));
+ python.cache_for_test(ResolvedPython {
+ bin_dir: PathBuf::from("/managed/python/bin"),
+ python_bin: PathBuf::from("/managed/python/bin/python3"),
+ version: "3.12.4".into(),
+ source: PythonSource::Managed,
+ });
+ let tool = ShellTool::with_language_bootstraps(
+ test_security(AutonomyLevel::Full),
+ test_runtime(),
+ test_audit(),
+ None,
+ Some(python),
+ );
+ let environment = CommandEnvironment::new([("PATH".into(), "/turn/bin".into())]);
+ let path = environment
+ .scope(tool.runtime_path_for_command("python3 -V"))
+ .await
+ .unwrap();
+ assert_eq!(path, "/managed/python/bin:/turn/bin");
+ let empty = CommandEnvironment::new(Vec::<(String, String)>::new());
+ let path = empty
+ .scope(tool.runtime_path_for_command("python3 -V"))
+ .await
+ .unwrap();
+ assert_eq!(path, "/managed/python/bin");
+}
diff --git a/crates/openhuman-embed/tests/turn_tools.rs b/crates/openhuman-embed/tests/turn_tools.rs
index b1543f26e0..021ad8668f 100644
--- a/crates/openhuman-embed/tests/turn_tools.rs
+++ b/crates/openhuman-embed/tests/turn_tools.rs
@@ -1,4 +1,4 @@
-//! A host can await its own approval UI inline without polling the core.
+//! Per-turn host-tool belts replace agent tools without leaking into other turns.
mod common;