Skip to content

Machine stdlib

mklang ships the reasoning architectures of the cookbook as ready, general-purpose machines — parameterized by context, callable from your own machines, runnable by name. These are ordinary .mkl documents bundled with the package (ADR 0012); discover them with mklang machines or the MCP list_machines / describe_machine tools.

Using a stdlib machine

By name from the CLI (no file needed):

mklang run std_self_consistency --set task="Estimate the risk of X"
mklang run std_map_reduce \
  --set task="Summarize the corpus" \
  --set items='["chunk one …", "chunk two …"]' \
  --set item_task="summarize in 2 sentences"

From an MCP host: run(path="std_refine", inputs={"task": "…"}).

As a subroutine of your own machine — the registry always contains the stdlib:

states:
  polish:
    call: std_refine
    input:
      task: "Rewrite this reply: {{draft}}"
      criteria: "courteous, under 150 words, no invented policies"
    output: final
    gates:
      - when: otherwise
        then: ok
        to: END

Lists cross call: as whole-template values (0.3, SPEC §4.8): an input: value that is exactly "{{items}}" passes the raw list into the callee; any mixed template renders to text. From CLI/MCP, list parameters (items, personas) are plain JSON via --set / inputs.

Your machines always win: a project .mkl that reuses a std_* name shadows the bundled machine (with a warning). Third-party packages can add machines via the mklang.machines entry-point group.

Catalog

Uniform contract: input task (string), result answer.

machine architecture flow extra context (defaults) budget tiers
std_cot Chain-of-Thought solve (traced reasoning) → END 3 balanced
std_self_consistency Self-consistency 5 sampled answers → majority vote → END, or low-confidence flag 12 fast → reasoning
std_refine Reflexion / self-refine draft → judged vs criteria → repair ×2 → END, or flagged best-effort criteria ("clear, correct, and complete") 6 balanced
std_tot Tree-of-Thought 3 angled proposals → select best → deepen or finalize best (internal carry, "") 10 balanced → reasoning
std_debate Debate / ensemble one argument per persona → synthesis with coverage repair personas (3 generic debaters, list) 12 fast → reasoning
std_map_reduce Map-Reduce apply item_task to each item → reduce with reduce_task items (list), item_task, reduce_task 20 fast → reasoning
std_cascade Speculative cascade fast draft → confident? END : redo at reasoning tier 4 fast → reasoning
std_plan_execute Plan-and-Execute plan (parse: list, 0.3) → execute each step → combine 16 reasoning → fast → reasoning
std_research Search → ground plan_query → search (accumulate) → check → {loop | finalize | no_search} today (host-fills ISO date, ""), notes (accumulator, []) 14 fast → reasoning
std_compress Working-memory compression compress (judge-verified, repair ×1) → END notes (the memory to compress, list or text) 4 balanced

Notes:

  • Fan-out widths are fixed (sample: 5, sample: 3) — sample/over are static by design. std_map_reduce/std_debate scale with the length of the list you pass; keep it within the budget noted in each file.
  • Every machine ships a *.test.yaml next to it — scripted scenarios you can run offline: mklang test <path>/std_refine.mkl --script <path>/std_refine.test.yaml. The test suite pins all of them in CI.
  • std_compress is built to be called mid-loop by other machines (ADR 0017 Layer 1): a state like {call: std_compress, input: {task: "{{task}}", notes: "{{notes}}"}, output: notes} rewrites an accumulator short before the next round — see examples/research_compress.mkl for the inline version of the same pattern.
  • std_research is the one machine that uses a tool: state — the bundled host search tool (ADR 0016), which every mklang install ships. It grounds the answer only in search observations; with no search backend bound (no TAVILY_API_KEY, MKLANG_SEARCH_BACKEND, or programmatic binding) it says so honestly instead of answering from training knowledge.

Not in the stdlib, and why

pattern blocker
ReAct needs arbitrary host tool:s — tool names are static, so the host must author the machine around its own tools (examples/react.mkl); std_research gets in only because search is bundled
Router-of-experts routes to domain call: targets, which are static — see examples/triage.mkl
Exact policy gates needs host hook:s — see examples/hook_gates.mkl

These stay as documented patterns: the cookbook has the skeletons, the authoring guide the recipe, and best practices the host-tool / layer checklist.