Skip to main content

Node

Nodes are the building blocks of your graphs. They represent individual units of computation and define the behavior of operations associated with that node.

The ops object in the constructor allows you to define the behavior of the node for different operations. For example, the addEdge operation is triggered when an edge is added to the node, while the removeEdge operation is executed when an edge is removed. These operations can be used to perform specific tasks or modifications within the node, such as updating internal state or handling incoming or outgoing edges.

The run operation is excecuted when the node is run for a particular context. This operation will contain your node's logic, and has access to the Node API through the provided context.

Example

import { Scribe } from "https://deno.land/x/scribeai/mod.ts";

// Create a new Scribe instance
const scribe = new Scribe<MyCtx>();

const myNode = await scribe.createNode({
ops: {
addEdge: async (_ctx, next) => {
await next();
},
removeEdge: async (_ctx, next) => {
await next();
},
write: async (_ctx, next) => {
await next();
},
runFor: async (_ctx, next) => {
await next();
},
init: async (_ctx, next) => {
await next();
},
// The `run` operation is triggered when the node has received a context
run: async (opsCtx, next) => {
// Get the node from the API...
const { node } = opsCtx.api;
// ... and do something with it (not shown)

return next();
},
destroy: async (_ctx, next) => {
await next();
},
},
});

Each node acts as a modular unit, encapsulating specific functionality and contributing to the overall flow of data and operations within your graph. Customize the operations, define the behavior, and orchestrate your workflows with ease using the expressive and powerful capabilities of graph nodes.