Skip to main content

Subgraph Node

Subgraph Node Screenshot

Overview

The Subgraph Node allows you to execute another graph within the current graph. This is useful for reusing logic across multiple graphs, or for breaking down complex graphs into smaller, more manageable pieces.

The inputs and outputs of the Subgraph Node are defined by Graph Input Nodes and Graph Output Nodes within the subgraph. The Subgraph Node will automatically update its inputs and outputs to match those of the selected subgraph.

The Subgraph Node also has an optional error output. If enabled, any errors that occur while executing the subgraph will be caught and output from the error output port. If not enabled, errors will cause the entire graph to fail.

Inputs

TitleData TypeDescriptionDefault ValueNotes
(custom names)AnyThe input values passed into the subgraph. Dynamic based on the inputs configured in the subgraph.N/AAlways accepts any data type.

Example 1: Reuse a graph in multiple places

  1. Create a new graph in your project, and add a Graph Input Node and a Graph Output Node to it. Connect the Graph Input Node to a Text Node and connect that node to Graph Output Node.
  2. Update the Text node to have the text {{input}} Hi, From Subgraph.
  3. In your main graph, add a Subgraph Node. In the editor settings, set the Graph to the graph you created in step 1.
  4. Connect a Text Node to the input of the Subgraph Node.
  5. Set the Text of the Text Node to Hello Subgraph!.
  6. Run the graph. Note that the text is passed through the subgraph and back to the main graph with the text from the subgraph appended to it.

Subgraph Node Example 1a Subgraph Node Example 1b

Example 2: Handle errors in a subgraph

  1. Using the same graphs from Example 1, in the subgraph add a vector store node.
  2. Connect all the outputs from the text node to the vector store node.
  3. This will cause the Vector Store Node to Error
  4. In your main graph, add a Subgraph Node. In the editor settings enable Use Error Output.
  5. Connect Text Nodes to both outputs of the Subgraph Node.
  6. Run the graph. Note that the error is output on the Error port of the Subgraph Node, and the Output port is not ran.

Subgraph Node Example 2a Subgraph Node Example 2b

Error Handling

If the subgraph errors, then the Subgraph Node will error. If you want to handle errors in the graph, then you can enable the Use Error Output setting. This will cause the Subgraph Node to not error, but instead pass the error message to the Error output port. If the Error port is populated, then the Result port will not be ran. You can use an If Node to check if the Error port is populated, and handle the error accordingly.

FAQ

Q: Can I use the Subgraph Node to execute a graph in a different project?

A: No, the Subgraph Node can only execute graphs within the same project.

Q: Can I use the Subgraph Node to execute a graph in a loop?

A: Yes, you can use a Loop Controller Node to execute a Subgraph Node in a loop. Each iteration of the loop will execute the subgraph with the current loop value as an input.

Q: Can I use the Subgraph Node to execute a graph conditionally?

A: Yes, you can use an If Node to conditionally execute a Subgraph Node. If the condition is false, the Subgraph Node will not be executed.

See Also