Skip to content
pleach

Nodes

The node shape — an async state function plus typed metadata. The reactive engine schedules from that metadata; the lattice gate reads it to refuse an out-of-stage edge.

A node is an async function plus typed metadata. The function takes the current state, returns a partial state update, and the metadata tells the runtime three things: which lattice stage the node belongs to, which LLM seam (if any) it consumes, and which channels it reads and writes. The reactive engine reads that metadata to schedule nodes; the lattice gate reads it to refuse out-of-stage edges.

Nodes are one of three concepts in the execution-graph cluster — graph, nodes, channels. See Architecture → the execution-graph cluster for the cluster framing.

This page covers the node-level surface. See Graph for how nodes compose into a StateGraph, and Channels for the reactive state slots nodes flow through.

Subpath@pleach/core/graph

The node shape

import type { CallClass } from "@pleach/core/modelfamily"

// The node-metadata shape you author for each node. The channel-wiring
// fields mirror the `*_NODE_METADATA` consts in @pleach/core's graph nodes.
interface NodeMetadataShape {
  stageId:     "anchor-plan" | "tool-loop" | "synthesize" | "post-turn"
  acceptsSeam: CallClass | null
  subscribes?: string[]
  writes?:     string[]
}
FieldPurpose
stageIdLattice membership. One of the four stages.
acceptsSeamCallClass literal if the node consumes an LLM seam; null if seam-free state transform.
subscribesChannels the node READS. When one of these advances, the engine schedules this node in the next superstep.
writesChannels the node UPDATES. The engine uses this to track downstream subscribers.

A minimal registration:

graph.addNode(
  "intentDetector",
  async (state) => ({ intent: classify(state.messages) }),
  {
    stageId: "anchor-plan",
    acceptsSeam: "utility",
    subscribes: ["messages"],
    writes: ["intent"],
  },
)

Coming from LangGraph?

LangGraph nodes typically return new Command({ update, goto, graph: Command.PARENT }) — a sum type that collapses "edge decision + state update + cross-graph routing" into one return value. Pleach moves all three concerns to declaration time, not return time:

  • State updates — return a partial state object (LangGraph: update field).
  • Edge routing — declare with subscribes / writes metadata. The reactive engine schedules subscribers automatically (LangGraph: goto field).
  • Cross-stage transitions — lattice-gated by stageId. The four-stage lattice admits nine (from-stage, to-stage) edge patterns (five cross-stage transitions + four intra-stage chains); CI rejects out-of-stage edges in the default graph (LangGraph: graph: Command.PARENT).
  • Cross-subgraph routing — subagents flow back to the parent turn via SpawnTreeState rather than a routing primitive.

The two approaches converge: pleach trades runtime flexibility for static-analyzability (a graph linter can see the topology without running the nodes). If you need LangGraph's runtime routing for a specific pattern, return a state field the next stage's nodes subscribe to.

Stage membership

Every node declares stageId. The lattice is one-way; the only backward edge is the bounded synthesize → tool-loop re-entry (at most once per turn, same messageId — it replaced the retired synthesize → synthesize retry self-loop):

Four-stage lattice: anchor-plan, tool-loop, synthesize, post-turnA turn is drawn as a four-layer network. Anchor-plan has three nodes, tool-loop fans out to six and loops back on itself, synthesize narrows to one node, and post-turn flushes to two. Every edge runs from one stage to the next, in order. The flow is enforced in CI — out-of-lattice edges fail the build.01anchor-planFrame the turn02tool-loopFan out + iterate03synthesizeOne final answerONE ANSWER ONLY04post-turnFlush + close
Every node in @pleach/core sits in exactly one of these four stages. Every release is checked for out-of-lattice edges — the diagram is the invariant, not a best-practice diagram.
anchor-plan  →  tool-loop  →  synthesize  →  post-turn
                   ↘ post-turn   (recovery dispatch)
                   ↖ synthesize  (bounded re-entry, ≤1/turn)

The four stages are structural: they pin cost allocation, time-travel rollback points, and per-stage budget gates. See Architecture — Stage lattice for the lattice's role in the broader substrate.

Seam membership

acceptsSeam is null for seam-free nodes and a CallClass literal (utility, reasoning, converse, synthesize) for nodes that consume an LLM seam. The literal is lint-restricted to the seam factories; outside the seams, a node resolves its model through AgentAdapter.resolveModel<C>() and the locked call class threads through statically.

Use acceptsSeam: null for pure state transforms, anchor builders, context projectors, and any node whose work is computation over existing state. Use a CallClass literal when the node fires a seam. See Architecture — Seams.

Reactive scheduling

subscribes is what triggers the node. When a channel a node subscribes to advances its version, the engine schedules that node in the next superstep. writes is the inverse — the engine uses it to compute downstream subscribers for the channels this node updates.

Without explicit metadata, the engine falls back to subscribing the node to every channel in the schema (and marking it as writing every channel). That conservative default keeps a metadata-less node correct but over-triggers it; declare explicitly when the read/write set matters for documentation, plugin-registered nodes, or any node whose subscription contract is load-bearing. See Channels for the six channel kinds and their concurrent-write semantics.

The default node catalogue

buildDefaultAgentGraph registers its nodes across the four stages — the Node catalog enumerates every name and its gated condition. A representative slice per stage:

