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.
@pleach/core/graphThe 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[]
}| Field | Purpose |
|---|---|
stageId | Lattice membership. One of the four stages. |
acceptsSeam | CallClass literal if the node consumes an LLM seam; null if seam-free state transform. |
subscribes | Channels the node READS. When one of these advances, the engine schedules this node in the next superstep. |
writes | Channels 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:
updatefield). - Edge routing — declare with
subscribes/writesmetadata. The reactive engine schedules subscribers automatically (LangGraph:gotofield). - 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
SpawnTreeStaterather 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):
@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 contextintentDetector— classifies user intentplanGenerator— emits the per-turn plan; underplanMode: "in-node"it makes one awaited planner callplanReconciler— handles plan drift mid-turnskillActivation— picks active skills for the turn (turn entry; its mid-loop re-arm arm is thetool-loopnodeskillRearm, same closure)costRouter— model resolution + cost-aware routingcontextProjection— projects relevant history into the active context
tool-loop
llm— the per-turn LLM decisiontools— dispatches tool callssubagent— spawns subagent runtimesskillRearm— mid-loop skill re-arm (shares theskillActivationclosure)safetyReview— pre-synthesis safety gatecreditBudget— per-turn budget gateeventLogger— logs completed tool-execution eventsrepetitionGuard— detects loops in tool selectionhallucination— narration-vs-execution analyzerfabrication— unsourced-claim guardforceSynthesizer— escape hatch when the loop won't converge — thetool-loop → synthesizetransitioncontinuation— 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 datacontextSummarizer— context-window summarizer for next-turn insertionmemoryExtraction— long-term memory extractionconsolidation— turn consolidation before the memory writesessionMemoryWrite— session-level memory persistencecostRollup— per-turn token/cost rollupanswerSufficiency— answer-coverage verdict: a deterministic backstop by default, plus a utility-seam model judge whenanswerSufficiencyJudgeis on
See the Node catalog for the full set.
New-node checklist
When you add a graph node through a plugin's extraGraphNodes():
- Declare
stageIdin the node's metadata. - Declare
acceptsSeam: CallClass | null: the literal for a node that reserves a seam,nullfor a pure state transform. - Declare
subscribesandwrites. Registration refuses a node without them. Empty arrays are valid. - 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 field | Node it wires |
|---|---|
enrichmentExecutor | enrichment |
safetyReviewExecutor | safetyReview |
qualityEvaluator | quality |
citationExtractor | citation |
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
Graph
How nodes compose into a StateGraph — edges, compile, the lattice as a whole.
Channels
The six channel kinds nodes subscribe to and write.
Architecture
Stage lattice, seams, audit ledger — the substrate the node shape sits inside.
Plugin contract
extraGraphNodes and the rest of the HarnessPlugin surface.
Graph
The declarative topology that drives a turn — Annotation channel schema, StateGraph builder, the Send envelope, compile() runner, and the four-stage lattice gate that keeps every node attributable.
Channels
The six channel kinds — LastValue, BinaryOperatorAggregate, Topic, EphemeralValue, NamedBarrier, DataChannel — with their concurrent-write semantics and reducers.