Skip to main content

spawn_runtime

Function spawn_runtime 

Source
pub async fn spawn_runtime() -> Result<Runtime, RuntimeError>
Expand description

Build the runtime a subagent runs on. Preferred: EngineHost::worker_runtime() — shares the host credential source and token cache (so NO set_global_broker re-install and NO token-cache eviction per spawn) and takes a clone of the cached worker registry template. Legacy path (no host installed, or kill-switch set): today’s Runtime::new() + rebuilt tools + apply_auth_config, verbatim.

Both paths run with the host’s worker hook view (EngineHost::worker_hook_bus: its after_tool_call output transforms, nothing else). Without an installed host there are no host subscriptions to see, and the legacy runtime keeps its own empty bus.

Called from the subagent’s own OS thread / current-thread tokio runtime: EngineHost::current() is a OnceLock read and worker_runtime() only touches tokio::sync primitives, so this is runtime-agnostic.