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.
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.
This is a SAM project. Deploy this project using the SAM CLI.
> sam build
> sam deploy --guided --capabilities='CAPABILITY_NAMED_IAM'
To test the Lambda function without having to create an agent first, or simply to test 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
- With the agent selected in the console, select
Test
. - A chat window will appear on the right hand side. You can now chat with your agent. 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.
- 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 selectCreate Alias
. - 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 theAliases
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. - 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 Python see here: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-agent-runtime.html