Skip to main content

Module spawn

Module spawn 

Source
Expand description

The daemon spawner: turns a SpawnArgs request into a live agent in the shared world - the CLI-side policy the runtime host calls for a Spawn control op.

It loads the blueprint, resolves each stage’s provider/model (against the world’s registered providers) and effective tool set, spawns the agent via leviath_runtime::pipeline::spawn_agent, attaches its run metadata / token totals / compaction settings, and registers its per-agent tool state with the CliToolService. The heavy MCP connections are shared (built once at daemon startup), so this whole path is synchronous - which lets it run straight from the host’s control loop.

Functions§

build_agent
Load the blueprint at args.blueprint_path, spawn the agent into world, register its tool state, and return the new entity. Operates on the raw ECS World so it is callable both from the host’s spawner (via PipelineWorld::world_mut) and from a fan-out world-system.
build_agent_for_reload
Like build_agent, but skips the required-at-spawn region gate - used by restart recovery, which reloads a run that already passed the gate when first spawned and whose context window is restored from a snapshot after this call.
filter_tools_by_available
Filter all tool defs down to those a stage’s available_tools names (alias-resolved). Shared by spawn-time stage resolution and the mid-run tool-service refresh so both apply Layer-1 identically.
resolve_stage_model
Resolve a stage’s ModelConfig to a concrete (provider, model) against the registered providers. Honors a --model override (provider/model or a bare model), otherwise picks the first listed model whose provider is registered, then falls back to the user default (when allow_user_default), and finally to the config’s first listed entry. (Ported from the executor’s inline resolution.)