Node types in prompt flow
Amazon Bedrock provides the following node types to build your prompt flow. When you configure a node, you need to provide the following fields:
-
Name – Enter a name for the node.
-
Type – In the console, you drag and drop the type of node to use. In the API, use the
type
field and the corresponding FlowNodeConfiguration in theconfiguration
field. -
Inputs – Provide the following information for each input:
-
Name – A name for the input. Some nodes have pre-defined names or types that you must use. To learn which ones have pre-defined names, see Logic node types.
-
Expression – Define the part of the whole input to use as the individual input. For more information, see Use expressions to define inputs by extracting the relevant part of a whole input in Amazon Bedrock Prompt flows.
-
Type – The data type for the input. When this node is reached at runtime, Amazon Bedrock applies the expression to the whole input and validates that the result matches the data type.
-
-
Outputs – Provide the following information for each output:
-
Name – A name for the output. Some nodes have pre-defined names or types that you must use. To learn which ones have pre-defined names, see Logic node types.
-
Type – The data type for the output. When this node is reached at runtime, Amazon Bedrock validates that the node output matches the data type.
-
-
Configuration – In the console, you define node-specific fields at the top of the node. In the API, use the appropriate FlowNodeConfiguration and fill in its fields.
Each node type is described below and its structure in the API is provided. Expand a section to learn more about that node type.
Nodes for controlling prompt flow logic
Use the following node types to control the logic of your prompt flow.
Every prompt flow contains only one flow input node and must begin with it. The flow input node takes the content
from the InvokeFlow
request, validates the data type, and sends it to the following node.
The following shows the general structure of an input FlowNode object in the API:
{ "name": "string", "type": "Input", "outputs": [ { "name": "document", "type": "String | Number | Boolean | Object | Array", } ], "configuration": { "input": CONTEXT-DEPENDENT } }
A flow output node extracts the input data from the previous node, based on the defined expression, and returns it. In the console, the output is the response returned after choosing Run in the test window. In the API, the output is returned in the content
field of the flowOutputEvent
in the InvokeFlow
response. A prompt flow can have multiple flow output nodes.
A flow can have multiple flow output nodes if there are multiple branches in the flow.
The following shows the general structure of an output FlowNode object:
{ "name": "string", "type": "Output", "inputs": [ { "name": "document", "type": "String | Number | Boolean | Object | Array", "expression": "string" } ], "configuration": { "output": CONTEXT-DEPENDENT } }
A condition node sends data from the previous node to different nodes, depending on the conditions that are defined. A condition node can take multiple inputs.
For an example, see Create a flow with a condition node.
To define a condition node
-
Add as many inputs as you need to evaluate the conditions you plan to add.
-
Enter a name for each input, specify the type to expect, and write an expression to extract the relevant part from the whole input.
-
Connect each input to the relevant output from an upstream node.
-
Add as many conditions as you need.
-
For each condition:
-
Enter a name for the condition.
-
Use relational and logical operators to define a condition that compares inputs to other inputs or to a constant.
Note
Conditions are evaluated in order. If more than one condition is satisfied, the earlier condition takes precedence.
-
Connect each condition to the downstream node to which you want to send the data if that condition is fulfilled.
-
Condition expressions
To define a condition, you refer to an input by its name and compare it to a value using any of the following relational operators:
Operator | Meaning | Supported data types | Example usage | Example meaning |
---|---|---|---|---|
== | Equal to (the data type must also be equal) | String, Number, Boolean | A == B | If A is equal to B |
!= | Not equal to | String, Number, Boolean | A != B | If A isn't equal to B |
> | Greater than | Number | A > B | If A is greater than B |
>= | Greater than or equal to | Number | A >= B | If A is greater than or equal to B |
< | Less than | Number | A < B | If A is less than B |
<= | Less than or equal to | Number | A <= B | If A is less than or equal to B |
You can compare inputs to other inputs or to a constant in a conditional
expression. For example, if you have a numerical input called profit
and another one called expenses
, both profit > expenses
or profit <= 1000
are valid expressions.
You can use the following logical operators to combine expressions for more complex conditions. We recommend that you use parentheses to resolve ambiguities in grouping of expressions:
Operator | Meaning | Example usage | Example meaning |
---|---|---|---|
and | Both expressions are true | (A < B) and (C == 1) | If both expressions are true:
|
or | At least one expression is true | (A != 2) or (B > C) | If either expressions is true:
|
not | The expression isn't true | not (A > B) | If A isn't greater than B (equivalent to A <= B) |
In the API, you define the following in the definition
field when you send a CreateFlow or UpdateFlow request:
-
A condition FlowNode object in the
nodes
array. The general format is as follows (note that condition nodes don't haveoutputs
):{ "name": "string", "type": "Condition", "inputs": [ { "name": "string", "type": "String | Number | Boolean | Object | Array", "expression": "string" } ], "configuration": { "condition": { "conditions": [ { "name": "string", "expression": "string" }, ... ] } } }
-
For each input into the condition node, a FlowConnection object in the
connections
array. Include a FlowDataConnectionConfiguration object in theconfiguration
field of theFlowConnection
object. The general format of theFlowConnection
object is as follows:{ "name": "string", "source": "string", "target": "string", "type": "Data", "configuration": { "data": { "sourceOutput": "string", "expression": "string" } } }
-
For each condition (including the default condition) in the condition node, a FlowConnection object in the
connections
array. Include a FlowConditionalConnectionConfiguration object in theconfiguration
field of theFlowConnection
object. The general format of the FlowConnection object is as follows:{ "name": "string", "source": "string", "target": "string", "type": "Data", "configuration": { "condition": "default", "condition": "string" ... } }
Use relational and logical operators to define the
condition
that connects this conditionsource
node to atarget
node downstream. For the default condition, specify the condition asdefault
.
An iterator node takes an array and iteratively returns its items as output to the downstream node. The inputs to the iterator node are processed one by one and not in parallel with each other. The flow output node returns the final result for each input in a different response. You can use also use a collector node downstream from the iterator node to collect the iterated responses and return them as an array, in addition to the size of the array.
The following shows the general structure of an iterator FlowNode object:
{ "name": "string", "type": "Iterator", "inputs": [ { "name": "array", "type": "String | Number | Boolean | Object | Array", "expression": "string" } ], "outputs": [ { "name": "arrayItem", "type": "String | Number | Boolean | Object | Array", }, { "name": "arraySize", "type": "Number" } ], "configuration": { "iterator": CONTEXT-DEPENDENT } }
A collector node takes an iterated input, in addition to the size that the array will be, and returns them as an array. You can use a collector node downstream from an iterator node to collect the iterated items after sending them through some nodes.
The following shows the general structure of a collector FlowNode object:
{ "name": "string", "type": "Collector", "inputs": [ { "name": "arrayItem", "type": "String | Number | Boolean | Object | Array", "expression": "string" }, { "name": "arraySize", "type": "Number" } ], "outputs": [ { "name": "collectedArray", "type": "Array" }, ], "configuration": { "collector": CONTEXT-DEPENDENT } }
Nodes for handling data in the prompt flow
Use the following node types to handle data in your prompt flow:
A prompt node defines a prompt to use in the flow. You can use a prompt from Prompt management or define one inline in the node. For more information, see Construct and store reusable prompts with Prompt management in Amazon Bedrock.
For an example, see Get started with example prompt flows.
The inputs to the prompt node are values to fill in the variables. The output is the generated response from the model.
The following shows the general structure of a prompt FlowNode object:
{ "name": "string", "type": "prompt", "inputs": [ { "name": "content", "type": "String | Number | Boolean | Object | Array", "expression": "string" }, ... ], "outputs": [ { "name": "modelCompletion", "type": "String" } ], "configuration": { "prompt": { "sourceConfiguration": PromptFlowNodeSourceConfiguration object (see below) } } }
The PromptFlowNodeSourceConfiguration object depends on if you use a prompt from Prompt management or if you define it inline:
-
If you use a prompt from Prompt management, the object should be in the following general structure:
{ "resource": { "promptArn": "string" } }
-
If you define a prompt inline, follow the guidance for defining a variant in the API tab of Create a prompt using Prompt management (note that there is no
name
field in this object, however). The object you use should be in the following general structure:{ "inline": { "modelId": "string", "templateType": "TEXT", "templateConfiguration": { "text": { "text": "string", "inputVariables": [ { "name": "string" }, ... ] } }, "inferenceConfiguration": { "text": { "maxTokens": int, "stopSequences": ["string", ...], "temperature": float, "topP": float } }, "additionalModelRequestFields": { "key": "value", ... } } }
An agent node lets you send a prompt to an agent, which orchestrates between FMs and associated resources to identify and carry out actions for an end-user. For more information, see Automate tasks in your application using conversational agents.
In the configuration, specify the Amazon Resource Name (ARN) of the alias of the agent to use. The inputs into the node are the prompt for the agent and any associated prompt or session attributes. The node returns the agent's response as an output.
Note
Currently, the agent doesn't support multi-turn invocations. You can't configure return of control for the agent in a flow.
The following shows the general structure of an agent FlowNode object:
{ "name": "string", "type": "Agent", "inputs": [ { "name": "agentInputText" "type": "String | Number | Boolean | Object | Array", "expression": "string" }, { "name": "promptAttributes" "type": "Object", "expression": "string" }, { "name": "sessionAttributes" "type": "Object", "expression": "string" } ], "outputs": [ { "name": "agentResponse", "type": "String" } ], "configuration": { "agent": { "agentAliasArn": "string" } } }
A knowledge base node lets you send a query to a knowledge base. For more information, see Retrieve data and generate AI responses with knowledge bases.
In the configuration, provide the knowledgeBaseId
minimally. You can optionally include the following fields depending on your use case:
-
modelId
– Include a model ID to use if you want to generate a response based on the retrieved results. To return the retrieved results as an array, omit the model ID. -
guardrailConfiguration
– Include the ID or ARN of the guardrail, defined in Amazon Bedrock Guardrails in theguardrailIdentifier
field and the version of the guardrail in theguardrailVersion
field.Note
Guardrails can only be applied when using
RetrieveAndGenerate
in a knowledge base node.
The input into the node is the query to the knowledge base. The output is either the model response, as a string, or an array of the retrieved results.
The following shows the general structure of a knowledge base FlowNode object:
{ "name": "string", "type": "KnowledgeBase", "inputs": [ { "name": "retrievalQuery", "type": "String", "expression": "string" } ], "outputs": [ { "name": "retrievalResults", "type": "Array | String" } ], "configuration": { "knowledgeBase": { "knowledgeBaseId": "string", "modelId": "string" } } }
An S3 storage node lets you store data in the flow to an Amazon S3 location. In the configuration, you specify the S3 bucket to use for data storage. The inputs into the node are the content to store and the object key. The node returns the URI of the S3 location as its output.
The following shows the general structure of an S3 storage FlowNode object:
{ "name": "string", "type": "Storage", "inputs": [ { "name": "content", "type": "String | Number | Boolean | Object | Array", "expression": "string" }, { "name": "objectKey", "type": "String", "expression": "string" } ], "outputs": [ { "name": "s3Uri", "type": "String" } ], "configuration": { "retrieval": { "serviceConfiguration": { "s3": { "bucketName": "string" } } } } }
An S3 retrieval node lets you retrieve data from an Amazon S3 location to introduce to the flow. In the configuration, you specify the S3 bucket from which to retrieve data. The input into the node is the object key. The node returns the content in the S3 location as the output.
Note
Currently, the data in the S3 location must be a UTF-8 encoded string.
The following shows the general structure of an S3 retrieval FlowNode object:
{ "name": "string", "type": "Retrieval", "inputs": [ { "name": "objectKey", "type": "String", "expression": "string" } ], "outputs": [ { "name": "s3Content", "type": "String" } ], "configuration": { "retrieval": { "serviceConfiguration": { "s3": { "bucketName": "string" } } } } }
A Lambda function node lets you call a Lambda function in which you can define code to carry out business logic. When you include a Lambda node in a prompt flow, Amazon Bedrock sends an input event to the Lambda function that you specify.
In the configuration, specify the Amazon Resource Name (ARN) of the Lambda function. Define inputs to send in the Lambda input event. You can write code based on these inputs and define what the function returns. The function response is returned in the output.
The following shows the general structure of a Λ function FlowNode object:
{ "name": "string", "type": "LambdaFunction", "inputs": [ { "name": "string", "type": "String | Number | Boolean | Object | Array", "expression": "string" }, ... ], "outputs": [ { "name": "functionResponse", "type": "String | Number | Boolean | Object | Array" } ], "configuration": { "lambdaFunction": { "lambdaArn": "string" } } }
Lambda input event for a prompt flow
The input event sent to a Lambda function in a Lambda node is of the following format:
{ "messageVersion": "1.0", "flow": { "flowArn": "string", "flowAliasArn": "string" }, "node": { "name": "string", "nodeInputs": [ { "name": "string", "type": "String | Number | Boolean | Object | Array", "expression": "string", "value": ... }, ... ] } }
The fields for each input match the fields that you specify when defining the Lambda node, while the value of the value
field is populated with the whole input into the node after being resolved by the expression. For example, if the whole input into the node is [1, 2, 3]
and the expression is $.data[1]
, the value sent in the input event to the Lambda function would be 2
.
For more information about events in Lambda, see Lambda concepts in the AWS Lambda Developer Guide.
Lambda response for a prompt flow
When you write a Lambda function, you define the response returned by it. This response is returned to your prompt flow as the output of the Lambda node.
Note
The Lex node relies on the Amazon Lex service, which might store and use customer content for the development and continuous improvement of other AWS services. As an AWS customer, you can opt out of having your content stored or used for service improvements. To learn how to implement an opt-out policy for Amazon Lex, see AI services opt-out policies.
A Lex node lets you call a Amazon Lex bot to process an utterance using natural language processing and to identify an intent, based on the bot definition. For more information, see Amazon Lex Developer Guide.
In the configuration, specify the Amazon Resource Name (ARN) of the alias of the bot to use and the locale to use. The inputs into the node are the utterance and any accompanying request attributes or session attributes. The node returns the identified intent as the output.
Note
Currently, the Lex node doesn't support multi-turn conversations. One Lex node can only process one utterance.
The following shows the general structure of a Lex FlowNode object:
{ "name": "string", "type": "Lex", "inputs": [ { "name": "inputText", "type": "String | Number | Boolean | Object | Array", "expression": "string" }, { "name": "requestAttributes", "type": "Object", "expression": "string" }, { "name": "sessionAttributes", "type": "Object", "expression": "string" } ], "outputs": [ { "name": "predictedIntent", "type": "String" } ], "configuration": { "lex": { "botAliasArn": "string", "localeId": "string" } } }
Summary tables for node types
The following tables summarize the inputs and outputs that are allowed for each node type. Note the following:
-
If a name is marked as Any, you can provide any string as the name. Otherwise, you must use the value specified in the table.
-
If a type is marked as Any, you can specify any of the following data types: String, Number, Boolean, Object, Array. Otherwise, you must use the type specified in the table.
-
Currently, only the Condition, Prompt, and Lambda function nodes allow multiple inputs that you can define yourself.
Input info | Output info | |||||
---|---|---|---|---|---|---|
Node type | Input | Name | Type | Output | Name | Type |
Input | N/A | N/A | N/A | The content field in the InvokeFlow request. |
document |
Any |
Output | Data to return in the InvokeFlow response. |
document |
Any | N/A | N/A | N/A |
Condition |
Data to send based on a condition. (multiple inputs allowed) |
Any | Any |
Data to send based on a condition. (specify conditions for different paths) |
Any | Any |
Iterator | An array for which you want to apply the following node(s) iteratively to each member. | array |
Array | Each item from the array | arrayItem |
Any |
The size of the input array | arraySize |
Number | ||||
Collector | An iteration that you want to consolidate into an array. | arrayItem |
Any | An array with all the outputs from the previous node appended. | collectedArray |
Array |
The size of the output array | arraySize |
Number |
Input info | Output info | |||||
---|---|---|---|---|---|---|
Node type | Input | Name | Type | Output | Name | Type |
Prompt |
A value to fill in a variable in the prompt. (multiple inputs allowed) |
|
Any | The response returned by the model. | modelCompletion |
String |
S3 storage | Data to store in an S3 bucket. | content |
Any | The URI of the S3 location. | s3Uri |
String |
The object key to use for the S3 object. | objectKey |
String | ||||
S3 retrieval | The object key for the S3 object | objectKey |
String | The data to retrieve from an S3 bucket. | s3Content |
Any |
Agent | The prompt to send to the agent. | agentInputText |
String | The response returned from the agent. | agentResponse |
String |
Any prompt attributes to send alongside the prompt. | promptAttributes |
Object | ||||
Any session attributes to send alongside the prompt. | sessionAttributes |
Object | ||||
Knowledge base | The query to send to the knowledge base. | retrievalQuery |
String | The returned results or generated response from the knowledge base. | retrievalResults |
Array |
Lambda function |
Data to send to the function. (multiple inputs allowed) |
Any | The response returned from the function. | functionResponse |
Any | |
Lex | The utterance to send to the bot. | inputText |
String | The intent that the bot predicts for the utterance. | predictedIntent |
String |
Any request attributes to send alongside the utterance. | requestAttributes |
Object | ||||
Any session attributes to send alongside the utterance. | sessionAttributes |
Object |