Skip to content

Complete Runtime examples ​

简体中文 · All examples · API reference

Run from the project root with Node 24+ and npm 11+. Install with npm ci first. The local entrypoints use public exports without model keys, databases or extra SDKs. graph-loop/placement execute on import; quickstart/api/flows only execute when run directly. Exported MCP/ReAct functions in flows require separately supplied external services.

FilePurposeCommand
quickstart.tsYAML behavior settings, CONTEXT.LOAD → SELECT, execution and closenpm run example:runtime:quickstart
api.tsCustom/private nodes, separate replicas, event failures, Artifact/Codec and cleanupnpm run example:runtime:api
flows.tsSkill loading, actual text RAG and README tool reading; exported MCP/ReAct callsnpm run example:runtime:flows
graph-loop.tsTwo read/count graphs; select the read graph once and repeat the count graph twice; bind nodes to independently configured Worker sandboxes; emit count eventsnpm run example:runtime
placement.tsExecute one CONTEXT.LOAD graph through direct calls, a real child-process IPC channel and another child-process HTTP server; exchange addresses and clean up resourcesnpm run example:runtime:placement

graph-loop.ts reads the actual root README.md. Reader permits only read_text and filesystem reads; counter permits only count_text, with no filesystem or command permissions. Output contains two counted events and final iteration=3 state. Counts depend on README content. Graphs define dependencies; execution worker mappings select replicas. The example loads root YAML behavior settings and defines Sandbox policies in code without loading .env.

placement.ts prints both child PIDs and direct/ipc/http results. IPC requests use the inherited Node channel. HTTP requests use an authenticated loopback socket; only startup/shutdown control messages use the HTTP child's IPC channel. This exercises the network protocol without claiming to connect two physical machines. For deployment across machines, start the HTTP Worker separately and configure its registered address and HTTPS endpoint on the caller. The graph stays unchanged.

Production credentials belong in .env; behavior settings such as graphConcurrency and loopMaxIterations belong in root YAML. Inject a SandboxExecutor to execute tools through a container or another environment. Process isolation and cooperative Sandbox checks serve separate purposes.

Exported function guide ​

FunctionPurpose
quickstartExecute and check LOAD → SELECT
textWorker / simpleTextWorkerActual text processing using defineWorker and extendWorker
workerLifecycleRegister replicas, verify private nodes/resources, process events, pause/unregister/close
eventFabricRun consumers, collect failures, unsubscribe
artifactsput/get/delete, inline/reference encoding and cleanup
readTextTool / contextFlowsFile tool plus Skill → text retrieval → tool → observation → Context
mcpFlowsDiscover then invoke a tool through a connected MCP client and update Context
reactFlowBounded ReAct with a configured model/readTextTool; throw on non-completion

Ditto · @codesoul-co/ditto · Node.js 24+