Skip to content

build-on-aws/amazon-bedrock-agents-outfit-assistant

Amazon Bedrock Agent Demo

Outfit Assistant

What should I wear today? Source: Titan Image Generator G1 - 'illustration of different weather and outfits'

Note: The demo relies on you having an account with OpenWeatherMap, and an API key to access the Weather service. This service is available on the OpenWeatherMap free plan. Please review any license terms applicable to the service with your legal team and confirm that your use case complies with the terms before proceeding.

Introduction

This repo contains code for a demo of Amazon Bedrock Agents.

In this demo, you will deploy an agent that is able to assist you in selecting the ideal outfit to where given your location.

In a standard deployment, a Large Language Model (LLM) can only reference 'knowledge' that it obtained during training. As such, when prompted to generate up-to-date information such as the current date and time, or getting the weather conditions, the model is left with no alternative other than to hallucinate.

In this demo, you will use Amazon Bedrock Agents to create a solution that enables an LLM to leverage realtime information including the date, time, and weather information. The solution will use this information to make suggestions for what outfit to wear.

This architecture could be easily extended to work with any number of APIs or data sources. If you are able to connect to your data from an Amazon Lambda function, then it can be used with Amazon Bedrock Agents.

Outfit Assistant

Deploying

This is a SAM project. To get started with SAM see here.

Deploy this project using the SAM CLI:

> sam build
> sam deploy --guided

You will be prompted for information as the project is deployed:

  • OpenWeatherAPIKey - A free API key from OpenWeatherMap
  • FoundationModel - The ID of the Amazon Bedrock foundation model to use. (This currently defaults to anthropic.claude-v2:1 Please ensure you have enabled access to this model in the region you are deploying to.)

Testing

  1. Once the project is deployed, you can test the agent in the AWS console. First navigate to Amazon Bedrock in the AWS console.
  2. Navigate to Agents in the left hand menu.
  3. Select the OutfitAssistantAgent agent.
  4. Test the agent with the chat tool on the right hand side of the console.
  5. Here are some messages you can try, note that they don't have to be limited to what outfit to wear:
    • "I am in Brisbane Australia, what should I wear today?"
    • "What is the time?" (May ask you where you are if this is the first message.)
    • "Is it raining in Oslo?"

If you are happy with the performance of the agent, you can deploy it, and access it via your own application.

  1. With the agent selected in the console, select Create Alias, enter a name and description so it's clear at what point in its development it was deployed, and select Create Alias.
  2. To call this agent alias from your own code you will need the agent ID which is shown in the Agent overview section of the console, and the alias ID which is shown in the Aliases section towards the bottom of the agent console page. Note that these IDs are generated by the service, and are not the same as the names you used.
  3. There is sample Python code for invoking your agent in a notebook ./test/agent_test.ipynb. For more information on the Agents for Amazon Bedrock API see here: (https://docs.aws.amazon.com/bedrock/latest/userguide/agents-api.html) and for the AWS Python SDK - Boto3 - see here: (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-agent-runtime.html)

Testing the Lambda function

To test the Lambda function without having to invoke the agent, I have provided you with three test event JSON files that can be pasted into the test event configuration page within the Lambda function. Each test event is formatted as the event will be sent from the agent:

  • ./tests/lambda_event_location.json
  • ./tests/lambda_event_time.json
  • ./tests/lambda__event_weather.json

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.