Skip to content

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

feat(agent): each turn owns the shell commands it leaves running

sanil-23c59ec8bd203a
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/operation_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/operation_context.rs
index eaa9ea797f..8374a55964 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/operation_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/operation_context.rs
@@ -18,6 +18,8 @@ pub struct OpenHumanRunExt {
pub task_recency_window: Option<Duration>,
/// Explicit child-process environment supplied by the embedding host.
pub command_environment: Option<Arc<std::collections::BTreeMap<String, String>>>,
+ /// The run's shell commands left running past their yield point.
+ pub(crate) shell_processes: Option<Arc<crate::sandbox::shell_processes::ShellProcesses>>,
}
impl std::fmt::Debug for OpenHumanRunExt {
@@ -34,10 +36,26 @@ impl OpenHumanRunExt {
Self {
task_recency_window: context.task_recency_window,
command_environment: context.command_environment.clone(),
+ shell_processes: Some(context.shell_processes.clone()),
}
}
}
+/// The run's registry of shell commands left running past their yield
+/// point. Direct tool dispatch (CLI, JSON-RPC, tests) has none, so its shell
+/// calls always wait for the command to end.
+pub(crate) fn shell_processes_for_tool(
+ context: Option<&dyn tinytools::ToolRunContext>,
+) -> Option<Arc<crate::sandbox::shell_processes::ShellProcesses>> {
+ context
+ .and_then(tinytools::ToolRunContext::host_extension)
+ .and_then(|extension| {
+ extension.downcast_ref::<tinyagents_harness::tool::ToolExecutionContext>()
+ })
+ .and_then(|context| context.host::<OpenHumanRunExt>())
+ .and_then(|ext| ext.shell_processes.clone())
+}
+
/// Reads the explicit command environment from a tool's run context.
pub(crate) fn command_environment_for_tool(
context: Option<&dyn tinytools::ToolRunContext>,
@@ -216,3 +234,12 @@ pub(crate) fn tool_context_with_approval(
tinyagents_harness::ids::CallId::new("approval-test-call"),
)
}
+
+/// One turn's run, for tests that make several tool calls in the same turn:
+/// each `ToolExecutionContext::from_run_context(&run, …)` shares its state.
+#[cfg(test)]
+pub(crate) fn test_turn_run() -> tinyagents_harness::context::RunContext<super::OpenHumanRunContext>
+{
+ super::OpenHumanRunContext::new()
+ .into_tinyagents(tinyagents_harness::context::RunConfig::new("turn-test"))
+}
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 319a36f34b..5d51e64404 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -301,6 +301,10 @@ pub struct OpenHumanRunContext {
/// binding the compaction summarizer recalls under. A child run has its
/// own and does not inherit it.
pub(crate) memory_turn: Option<Arc<crate::memory::lifecycle::hooks::MemoryTurn>>,
+ /// Shell commands this turn left running past their yield point
+ /// (`sandbox::shell_processes`). Each run, child runs included, has its
+ /// own; dropping the last copy at the end of the run stops them.
+ pub(crate) shell_processes: Arc<crate::sandbox::shell_processes::ShellProcesses>,
}
/// The host callbacks and caps a turn's harness assembly installs, taken from
@@ -315,14 +319,15 @@ pub(crate) struct HarnessHostPolicy {
pub(crate) tool_call_cap: Option<usize>,
}
-#[cfg(test)]
-pub(crate) use super::operation_context::tool_context_with_approval;
pub use super::operation_context::{approval_for_tool, OpenHumanRunExt};
pub(crate) use super::operation_context::{
command_environment_for_tool, dispatch_ctx_for_tool, memory_identity_for_tool,
memory_in_prompt_for_tool, parent_agent_id_for_tool, sandbox_mode_for_tool,
- task_recency_window_for_tool, turn_origin_for_tool, HostOperationContext,
+ shell_processes_for_tool, task_recency_window_for_tool, turn_origin_for_tool,
+ HostOperationContext,
};
+#[cfg(test)]
+pub(crate) use super::operation_context::{test_turn_run, tool_context_with_approval};
impl Default for OpenHumanRunContext {
fn default() -> Self {
@@ -381,6 +386,7 @@ impl OpenHumanRunContext {
required_output: None,
tool_dialect: tinyagents_harness::config::ToolDispatcher::Auto,
memory_turn: None,
+ shell_processes: crate::sandbox::shell_processes::ShellProcesses::new(),
}
}
@@ -523,6 +529,7 @@ impl OpenHumanRunContext {
child.resolved_route = Arc::new(Mutex::new(None));
child.memory_turn = None;
child.response_shape = None;
+ child.shell_processes = crate::sandbox::shell_processes::ShellProcesses::new();
child
}