Skip to main content

API

Everything on this page is exported by @ailu-ai/graph-sdk. Types are in the package's .d.ts files; your editor shows them on hover.

Build a graph: createGraph​

createGraph({ name, id?, version?, recursionLimit? }) returns a builder. Every method returns the builder, so calls chain.

MethodAdds
.channel(name, { type, default?, reducer?, noLog? })A channel. reducer: "replace" (default), "append", "merge". noLog masks it in events.
.node(id, handler)A step: async (input, state) => ({ ...updates }). Or .node(id, { handler, retryPolicy: { maxAttempts, backoffMs }, label }).
.agentNode(id, config)An LLM agent. See below.
.humanGate(id)A node that suspends the run until you resume it.
.component(id, components.<kind>({...}))A built-in component.
.taskNode(id, { subAgent, objectiveChannel?, reportChannel?, compress? })An isolated sub-agent that reads objective and writes report.
.mapAgents(id, { overChannel, subAgent, joinAt, suspendForApproval? })One sub-agent per item of overChannel, results in joinAt.
.subgraph(id, builder, { inputMapping?, outputMapping? })Another builder as one node. Mappings are destination: source.
.edge(from, to)An edge.
.conditionalEdge(from, to, name, (state) => boolean)An edge taken when the named predicate returns true.
.errorEdge(from, to)Where to go when from fails after its retries.
.fanOut(from, [branches], joinAt)Run branches in parallel after from, continue at joinAt.
.entry(id)The start node (default: the first node added).
.fsPolicy([{ glob, verb }])File rules for agents with enableFs. verb: read, write, gate, deny.
.compile()Checks the graph and returns a CompiledGraph. Throws GraphCompileError. .safeCompile() returns a result instead.

agentNode config​

OptionTypeDefault
modelmodel.*(...), or a "provider:model" stringAnthropic's default model
prompt{ system: string }required
toolsInMemoryToolRegistrynone
suspendForApprovalboolean: stop the run when a gated tool is requestedfalse
outputChannelstring"agentResult"
visibleChannelsstring[]: the channels the agent is shownall
webSearch{ maxUses?, allowedDomains?, blockedDomains? }: the model provider searches the web (Mistral, Anthropic); no tools alongside; results in agentResult.webSearchoff
maxIterationsnumberengine default
middleware[{ kind: "structuredOutput" | "terse" | "contextBudget" | "compress" | "reflection", params? }]none
profile"fast" | "frontier-careful" | "governed-deep"none
todosChannelstring: where the writeTodos plan is savednone
enableFsboolean: file tools, under .fsPolicyfalse
memory{ namespace, topK?, recall? }none
skills{ namespace, required?, advisoryK? } (catalog runner only)none
inputBlocksChannelstring: a channel of images, audio or files for the modelnone

Run it: CompiledGraph​

MemberDoes
run(data?, { runId? })Runs until the end or a suspension. Resolves with the state: { runId, status, currentNodeId, channels }.
resume(runId)Continues a suspended run of this instance.
approveAndResume(runId, { approvedTools, resolvedBy })Grants gated tools, then continues. resolvedBy, the approver, is required.
signal(runId, name, payload?)Delivers a signal to a run waiting on waitForSignal(name).
stream(data, mode, { runId? })Runs and yields events. mode: "messages", "updates", "values", "debug".
onEvent(handler)Subscribes to run events. Returns an unsubscribe function.
explain(runId)What a suspended run waits for, and how to continue it.
definitionThe graph as a plain GraphDefinition (JSON).

status is "running", "suspended", "completed", "failed" or "cancelled".

Run from saved state: the catalog runner​

FunctionDoes
runCatalogGraph(definition, options?)Runs a GraphDefinition. Resolves with { state, status, pendingApprovals?, replayJournal?, entryState? }.
resumeCatalogGraph(definition, state, options?)Continues a run from a saved state. With approvalEngine, first checks that the engine approved what the run waits on.
replayCatalogGraph(definition, entryState, id, replayJournal)Re-runs a recorded run without calling a model.

Options: initialData, runId, approvalEngine, tools ([{ name, execute }]), nodes ([{ id, execute }], where execute({ nodeId, channels, effectKey }) returns the update), approvedTools (resume only: [{ name, requestedBy, resolvedBy }]), signal (an AbortSignal), checkpointer ({ save(checkpoint) }: keeps every checkpoint before the run goes on, see Keep each checkpoint), onEvent, providerKeys, fsPolicy, skills, subgraphs, streamTokens.

Agents, components, human gates, subgraphs and mapAgents run on this path, and the plain nodes you bind with nodes (Run your code as a step). Your own .node() functions and conditional-edge functions do not. The engine reads the settings saved on the nodes (metadata.agent, metadata.component, metadata.mapAgents) itself, so a saved graph runs the same from Python.

Models​

model and model.invoke(): see Models and providers and Agents and models.

Helpers​

ExportDoes
finalAnswer(result)The answer text of an agent result.
InMemoryToolRegistryHolds tools: register(definition, handler).
writeTodosToolThe built-in planning tool: register(writeTodosTool.definition, writeTodosTool.handler).
waitForSignal(name, { wakeAt? }), sleepUntil(date)Node return values that suspend the run.
readSignal(state, name), readSuspendMeta(state)Read a delivered signal, or why a run is suspended.
council({ members, reviewers?, chair, humanGate? })A council graph, for runCatalogGraph.
componentsThe built-in components.
semanticRetriever, createEmbeddings, createVectorStoreRetrieval by embeddings. See RAG.
InMemoryApprovalEngine, Ed25519Attestor, verifyChain, verifyReplayDecisions, replayedDecisions, attestedDecisionsApproval records and evidence. See Governance.
exportTracesToOtlp, estimateCost, aggregateCosts, computeCost, serveInspector, explainRunObservability. Cost types: CostResult, CostSummary, and ModelPrice (with promptIncludesCacheReads, which says whether a provider counts cache reads inside the prompt tokens). See Observability.
compileGraphFile(yaml, fileName), validateGraph(definition)YAML graphs. See YAML and the CLI.
rustEngineAvailable()Whether the native engine loaded.
componentCatalog, componentSchemas(), generateLlmsTxt()Machine-readable descriptions of the SDK.