Multi-turn conversations with Amazon Bedrock Flows
What are agents? Why are they helpful? And how can we use Amazon Bedrock Flows to help!
- A travel agent created through Amazon Bedrock Agents
- A travel assistant flow created through Amazon Bedrock Flows
- Head to the Amazon Bedrock Console, and choose Agents from Builder tools in the navigation paneImage not found
Selecting Agents in the console - Create the agent with the name of your choice and if you'd like, give a description
- In the Agent builder section select a foundation model to power the agent. In this case I'm selecting Anthropic's Claude 3.5 Sonnet v2.
- Under Instructions for the Agent we are creating an instruction set that the agent persona will follow. In this sample travel assistant we want to configure an agent that will help a user book a flight when it has context of a users origin, destination and date/time.
- I use the following instruction:
To book a flight, you should know the origin and destination airports and the day and time the flight takes off.
Image not foundSelect foundation model and set the instructions
- In Additional settings make sure User input is enabled so the agent can prompt user for additional information if needed.Image not found
Enable user input in the additional settings - In Memory select Enabled, we do this so the agent can store a session in memory and continue to have user context when a session ends and we reference it again laterImage not found
Enable memory - Now we'll move on to create an action group with 2 functions. Action groups help organize what tasks the agent will help with and sets up the logic they'll use. The business logic of an action group lives in a Lambda function which you create and point agents to.
- Give a name to the action group, I'll use
search_book_flights
, and select Define with function details. - Next we'll select the option which has the wizard Quick create a new Lambda function.Image not found
Select the action group type and creation of Lambda function - For the first action group function we'll define a function that can search for sets of flights based on origin, destination and a date. The three parameters we set are string types,
date
,origin_airport
, anddestination_airport
with the option of required set to true.Image not foundCreate the first function of the action group - The second action group function defines how to book a flight given the origin, destination and the date and time. The four parameters we set are string types,
date
,time
,origin_airport
, anddestination_airport
with the option of required set to true.Image not foundCreate the second function of the action group
- Complete the agent creation with Create.
- Once complete you can access the Lambda function created by the wizard and edit its contents. I use the Python example described in this blog which simulates flights and times for testing purposes.
- Let's head back to the Amazon Bedrock Console and this time select Flows from Builder tools in the navigation pane.
- Click Create flow and enter a name, allow for a new service role unless you've done this before and have one ready.
- Once created you will be redirected to the flow builder GUI to start stringing together elements.
- Let's pause here and quickly discuss the expected outcome. What we want to demonstrate is a travel assistant workflow in which a user can ask generic questions about a city and be given responses powered by an LLM. The user can also inquire about flights to these destinations and if they decide to they can ask the agent to book a particular flight. The following steps outline how we build a Bedrock Flow to implement this functionality.
- In the Flow builder panel select and drag the Prompts node to your workspace. When selected the configuration pane opens and we can customize the node.
- Give the prompt node a name, I use
user_intent
. Select Define in node to set the logic directly from this pane. Select a model, I useNova Lite 1.0.
This prompt node will be the first entry point for a user using this assistant, it needs to classify whether the user is asking generic questions about a city or looking to book a flight. To do this we give the node a persona and instructions. I use the following:You are a query classifier. Analyze the {{input}} and respond with a single letter: A: Travel planning/booking queries for hotel and flights Example: "Find flights to London" B: Destination information queries Example: "What's the weather in Paris?" Return only 'A' or 'B' based on the primary intent.
- To finish the prompt node setup we can change the Inference configurations to manipulate the temperature.
- The scale is from 0-1 and indicates how much "creativity" or randomness you want the model to take. The closer to 1 the more likely the model is to hallucinate, but depending on the use case such as writing, brainstorming, etc a more random approach can lead to better results.
- In this case, I set the temperature to 0.1 so the responses are more focused/deterministic.
- Next, I create a condition node that will take as input the category letter the
user_intent
node generates.- Drag and drop the Condition node to the workspace. Name the node, I use
Book_or_Questions
. - Leave the input formats as default. Next, I name the condition and define it using
Condition: categoryLetter=="A"
. - At this point the workspace should look like so: flow input -> prompt node -> condition node.Image not found
Bedrock Flows with prompt node and condition nodes configured - Currently a user interacting with this flow can enter their query and the query is classified into either "A- booking support" or "B- travel destination questions". We now need to build out support for the flow for "B- travel destination questions" which requires we create another prompt node that uses a LLM to respond.
- Drag and drop a Prompts node to your workspace.
- Finally we get to the step where we connect the agent created in the previous section. As a reminder my agent was called
travel-agent
. - If everything is linked up correctly the flow diagram should look similar to this. Double check the input/output connections to confirm everything looks right, I had some lines incorrectly linked which caused the test to fail later on and a debugging nightmare.Image not found
Final Bedrock Flow diagram
- GitHub- Bedrock Flows Samples
- Blog- Setting up Agents
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.