Get started with example flows - Amazon Bedrock

Get started with example flows

This topic provides some example flows that you can try out to get started with using Amazon Bedrock Flows. Expand an example to see how to build it in the Amazon Bedrock console:

The following image shows a flow consisting of a single prompt, defined inline in the node, that builds a playlist of songs, given a genre and the number of songs to include in the playlist.

Example of using a prompt node with two variables.
To build and test this flow in the console
  1. Follow the steps under To create a flow in the Console tab at Create a flow in Amazon Bedrock. Enter the Flow builder.

  2. Set up the prompt node by doing the following:

    1. From the Flow builder left pane, select the Nodes tab.

    2. Drag a Prompt node into your flow in the center pane.

    3. Select the Configure tab in the Flow builder pane.

    4. Enter MakePlaylist as the Node name.

    5. Choose Define in node.

    6. Set up the following configurations for the prompt:

      1. Under Select model, select a model to run inference on the prompt.

      2. In the Message text box, enter Make me a {{genre}} playlist consisting of the following number of songs: {{number}}.. This creates two variables that will appear as inputs into the node.

      3. (Optional) Modify the Inference configurations.

    7. Expand the Inputs section. The names for the inputs are prefilled by the variables in the prompt message. Configure the inputs as follows:

      Name Type Expression
      genre String $.data.genre
      number Number $.data.number

      This configuration means that the prompt node expects a JSON object containing a field called genre that will be mapped to the genre input and a field called number that will be mapped to the number input.

    8. You can't modify the Output. It will be the response from the model, returned as a string.

  3. Choose the Flow input node and select the Configure tab. Select Object as the Type. This means that flow invocation will expect to receive a JSON object.

  4. Connect your nodes to complete the flow by doing the following:

    1. Drag a connection from the output node of the Flow input node to the genre input in the MakePlaylist prompt node.

    2. Drag a connection from the output node of the Flow input node to the number input in the MakePlaylist prompt node.

    3. Drag a connection from the output node of the modelCompletion output in the MakePlaylist prompt node to the document input in the Flow output node.

  5. Choose Save to save your flow. Your flow should now be prepared for testing.

  6. Test your flow by entering the following JSON object is the Test flow pane on the right. Choose Run and the flow should return a model response.

    { "genre": "pop", "number": 3 }

The following image shows a flow with one condition node returns one of three possible values based on the condition that is fulfilled:

Example of using a condition node with two conditions.
To build and test this flow in the console:
  1. Follow the steps under To create a flow in the Console tab at Create a flow in Amazon Bedrock. Enter the Flow builder.

  2. Set up the condition node by doing the following:

    1. From the Flow builder left pane, select the Nodes tab.

    2. Drag a Condition node into your flow in the center pane.

    3. Select the Configure tab in the Flow builder pane.

    4. Expand the Inputs section. Configure the inputs as follows:

      Name Type Expression
      retailPrice Number $.data.retailPrice
      marketPrice Number $.data.marketPrice
      type String $.data.type

      This configuration means that the condition node expects a JSON object that contains the fields retailPrice, marketPrice, and type.

    5. Configure the conditions by doing the following:

      1. In the Conditions section, optionally change the name of the condition. Then add the following condition in the Condition text box: (retailPrice > 10) and (type == "produce").

      2. Add a second condition by choosing Add condition. Optionally change the name of the second condition. Then add the following condition in the Condition text box: (retailPrice < marketPrice).

  3. Choose the Flow input node and select the Configure tab. Select Object as the Type. This means that flow invocation will expect to receive a JSON object.

  4. Add flow output nodes so that you have three in total. Configure them as follows in the Configure tab of the Flow builder pane of each flow output node:

    1. Set the input type of the first flow output node as String and the expression as $.data.action[0] to return the first value in the array in the action field of the incoming object.

    2. Set the input type of the second flow output node as String and the expression as $.data.action[1] to return the second value in the array in the action field of the incoming object.

    3. Set the input type of the third flow output node as String and the expression as $.data.action[2] to return the third value in the array in the action field of the incoming object.

  5. Connect the first condition to the first flow output node, the second condition to the second flow output node, and the default condition to the third flow output node.

  6. Connect the inputs and outputs in all the nodes to complete the flow by doing the following:

    1. Drag a connection from the output node of the Flow input node to the retailPrice input in the condition node.

    2. Drag a connection from the output node of the Flow input node to the marketPrice input in the condition node.

    3. Drag a connection from the output node of the Flow input node to the type input in the condition node.

    4. Drag a connection from the output of the Flow input node to the document input in each of the three output nodes.

  7. Choose Save to save your flow. Your flow should now be prepared for testing.

  8. Test your flow by entering the following JSON objects is the Test flow pane on the right. Choose Run for each input:

    1. The following object fulfills the first condition (the retailPrice is more than 10 and the type is "produce") and returns the first value in action ("don't buy"):

      { "retailPrice": 11, "marketPrice": 12, "type": "produce", "action": ["don't buy", "buy", "undecided"] }
      Note

      Even though both the first and second conditions are fulfilled, the first condition takes precedence since it comes first.

    2. The following object fulfills the second condition (the retailPrice is less than the marketPrice) and returns the second value in action ("buy"):

      { "retailPrice": 11, "marketPrice": 12, "type": "meat", "action": ["don't buy", "buy", "undecided"] }
    3. The following object fulfills neither the first condition (the retailPrice is more than 10, but the type is not "produce") nor the second condition (the retailPrice isn't less than the marketPrice), so the third value in action ("undecided") is returned:

      { "retailPrice": 11, "marketPrice": 11, "type": "meat", "action": ["don't buy", "buy", "undecided"] }