Skip to content

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

refactor(spawn_subagent): convert preflight include into a macro

Steven Enamakel5e9721bcaf5e
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs
index 88c2a7e242..006e1072ec 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs
@@ -11,7 +11,19 @@ impl SpawnSubagentTool {
>,
>,
) -> anyhow::Result<ToolResult> {
- include!("spawn_subagent_preflight.rs");
+ spawn_subagent_preflight!(
+ dispatch,
+ agent_id,
+ prompt,
+ context,
+ model_override,
+ task_title,
+ task_key,
+ force_fresh,
+ run_context,
+ args,
+ detached_parent
+ );
let parent = match run_context.parent.clone() {
Some(parent) => parent,
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_preflight.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_preflight.rs
index 70d95b5a84..e4145c98b1 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_preflight.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_preflight.rs
@@ -1,19 +1,23 @@
-let dispatch = run_context.dispatch_ctx();
-let AsyncSpawnArgs {
- agent_id,
- mut prompt,
- context,
- model_override,
- task_title,
- task_key,
- force_fresh,
-} = decode_async_spawn_args(&args);
+macro_rules! spawn_subagent_preflight {
+ ($dispatch:ident, $agent_id:ident, $prompt:ident, $context:ident, $model_override:ident, $task_title:ident, $task_key:ident, $force_fresh:ident, $run_context:ident, $args:ident, $detached_parent:ident) => {
+ let $dispatch = $run_context.dispatch_ctx();
+ let AsyncSpawnArgs {
+ $agent_id,
+ mut $prompt,
+ $context,
+ $model_override,
+ $task_title,
+ $task_key,
+ $force_fresh,
+ } = decode_async_spawn_args(&$args);
-if let Some(refusal) = refuse_empty_spawn_args(&agent_id, &prompt) {
- return Ok(refusal);
+ if let Some(refusal) = refuse_empty_spawn_args(&$agent_id, &$prompt) {
+ return Ok(refusal);
+ }
+ let Some($detached_parent) = $detached_parent else {
+ return Ok(ToolResult::error(
+ "spawn_subagent requires a live harness run context.",
+ ));
+ };
+ };
}
-let Some(detached_parent) = detached_parent else {
- return Ok(ToolResult::error(
- "spawn_subagent requires a live harness run context.",
- ));
-};
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_surface.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_surface.rs
index 0e6451ba47..74e574fa52 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_surface.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_surface.rs
@@ -369,6 +369,7 @@ impl SpawnSubagentTool {
mod completion;
include!("spawn_subagent_driver_lookup.rs");
+include!("spawn_subagent_preflight.rs");
include!("spawn_subagent_host_impl.rs");
include!("spawn_subagent_request.rs");
include!("spawn_subagent_projection.rs");