Creating Subgraphs

This guide assumes familiarity with:

In this guide, you'll learn how to use the Subgraph feature to modularize a graph and separate functionality into distinctive and reusable sections. This feature also reduces the complexity of a graph. For example, you can create a subgraph to calculate a conversion, check a specific attribute like if the power is on, or get date information.

You'll also learn how to do the following:

The example "Set the cooling temperature of the thermostat to 23 degrees celsius" will be used to design an action flow for this voice command, which includes a subgraph that converts an input temperature value from Celsius to Fahrenheit. This will allow Bixby to set the thermostat's cooling temperature to the Fahrenheit equivalent of the Celsius input.

First, add a subgraph to the metadata.

Adding a Subgraph to the Metadata

In order to create and use a subgraph with your device, you have to add the subgraph to the Sub Graph Manifest in the metadata sidebar.

In the metadata sidebar on the left, click the add icon Add Icon on the right of Sub Graph. Add a Subgraph A pop-up for the Sub Graph Manifest appears. Sub Graph Manifest Pop-up

Next, customize the subgraph.

Customizing a Subgraph

This section defines the parameters being passed to your subgraph and what information is returned by it.

  1. In the Sub Graph Manifest, type a Sub Graph Name and click SAVE. This example uses the Sub Graph Name ToFahrenheit. This name shows up under the Call Subgraph Node, which will be called in the main graph. In Sub Graph Manifest, Sub Graph Name Entered As ToFahrenheit
  2. To the right of Parameters, click ADD.
  3. Select Parameters.
  4. Type a Parameter Name for the dynamic input value. This example uses TempInCelsius. Each parameter you add becomes an input port on the Call Subgraph Node.
  5. Select a Parameter Type from the drop-down menu, such as Integer. Parameters Is Selected, Parameter Name Is TempInCelsius, Selected Parameter Type Is Integer
  6. To the right of Triggers, click ADD.
  7. Select Trigger Name.
  8. Type a Trigger Name. This example uses the name main. Each trigger you add becomes a trigger port on the Call Subgraph Node. Triggers Is Selected, Trigger Name Is Main
  9. Check the box for Return value. This ensures that Bixby returns the resulting value from the subgraph. Box to The left of Return value Has a Checkmark in It

Now, you can create an action flow for the subgraph using relevant nodes.

Creating the Subgraph's Action Flow

Subgraphs can be used in any main graphs. With a subgraph, you can perform all functions available in a main graph, with the exception of creating Bixby responses. The subgraph editor doesn't have Response Nodes.

  1. Add a Start Subgraph Node, which initiates the execution of a subgraph's action flow.
  2. To test a subgraph, configure the Start Subgraph Node with a default parameter value by clicking on the node and typing the value under the appropriate parameter. This example uses the parameter value 23 for the TempInCelsius parameter. Start Subgraph Node Configuration Menu With Default TempInCelsius Parameter Value of 23
  3. Add additional nodes as needed to do a process, such as Command or Set Variable. This example uses a Calculation Node configured with the mathematical expression for converting a Celsius temperature value into a Farenheit one. Calculation Node Configuration Menu With Expression Parameter Value of ("C * 9/5) + 32"
  4. Add a SetReturn SubGraph Node, which sets the value the graph will return.
  5. Configure the SetReturn SubGraph Node with appropriate information. This example uses value as the returnName. SetReturn SubGraph Node Configuration Menu With returnName set to value
  6. Add a End Subgraph Node, which sets the port to trigger upon completion of subgraph execution.
  7. Configure the End Subgraph Node with appropriate information. This example uses main as the triggerName. End Subgraph Node Configuration Menu With triggerName Set to Main
  8. Connect the nodes together as needed. This example shows a subgraph for converting a Celsius input value to a Farenheit one. Subgraph Action Flow

Next, test your subgraph.

Testing Your Subgraph

To test the action flow, click the Try It button at the top right of the editor window. The flow editor should look like this:

Successful Testing of Subgraph Action Flow

In this example's test run, Bixby first fetches the input value, which is 23 degrees Celsius. Then, Bixby uses the mathematical expression (C * 9/5) + 32 to convert 23 degrees Celsius to 73.4 degrees Fahrenheit. Then, Bixby returns the value of 73.4 and the execution process finishes.

You can now use the subgraph in your main graph's action flow.

Adding Your Subgraph to The Main Graph

A subgraph, a reusable section of graph containing a specified functionality, can be used in any main graph. Incorporating a subgraph helps reduce the complexity of a main graph by allowing one node, Call Subgraph, to fetch the value returned from the operation performed in a specific subgraph.

To incorporate a subgraph into your main graph's action flow:

  1. If you haven't already, add the relevant voice intent to the Metadata profile for your device.
  2. Under the relevant voice intent, click Graph to switch to the main graph tab for it, which will be labeled with that voice intent.
  3. Add a Start Node.
  4. To test an action flow, configure the Start Node with default parameter values. This example uses a default integer value of 23 for thecoolingTemperature parameter and a default string value of c for the predefinedCoolingTemperatureUnit parameter. Start Node Configuration Menu With Default Input Value of 23
  5. Add a Call Subgraph Node, which invokes a specified subgraph.
  6. Configure the Call Subgraph Node by clicking on the node and selecting a graphId from the drop-down menu. This example calls the ToFahrenheit Sub Graph. Call Subgraph Configuration Menu With graphId Value of ToFahrenheit
  7. Add a Response: Success Node.
  8. Connect the nodes together as needed. This example shows an action path that calls the ToFahrenheit Sub Graph: Main Graph's Action Flow

Testing Your Action Flow

To test the action flow, click the Try It button at the top right of the editor window. The flow editor should look like this:

Successful Testing of Action Flow

In this example's test run, Bixby first fetches the input value, which is 23 degrees Celsius. Next, Bixby fetches the value returned from the subgraph, which is 73.4 degrees Fahrenheit. Then, Bixby sets the device's cooling temperature to 73.4 degrees Fahrenheit. Finally, Bixby responds to the user by saying "SUCCESS."