Skip to main content

Core API Overview

The Core API section documents the workflow.* runtime API available directly to business workflows. Its boundary is src/runtime-api.ts in the Core repository: platforms, CLI, Desktop, and Server inject these methods into globalThis.workflow, so a business workflow does not import them from "workflow-code".

Entry boundary

EntranceDescription
workflow.*Global API used by business workflows, sourced from src/runtime-api.ts in the Core repository.
workflow-code package entryUtility entry used by CLI, Desktop, Server, tests, and advanced hosts, sourced from src/index.ts in the Core repository.

Runtime API index

APIDescription
defineWorkflowDefines a workflow and its main execution function.
defineEntrypointDefines an independently runnable Workflow entrypoint, including its parameters, tools, and registry.
defineExecutorDefines a Workflow project's entrypoints or a Conversation project's single execution configuration.
parseConversationDefaultInputArgsParses the serialized --message, --images, and --files values from the default conversation input.
createInputNodeCreates an input-parsing node.
createFileInputNodeCreates a file-input node and resolves a file parameter reference to a file object.
createUserInputNodeCreate a human input node that can be persisted, pausing workflow to waiting_for_input.
createToolApprovalGateCreate tool approval wrappers; combine executor tools registry entries and context.toolPermissions reuse user-input to wait for/resume protocol approval tool calls.
createLLMNodeCreate a non-streaming LLM call node.
createLLMStreamNodeCreate a streaming LLM call node.
createLLMProviderFromEnvCreate a LLM provider from the workflow runtime environment variable.
getServerLLMCredentialsObtain the server AI configuration available for the current logon account and create a proxy provider that does not expose the upstream key.
createLLMProviderRefCreates a provider reference that can be deferred resolved.
createOutputNodeCreating a synchronous or streaming output node;createOutputItem, createOutputPayload, addOutputItem, and createOutputItemChunk are also described on this page.
createDetailsOutputNodeA convenient output node for creating independent, foldable output items.
createTimerNode / endTimerCreate a business timing node and write a timing card at the explicit end or workflow end.
createQuestionClassifierNodeCreate a problem classification node based on LLM.
runNodeExecute the normal node and trigger the node to execute the hook.
runStreamNodeExecute the streaming node, collect chunks, and produce finalize results.
runIfExecute the if / else-if / else branch and write the branch selection to the run report and Diagram.
runForExecute a traceable for loop and let Diagram display the loop body with the loop container.
runWhileExecute the traceable while loop and let Diagram display the loop body with the loop container.
runWorkflowCall another workflow in the current context, multiplexing KV, session, provider, token usage, and trace.
Knowledge DocumentsManage project Markdown Knowledge documents through an explicit local or server storage context.
getEnvReads a non-empty variable in the current runtime environment.
getRuntimePlatform / isCli / isWeb / isDesktopDetermine whether the execution host for the current workflow is CLI, Desktop, or server web.
getRuntimeLocaleReads the Simplified Chinese or English language selected by the current host for localized visible output.
getLLMProviderResolves LLM provider by context, node name, and provider source.
WorkflowErrorStandard workflow error type.

Core Run Object

Most API runs around input, context, node, and payload.

ObjectTypeDescription
inputInput or node OutputThe input data for the current workflow or node.
contextWorkflowContext / NodeContextContains provider, storage, conversation, files, metadata, hooks, and abortSignal.
payloadWorkflowPayload subtypeNode payload should inherit WorkflowPayload, errCode: 0, errMessage: "" on success.
providerLLMProviderSource / LLMProviderThe LLM node parses the actual provider by provider source.

NodeContext Core Fields

FieldTypeDescription
providersProviderRegistryLLM provider the registry and binding tables.
storageWorkflowStorageContextExplicit local and server locations, each with three-scope kv and persistentValue. The project dataStorage.mode strictly limits accessible locations. Core 0.2 no longer provides top-level context.kv or context.persistentValue.
conversationWorkflowConversationContextSession state read/write entry. setTitle can safely suggest UI title; other reads and writes will throw errors when the session is not enabled.
tokenUsageWorkflowTokenUsageContextToken-usage reporting context. When disabled, report() is a no-op; when enabled, it writes KV, run reports, and runtime events.
userInputWorkflowUserInputContext | undefinedWait/resume entry for user input and tool approval. CLI, Desktop, server runner will be injected according to the host capacity.
filesWorkflowFileStore | undefinedFile reference resolution entry;createFile generates a server-backed run file.
metadataobject | undefinedCurrent execution meta information, such as workflow, runId, conversationId;Workflow run also contains entrypointId and entrypointTitle.
nodeHooksNodeExecutionHooks | undefinedNode start, chunk, complete, and other event callbacks.
timersWorkflowTimerContext | undefinedBusiness timing node context;createTimerNode start timing,endTimer end timing.
toolPermissionsWorkflowToolPermissionContext | undefinedThe tool permission context for the current run. Parses by executor tools default and host override values for createToolApprovalGate() or custom tool call logic to determine enablement, automatic approval, and manual approval.
abortSignalAbortSignal | undefinedInterrupt execution and provider calls.

Payload Constraint

FieldDescription
errCodeBusiness error code. The success value is 0.
errMessageThe error description. Uniform empty string on success.