Skip to content

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

refactor(agent): route workspace binding through a single apply helper

Steven Enamakel2c1ad898347b
diff --git a/crates/openhuman-core/src/agent/turn_host.rs b/crates/openhuman-core/src/agent/turn_host.rs
index 09132fe926..a4dd3e7295 100644
--- a/crates/openhuman-core/src/agent/turn_host.rs
+++ b/crates/openhuman-core/src/agent/turn_host.rs
@@ -70,6 +70,16 @@ pub(crate) enum WorkspaceBinding {
Set(tinytools::WorkspaceDescriptor),
}
+impl WorkspaceBinding {
+ fn apply(self, current: Option<tinytools::WorkspaceDescriptor>) -> Option<tinytools::WorkspaceDescriptor> {
+ match self {
+ Self::Preserve => current,
+ Self::Clear => None,
+ Self::Set(workspace) => Some(workspace),
+ }
+ }
+}
+
/// Shared agent-domain execution port used by web and external-channel hosts.
pub(crate) struct AgentTurnHost;
@@ -94,13 +104,10 @@ impl AgentTurnHost {
.turn_deadline
.map(tinyagents_harness::turn_deadline::TurnDeadline::starting_now);
session.set_host_env(host_env);
- match request.workspace {
- WorkspaceBinding::Preserve => {}
- WorkspaceBinding::Clear => session.set_workspace_descriptor(None),
- WorkspaceBinding::Set(workspace) => {
- session.set_workspace_descriptor(Some(workspace));
- }
- }
+ let workspace = request
+ .workspace
+ .apply(session.live_workspace_descriptor());
+ session.set_workspace_descriptor(workspace);
// Keep the large agent future behind a pointer while the origin scope
// is active. The origin is explicit and independent from RPC metadata.
@@ -115,3 +122,7 @@ impl AgentTurnHost {
.await
}
}
+
+#[cfg(test)]
+#[path = "turn_host_tests.rs"]
+mod tests;