anchor-plan

  • sessionAnchor — boots the turn with system primer + session-level context
  • intentDetector — classifies user intent
  • planGenerator — emits the per-turn plan; under planMode: "in-node" it makes one awaited planner call
  • planReconciler — handles plan drift mid-turn
  • skillActivation — picks active skills for the turn (turn entry; its mid-loop re-arm arm is the tool-loop node skillRearm, same closure)
  • costRouter — model resolution + cost-aware routing
  • contextProjection — projects relevant history into the active context

tool-loop

  • llm — the per-turn LLM decision
  • tools — dispatches tool calls
  • subagent — spawns subagent runtimes
  • skillRearm — mid-loop skill re-arm (shares the skillActivation closure)
  • safetyReview — pre-synthesis safety gate
  • creditBudget — per-turn budget gate
  • eventLogger — logs completed tool-execution events
  • repetitionGuard — detects loops in tool selection
  • hallucination — narration-vs-execution analyzer
  • fabrication — unsourced-claim guard
  • forceSynthesizer — escape hatch when the loop won't converge — the tool-loop → synthesize transition
  • continuation — depth-zero continuation gate

synthesize

  • synthesizer — the singleton synthesizer seam call; owns the final user-visible content

synthesize is a true singleton — synthesizer is the only node the lattice admits in this stage, enforced by a structural check on singleton node names. The recovery siblings earlier revisions placed here (refusalHint, retryNarration, garbleRecovery, recovery) retired from the lattice; they fire now as post-turn stream filters, not graph nodes.

post-turn

  • citation — citation injection back to source data
  • contextSummarizer — context-window summarizer for next-turn insertion
  • memoryExtraction — long-term memory extraction
  • consolidation — turn consolidation before the memory write
  • sessionMemoryWrite — session-level memory persistence
  • costRollup — per-turn token/cost rollup
  • answerSufficiency — answer-coverage verdict: a deterministic backstop by default, plus a utility-seam model judge when answerSufficiencyJudge is on

See the Node catalog for the full set.

New-node checklist

When you add a graph node through a plugin's extraGraphNodes():

  1. Declare stageId in the node's metadata.
  2. Declare acceptsSeam: CallClass | null: the literal for a node that reserves a seam, null for a pure state transform.
  3. Declare subscribes and writes. Registration refuses a node without them. Empty arrays are valid.
  4. Keep the name unique. A plugin node can't shadow a core node at a different stage.

See Release checks for what Pleach's CI checks on the default graph.

Post-tool tier — agnostic by injection

The post-tool nodes (enrichment, safetyReview, quality, citation) are wired into the lattice but their bodies are domain-free. Host runtimes supply the domain logic at runtime through buildDefaultAgentGraph(config):

Config fieldNode it wires
enrichmentExecutorenrichment
safetyReviewExecutorsafetyReview
qualityEvaluatorquality
citationExtractorcitation

The factory only registers the matching node when the executor is provided; absent executor means absent node. This is pure dependency inversion — the graph layer carries no hardcoded host logic for biosecurity scanning, citation extraction, domain quality thresholds, or enrichment passes. A host runtime stays in control of every domain decision through the executor it supplies.

Authoring a custom node

A custom node is an async function returning Partial<State>, registered with metadata. The example below summarises completed tool calls into a single string — no seam consumed, so acceptsSeam is null.

import type { ToolResult } from "@pleach/core"

const toolSummaryMetadata = {
  stageId: "tool-loop",
  acceptsSeam: null,
  subscribes: ["completedTools"],
  writes: ["toolSummary"],
}

async function toolSummary(state: { completedTools: ToolResult[] }) {
  const lines = state.completedTools.map(
    (t) => `${t.success ? "ok" : "error"}: ${t.message ?? ""}`,
  )
  return { toolSummary: lines.join("\n") }
}

graph.addNode("toolSummary", toolSummary, toolSummaryMetadata)

The metadata is the contract. The runtime reads subscribes to know when to schedule the node, writes to know who's downstream, stageId to refuse an out-of-lattice edge at compile time, and acceptsSeam to know the node doesn't consume an LLM.

Plugin-registered nodes

A plugin contributes nodes via HarnessPlugin.extraGraphNodes(), which returns PluginGraphNodeRegistration[]:

interface PluginGraphNodeRegistration {
  name:      string
  factory:   (ctx: PluginGraphNodeContext) => GraphNode
  metadata?: StateGraphNodeMetadata
}

The graph builder calls each factory once at compile time, passing a PluginGraphNodeContext with shared resources (storage adapter, event log writer, registries). This is the path for domain-specific nodes that shouldn't live in the substrate's generic builder — a retrieval node bound to a particular vector store, a tenant-specific safety pass, an integration-specific post-turn writer. See Plugin contract for the full surface.

Determinism contract

A node function MUST be deterministic given the same state input. The function is async because real nodes do I/O — a tool call, a storage read, a seam invocation — but the OUTPUT must be a function of the input state. No module-level RNG. No wall-clock reads outside the captured-at-turn-start values the runtime threads through. No reads from singletons that mutate between turns.

Replay determinism depends on it. A node that captures Date.now() mid-body produces a different partial state on replay than on record, the engine schedules a different next superstep, and the diff harness flags the node as the divergence source. See Determinism for the five substrate-level contracts the node-level rule sits inside.

What's checked when you add a node

The graph build checks a plugin node: it has to declare subscribes and writes, and it can't shadow a core node at a different stage. Declare a stageId too, so the node takes part in its stage.

The node is one row in the extension map, and When a check fails maps each error to its fix.

Where to go next