Skip to main content
Nodes are the fundamental processing units in GraphAI. They encapsulate discrete pieces of functionality and can be connected to form complex workflows.

Node Basics

A node in GraphAI is created by decorating an async function with the @node decorator:
All nodes must be async functions that:
  1. Accept at least an input dictionary
  2. Return a dictionary containing the processed results

Creating Different Types of Nodes

GraphAI supports several types of nodes for different purposes:

Standard Nodes

Standard nodes process data and pass it to the next node:

Start Nodes

Start nodes mark the entry point to your graph:
A graph can have only one start node.

End Nodes

End nodes mark the exit points from your graph:
A graph can have multiple end nodes.

Streaming Nodes

Nodes that need to stream data (like LLM outputs) can use the stream parameter:
Streaming nodes receive a callback parameter that can be used to stream data.

Node Return Values

Nodes must return a dictionary containing their output:
The returned dictionary is merged with the current state and passed to the next node.

Accessing State

Nodes can access the graph’s state by adding a state parameter:

Router Nodes

Routers are special nodes that determine the next node to execute:
Routers must return a dictionary with a "choice" key containing the name of the next node to execute.

Router Example with LLM

Routers are often implemented using LLMs for intelligent routing:

Advanced Node Features

Named Nodes

You can provide explicit names for nodes:
This is useful when you need to refer to nodes by name in router decisions.

Function Signatures

GraphAI automatically handles parameter mapping, so you only need to declare the parameters your node uses:
The node will only receive the parameters it declares in its signature.

Node Input Validation

GraphAI validates that nodes receive the required parameters:
If a node’s required parameters are missing, the graph execution will fail with a detailed error message.

Next Steps

  • Learn about Graph orchestration to connect your nodes
  • Explore State management for maintaining context
  • Check out Callbacks for implementing streaming responses