Skip to main content

Module process_spawner

Module process_spawner 

Source
Expand description

ProcessSpawner — a general-purpose SpawnerAdapter implementation that spawns an arbitrary binary (or a one-line shell command) and runs it as a worker. The thin path for wrapping an agent-block CLI, an LLM CLI, a random binary, or a shell script as a worker.

Direct library integration with the agent-block-core SDK lives on a separate axis, in crate::worker::agent_block::AgentBlockInProcessSpawnerFactory: the SDK is embedded in-process, and bus.emit("worker_result", ...) is captured host-side. This spawner’s selling point is “call anything over a shell”; it is not agent-block-specific, and the two paths have fully separated responsibilities.

Naming convention: ProcessSpawner starts a shell process, and AgentBlockInProcessSpawnerFactory provides direct integration with the agent-block SDK. Older commits still reference an “AgentBlockSpawner” — that was renamed to ProcessSpawner in the current design (commit 8d1058f). See mini-app issue 96821965 for the full rationale.

§Modes (two flavours)

plain mode (default):

  1. On spawn, launch a child process with Command::new(self.program) + args.
  2. Write the directive to the child’s stdin (used as the prompt).
  3. Buffer the child’s stdout in full.
  4. Try to parse stdout as JSON; on failure wrap it as {"raw": "<text>"}.
  5. ok = true on exit code 0, otherwise ok = false.
  6. Emit the WorkerResult in parallel via engine.submit_output(Final) (design intent).

streaming mode (.stream_mode(StreamMode::...)): 1-2. Same as plain mode. 3. Read the child’s stdout line by line through a BufReader for NDJSON — or via a different protocol later. 4. Parse each chunk as an OutputEvent; skip failures. 5. engine.submit_output each successfully-parsed event incrementally. 6. When OutputEvent::Final arrives, fold its {content, ok} into the WorkerResult. 7. If EOF is hit without a Final, mark the outcome ok = false (Blocked).

Only StreamMode::NdjsonLines ships today; SSE, length-prefixed, and friends are carries for future turns.

Token metadata is also handed to the child as environment variables so a worker can re-pull if it needs to. sig_hex is deliberately not exported, to keep exposure minimal.

Structs§

ProcessSpawner
A SpawnerAdapter that runs a worker as an external OS process (a binary or a sh -c one-liner). Configured with the builder methods below, then registered like any other spawner.
ProcessWorker
Concrete Worker type for the Subprocess kind — the handle to a child OS process’s wait_with_output / stream wait. Embeds a WorkerJoinHandler to carry the async signal.

Enums§

StreamMode
Wire protocol used to receive OutputEvents from the child’s stdout. None means plain mode — the default — which buffers stdout in full and folds it into a single Final.