What is the Blueprint Engine?
Magpie’s blueprint engine is a deterministic orchestration layer that coordinates AI agent steps, shell commands, and conditional logic into reproducible workflows. Unlike pure agentic systems where behavior can vary, blueprints provide structure and predictability.The blueprint engine is the glue between simple shell scripts (too rigid) and pure AI agents (too unpredictable). It gives you the best of both worlds: deterministic control flow with intelligent agent execution.
Core Architecture
The blueprint system consists of four main components:1. Blueprint
A named sequence of steps that defines a complete workflow.crates/magpie-core/src/blueprint/runner.rs:8-12
Key methods:
Blueprint::new(name)— Create a new blueprint.add_step(step)— Chain steps fluently
2. Step
A single unit of work with a name, kind, condition, and error handling.crates/magpie-core/src/blueprint/step.rs:56-62
3. StepKind
Defines what the step does:crates/magpie-core/src/blueprint/step.rs:49-53
ShellStep
Runs a command via the sandbox abstraction, captures output and exit code:crates/magpie-core/src/blueprint/steps/shell.rs:8-11
Example:
AgentStep
Runs a Goose-powered AI agent with a prompt, optionally injecting prior output:crates/magpie-core/src/blueprint/steps/agent.rs:11-18
Example:
4. Condition
Controls when a step runs:crates/magpie-core/src/blueprint/step.rs:25-31
Evaluation logic:
crates/magpie-core/src/blueprint/step.rs:34-45
StepContext: State Flow Between Steps
TheStepContext flows between steps, carrying shared state:
crates/magpie-core/src/blueprint/step.rs:5-11
How it works:
- Each step receives the current context
- The step executes (shell command or agent prompt)
- A new context is returned with updated
last_outputandlast_exit_code - The next step receives this updated context
chat_history— Discord/Teams conversation contexttrace_dir— JSONL trace output directory
BlueprintRunner: Execution Engine
TheBlueprintRunner executes a blueprint step-by-step:
crates/magpie-core/src/blueprint/runner.rs:29-39
Execution Flow
For each step, the runner:- Evaluates the condition — Skip if not met
- Executes the step — Shell command or agent prompt
- Checks the exit code — Fail fast or continue on error
- Updates the context — Flow state to the next step
crates/magpie-core/src/blueprint/runner.rs:41-101
Error Handling Modes
Each step has acontinue_on_error flag:
false(default) — Fail fast: stop the blueprint on non-zero exit or errortrue— Continue: log warning and proceed to next step
crates/magpie-core/src/pipeline.rs:456-461
Built-in Blueprints
Magpie ships with three production blueprints, selected based on task classification:Simple
Single-shot agent call for docs, typos, renames
TDD
Test-Driven Development flow for new features
Diagnostic
Root cause investigation for bug fixes
Why Blueprints Matter
Reproducibility
Reproducibility
The same blueprint with the same inputs produces similar behavior. This makes debugging and testing possible.
Observability
Observability
Each step logs
[N/M] step-name → running... and → OK (exit 0). You can trace exactly where a workflow failed.Composability
Composability
Build complex workflows by chaining simple steps. Shell steps provide determinism, agent steps provide intelligence.
Testing
Testing
Use
MockSandbox to record/replay step executions without running real commands or agents. See tests in runner.rs:234-267.Next Steps
Explore Built-in Blueprints
See how Simple, TDD, and Diagnostic blueprints work in production
Build Custom Blueprints
Learn to create your own blueprints with
Blueprint::new() and .add_step()