Overseas access: www.kdjingpai.com
Bookmark Us
Current Position:fig. beginning " AI Answers

How to implement a simple node task in ZeroGraph?

2025-08-21 252

In ZeroGraph, the node tasks are created by inheriting the Node class implementation. Here are the steps to create a simple greeting node:

  1. Defining Node Classes::
    • rewrite prep method prepares the input data (e.g., getting a name from a shared object).
    • exist exec Write core logic (e.g., generating greetings) in the
    • pass (a bill or inspection etc) post Store the results to a shared object.
    class GreetingNode extends Node {
      prep(shared: any): string {
        return shared.name || 'World';
      }
      exec(name: string): string {
        return `Hello, ${name}!`;
      }
      post(shared: any, execRes: string): void {
        shared.greeting = execRes;
      }
    }
  2. workflow::
    • establish Flow instance and pass in the node, run it and output the result:
      const flow = new Flow(new GreetingNode());
      const shared = { name: 'TypeScript' };
      flow.run(shared);
      console.log(shared.greeting); // 输出: Hello, TypeScript!

Recommended

Can't find AI tools? Try here!

Just type in the keyword Accessibility Bing SearchYou can quickly find all the AI tools on this site.

Top

en_USEnglish