Class MissionBuilder

Fluent builder that collects mission configuration and validates it at .compile() time.

All setter methods return this for chaining. No compilation work is performed until .compile() is called, ensuring fast construction of mission objects at module load time.

Constructors

Methods

  • Declare the input schema for this mission.

    Accepts a Zod schema object or a plain JSON-Schema Record<string, unknown>. The schema is stored in the compiled graph's stateSchema.input field and used by the runtime for optional input validation.

    Parameters

    • schema: any

      Zod or JSON-Schema object describing the expected input payload.

    Returns this

  • Set the goal template for this mission.

    The template is a free-form string that describes what the mission should achieve. It may include {{variable}} placeholders. The current stub compiler passes the template through verbatim into generated node instructions; future planner integrations may interpolate it from runtime input.

    Example: 'Research {{topic}} and produce a concise summary'

    Parameters

    • template: string

      Goal prompt template string.

    Returns this

  • Declare the output (return) schema for this mission.

    Accepts a Zod schema object or a plain JSON-Schema Record<string, unknown>. The schema is stored in the compiled graph's stateSchema.artifacts field.

    Parameters

    • schema: any

      Zod or JSON-Schema object describing the expected artifact payload.

    Returns this

  • Configure planner hints recorded on the mission config.

    Today the compiler emits a fixed stub plan regardless of strategy. These settings are still preserved so planner-backed mission compilation can adopt them without changing the authoring API.

    Parameters

    • config: {
          strategy: string;
          maxSteps: number;
          maxIterationsPerNode?: number;
          parallelTools?: boolean;
      }

      Planner settings including strategy name, step budget, and per-node iteration and tool-parallelism caps.

      • strategy: string

        Routing/planning strategy identifier (e.g. 'linear', 'react', 'tree-of-thought').

      • maxSteps: number

        Hard cap on the total number of plan steps the planner may emit.

      • Optional maxIterationsPerNode?: number

        Maximum LLM iterations a single gmi node may consume per invocation. Forwarded to gmiNode as maxInternalIterations.

      • Optional parallelTools?: boolean

        When true, gmi nodes are configured to issue multiple tool calls per turn. Forwarded to gmiNode as parallelTools.

    Returns this

  • Apply mission-level policy overrides.

    Policies declared here are applied to all compiled nodes unless a node already carries its own policy declaration. This is the preferred mechanism for setting blanket guardrails, memory consistency modes, or persona settings across a mission.

    Parameters

    • config: {
          memory?: {
              consistency?: MemoryConsistencyMode;
              read?: any;
              write?: any;
          };
          discovery?: {
              kind?: string;
              fallback?: string;
          };
          personality?: {
              traitRouting?: boolean;
              adaptStyle?: boolean;
              mood?: string;
          };
          guardrails?: string[];
      }

      Policy configuration object.

      • Optional memory?: {
            consistency?: MemoryConsistencyMode;
            read?: any;
            write?: any;
        }
      • Optional discovery?: {
            kind?: string;
            fallback?: string;
        }
        • Optional kind?: string
        • Optional fallback?: string
      • Optional personality?: {
            traitRouting?: boolean;
            adaptStyle?: boolean;
            mood?: string;
        }
        • Optional traitRouting?: boolean
        • Optional adaptStyle?: boolean
        • Optional mood?: string
      • Optional guardrails?: string[]

        Guardrail identifiers applied as output guardrails on every node.

    Returns this

  • Declare an anchor node that will be spliced into the execution order.

    Anchors let callers inject pre-built GraphNode objects (e.g. specialised tool invocations, human-in-the-loop checkpoints, or validation guardrails) at precise positions within the phase-ordered plan without modifying the planner output.

    Parameters

    • id: string

      Unique node id assigned to the anchor in the compiled graph.

    • node: GraphNode

      Pre-built GraphNode (from gmiNode, toolNode, etc.).

    • constraints: {
          required: boolean;
          phase?: "gather" | "process" | "validate" | "deliver";
          after?: any;
          before?: any;
      }

      Placement constraints: phase, after / before ordering.

      • required: boolean

        When true the compiler will throw if the anchor cannot be placed.

      • Optional phase?: "gather" | "process" | "validate" | "deliver"

        Execution phase the anchor belongs to. Phases are ordered: gatherprocessvalidatedeliver.

      • Optional after?: any

        Insert the anchor after this node id (sibling anchor id or plan step id). When the referenced id is not found the anchor is appended to the phase tail.

      • Optional before?: any

        Insert the anchor before this node id. Currently reserved for future use; has no effect in this compiler version.

    Returns this

  • Set the autonomy mode for this mission.

    • autonomous — all expansion gates auto-approve. Only stops at hard caps.
    • guided — every expansion requires explicit user approval.
    • guardrailed — auto-approves below configurable thresholds, asks above.

    Parameters

    • mode: "autonomous" | "guided" | "guardrailed"

      Autonomy mode.

    Returns this

  • Set the provider assignment strategy for this mission.

    Parameters

    • strategy: string

      Strategy name: best, cheapest, balanced, explicit, mixed.

    • Optional options: {
          assignments?: Record<string, {
              provider: string;
              model?: string;
          }>;
          fallback?: string;
      }

      Optional explicit assignments and fallback strategy.

      • Optional assignments?: Record<string, {
            provider: string;
            model?: string;
        }>
      • Optional fallback?: string

    Returns this

  • Set the number of Tree of Thought branches to explore during planning.

    Parameters

    • count: number

      Branch count (default: 3, max: 3 for linear/parallel/hierarchical).

    Returns this

  • Set the model used for Tree of Thought planning phases.

    Use a strong reasoning model here (e.g., claude-opus-4-6, gpt-4o) for better plan quality. Defaults to the same model as execution if not set.

    Parameters

    • model: string

      Model identifier string (e.g., 'claude-opus-4-6').

    Returns this

  • Set the default model used for agent node execution.

    Can differ from the planner model — e.g., use Opus for planning but GPT-5.4 for actual agent output generation.

    Parameters

    • model: string

      Model identifier string (e.g., 'gpt-5.4').

    Returns this

  • Validate configuration and compile this mission into a CompiledMission.

    Required fields: input, goal, returns, planner. Throws with a descriptive message if any required field is missing.

    Parameters

    • Optional options: {
          checkpointStore?: ICheckpointStore;
      }

      Optional compilation overrides.

      • Optional checkpointStore?: ICheckpointStore

        Custom checkpoint store; defaults to InMemoryCheckpointStore.

    Returns CompiledMission

    A CompiledMission ready to invoke(), stream(), or explain().

    Throws

    When required builder fields are missing.