Skip to main content

Module compiler

Module compiler 

Source
Expand description

Blueprint Compiler, CompiledAgentTable, and the three default SpawnerFactory implementations.

§Pipeline

Blueprint (= flow + agents + hints + strategy + spawner_hints)
    │
    │ Compiler.compile(&bp)          ← this module (AgentDef → SpawnerAdapter table)
    ▼
CompiledBlueprint {
    router: Arc<CompiledAgentTable>, // ctx.agent → SpawnerAdapter lookup
    flow:   FlowNode,                // the flow.ir source (evaluated via EngineDispatcher)
    metadata: BlueprintMetadata,
}
    │
    │ service::linker::link(router, blueprint.spawner_hints.layers, &engine)
    ▼                                   ↑ Layer wrapping is done separately (src/service/linker.rs)
`Arc<dyn SpawnerAdapter>`            (already wrapped with base + hint SpawnerLayers)
    │
    ▼ EngineDispatcher::with_spawner → engine.dispatch_attempt_with

CompiledAgentTable is a thin table: it looks up routes[name] by ctx.agent and hands the spawn off to the matching SpawnerAdapter. The routes map is built at compile time through SpawnerFactory implementations. Layer wrapping is not part of this module — it lives in service::linker::link.

Structs§

CompiledAgentTable
The compile result: an agent name → SpawnerAdapter lookup table.
CompiledBlueprint
The result of Compiler::compile — a routing table plus the unmodified flow and metadata, ready to hand to EngineDispatcher::with_spawner / mlua_flow_ir::eval_async.
Compiler
Turns a Blueprint into a CompiledBlueprint by resolving every AgentDef against a SpawnerRegistry. One-shot: build a fresh Compiler per compile() call (or reuse it — it holds no per-compile state).
HostBridge
Rust-side bridge function callable from Lua.
LuaInProcessSpawnerFactory
Factory for AgentKind::Lua. At build time it looks the fn_id up in its internal registry and returns an InProcSpawner with the Lua-eval WorkerFn registered under agent_name — one InProcSpawner instance per agent.
LuaScriptSource
Carrier type for Lua script sources. Paths are not required — a source string plus an identifying label is all it holds.
LuaWorker
Concrete Worker type for the Lua kind — a handle to a Lua-eval task inside an mlua VM. Embeds a WorkerJoinHandler. Reserved as the home for future Lua-specific extensions (an mlua VM cancellation mechanism, Lua-side error type retention, and so on).
OperatorSpawnerFactory
Factory for AgentKind::Operator. Looks up the Arc<dyn Operator> pre-registered under spec.operator_ref and wraps it in an OperatorSpawner.
RustFnInProcessSpawnerFactory
Factory for AgentKind::RustFn. At build time it looks the fn_id up in its internal registry and returns an InProcSpawner with the Rust closure WorkerFn registered under agent_name.
RustFnWorker
Concrete Worker type for the RustFn kind — a handle to a task that directly calls a Rust closure. Embeds a WorkerJoinHandler. Being a pure function, there is minimal kind-specific extension surface here; the primary purpose is to nail down the type binding.
SpawnerRegistry
AgentKind → SpawnerFactory mapping. The compiler looks entries up during compile().
SubprocessProcessSpawnerFactory
Factory for AgentKind::Subprocess. Turns the spec into a ProcessSpawner.

Enums§

CompileError
Everything that can go wrong while Compiler::compile turns a Blueprint into a CompiledBlueprint.

Traits§

SpawnerFactory
Factory trait that interprets an AgentDef and builds the concrete SpawnerAdapter. Register one per kind. Parsing the spec, validating it, and baking the profile are the implementation’s job.
SpawnerFactoryKind
Companion trait that carries the type-side source of truth for the Adapter ↔ AgentKind correspondence.