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
refactor(turn_host): extract workspace binding into helper
Steven Enamakel83d2c082a359
diff --git a/crates/openhuman-core/src/agent/session_host/live_tools.rs b/crates/openhuman-core/src/agent/session_host/live_tools.rsindex 16f51e511d..b9bf4c74b5 100644--- a/crates/openhuman-core/src/agent/session_host/live_tools.rs+++ b/crates/openhuman-core/src/agent/session_host/live_tools.rs@@ -37,11 +37,6 @@ impl OpenHumanSessionHost {dispatch: crate::core::runtime::DispatchCtx::from_weak(self.host_env.core.as_ref()),}}-- /// The workspace descriptor tools run against.- pub(crate) fn live_workspace_descriptor(&self) -> Option<tinytools::WorkspaceDescriptor> {- self.workspace_descriptor.clone()- }}#[cfg(test)]diff --git a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rsindex ab7bec2f6d..35975594c1 100644--- a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs@@ -437,6 +437,11 @@ impl OpenHumanSessionHost {self.workspace_descriptor = descriptor;}+ /// The current workspace binding used by this session's tools.+ pub(crate) fn live_workspace_descriptor(&self) -> Option<tinytools::WorkspaceDescriptor> {+ self.workspace_descriptor.clone()+ }+/// Attach an active-run queue for mid-turn steering.pub fn set_run_queue(&mut self,diff --git a/crates/openhuman-core/src/agent/turn_host.rs b/crates/openhuman-core/src/agent/turn_host.rsindex e833bf0ef0..61584b53b1 100644--- a/crates/openhuman-core/src/agent/turn_host.rs+++ b/crates/openhuman-core/src/agent/turn_host.rs@@ -80,6 +80,12 @@ impl WorkspaceBinding {}}+fn bind_workspace(session: &mut OpenHumanSessionHost, binding: WorkspaceBinding) {+ if let Some(workspace) = binding.update() {+ session.set_workspace_descriptor(workspace);+ }+}+/// Shared agent-domain execution port used by web and external-channel hosts.pub(crate) struct AgentTurnHost;@@ -104,9 +110,7 @@ impl AgentTurnHost {.turn_deadline.map(tinyagents_harness::turn_deadline::TurnDeadline::starting_now);session.set_host_env(host_env);- if let Some(workspace) = request.workspace.update() {- session.set_workspace_descriptor(workspace);- }+ bind_workspace(session, request.workspace);// Keep the large agent future behind a pointer while the origin scope// is active. The origin is explicit and independent from RPC metadata.diff --git a/crates/openhuman-core/src/agent/turn_host_tests.rs b/crates/openhuman-core/src/agent/turn_host_tests.rsindex d2a3584e4f..98ab43eb93 100644--- a/crates/openhuman-core/src/agent/turn_host_tests.rs+++ b/crates/openhuman-core/src/agent/turn_host_tests.rs@@ -2,17 +2,43 @@ use super::*;#[test]fn workspace_binding_clears_a_previous_turns_workspace() {- assert_eq!(WorkspaceBinding::Clear.update(), Some(None));+ let mut session = session_with_workspace("/previous/thread");+ assert_eq!(+ session.live_workspace_descriptor().unwrap().root,+ std::path::PathBuf::from("/previous/thread")+ );++ bind_workspace(&mut session, WorkspaceBinding::Clear);++ assert_eq!(session.live_workspace_descriptor(), None);}#[test]fn workspace_binding_can_preserve_or_replace_the_session_workspace() {let previous = tinytools::WorkspaceDescriptor::new("/configured");let requested = tinytools::WorkspaceDescriptor::new("/thread");+ let mut session = session_with_workspace("/configured");- assert_eq!(WorkspaceBinding::Preserve.update(), None);- assert_eq!(- WorkspaceBinding::Set(requested.clone()).update(),- Some(Some(requested))- );+ bind_workspace(&mut session, WorkspaceBinding::Preserve);+ assert_eq!(session.live_workspace_descriptor(), Some(previous));++ bind_workspace(&mut session, WorkspaceBinding::Set(requested.clone()));+ assert_eq!(session.live_workspace_descriptor(), Some(requested));+}++fn session_with_workspace(path: &str) -> OpenHumanSessionHost {+ let root = tempfile::tempdir().expect("workspace tempdir");+ let model = std::sync::Arc::new(tinyagents_harness::testkit::ScriptedModel::replies(vec![+ "ok",+ ]));+ let chat_model: std::sync::Arc<dyn tinyinference_llm::model::ChatModel<()>> = model;+ crate::agent::SessionHostBuilder::new()+ .chat_model(chat_model)+ .tools(Vec::new())+ .workspace_dir(root.path().join("workspace"))+ .action_dir(root.path().to_path_buf())+ .workspace_descriptor(Some(tinytools::WorkspaceDescriptor::new(path)))+ .tool_dispatcher(Box::new(tinytools_agent::dialect::NativeDialect))+ .build()+ .expect("session host")}