You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: scenarios/features/bedrock_converse_tool/README.md
+8-9Lines changed: 8 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,14 @@ This example shows how to use AWS SDKs and the Amazon Bedrock Converse API to ca
8
8
9
9
This example illustrates a typical interaction between a generative AI model, an application, and connected tools or APIs to solve a problem or achieve a specific goal. The scenario follows these steps:
10
10
11
-
1. Set up the system prompt and tool configuration.
12
-
2. Specify the AI model to be used (e.g., Anthropic Claude 3 Sonnet).
13
-
3. Create a client to interact with Amazon Bedrock.
14
-
4. Prompt the user for their weather request.
15
-
5. Send the user input including the conversation history to the model.
16
-
6. The model processes the input and determines if a connected tool or API needs to be used. If this is the case, the model returns a tool use request with specific parameters needed to invoke the tool, and a unique tool use ID to correlate tool responses to the request.
17
-
7. The scenario application invokes the tool to fetch weather data, and append the response and tool use ID to the conversation.
18
-
8. The model uses the tool response to generate a final response. If additional tool requests are needed, the process is repeated.
19
-
9. Once the final response is received and printed, the application returns to the prompt.
11
+
1. Set up the system prompt and tool configuration.
12
+
2. Create a client to interact with Amazon Bedrock.
13
+
3. Prompt the user for their weather request.
14
+
4. Send the user input including the conversation history to the model.
15
+
5. The model processes the input and determines if a connected tool or API needs to be used. If this is the case, the model returns a tool use request with specific parameters needed to invoke the tool, and a unique tool use ID to correlate tool responses to the request.
16
+
6. The scenario application invokes the tool to fetch weather data, and append the response and tool use ID to the conversation.
17
+
7. The model uses the tool response to generate a final response. If additional tool requests are needed, the process is repeated. If the max recursion is reached, the conversation is ended.
18
+
8. Once the final response is received and printed, the application returns to the prompt.
Copy file name to clipboardExpand all lines: scenarios/features/bedrock_converse_tool/SPECIFICATION.md
+55-29Lines changed: 55 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,35 +23,61 @@ For an introduction, see the [README.md](README.md).
23
23
24
24
The user's input is used as the starting point for the Bedrock Runtime conversation, and each response is added to an array of messages.
25
25
The model should respond when it needs to invoke the tool, and the application should run the tool and append the response to the conversation.
26
-
This process can be repeated as needed. See the .NET implementation for an example of the processing of the messages. Following is an example of how the conversation could go:
27
-
28
-
1.**Greet the user and provide an overview of the application**:
29
-
- The application is an assistant that provides current weather information for user-specified locations.
30
-
- Users can ask for weather details by providing the location name or coordinates.
31
-
- Example queries are provided, such as "What's the weather like in New York?" and "Current weather for latitude 40.70, longitude -74.01".
32
-
- Users can exit the application by typing 'x' and pressing Enter.
33
-
- The application is not limited to single locations or using English.
34
-
35
-
2.**Handle the user's weather information request**:
36
-
- The user requests weather information.
37
-
- The application looks up the latitude and longitude coordinates for Oklahoma City.
38
-
- The application then uses the Weather_Tool to retrieve the current weather data for those coordinates.
39
-
- The application prints the current weather conditions, including the temperature, wind speed and direction, and a description of the weather.
40
-
41
-
3.**Handle an off-topic user request**:
42
-
- The user requests information about a different topic.
43
-
- The application responds that it is focused on providing current weather information and does not have any data or capabilities related to discussing other topics.
44
-
- The application suggests returning to discussing weather conditions for a particular location.
45
-
46
-
4.**Find the warmest city in a location**:
47
-
- The user requests the warmest city in a state.
48
-
- The application looks up the coordinates for some major cities in the state.
49
-
- The application uses the Weather_Tool to retrieve the current temperature for each city.
50
-
- The application compares the temperatures prints a response.
51
-
52
-
5 **Exit the application**:
53
-
- The user types 'x' and presses Enter to exit the application.
54
-
- The application prints a farewell message and provides a link to more Bedrock examples.
26
+
This process can be repeated as needed until a maximum number of recursions (5). See the .NET implementation for an example of the processing of the messages. Following is an example of how the conversation could go:
27
+
28
+
1. Greet the user and provide an overview of the application.
29
+
1. Handle the user's weather information request:
30
+
1. The user requests weather information. This request is sent to the Bedrock model.
31
+
2. The model response includes a tool request, with a latitude and longitude to provide to the tool.
32
+
3. The application then uses the Weather_Tool to retrieve the current weather data for those coordinates, and appends that response as a tool response to the conversation. The conversation is sent back to the model.
33
+
4. The model responds with either a final response, or a request for more information. The process repeats.
34
+
5. The application prints the final response.
35
+
1. Any off topic requests should be handled according to the system prompt. This prompt is provided below.
36
+
1. The user can type 'x' to exit the application.
37
+
38
+
#### System prompt
39
+
```
40
+
You are a weather assistant that provides current weather data for user-specified locations using only
41
+
the Weather_Tool, which expects latitude and longitude. Infer the coordinates from the location yourself.
42
+
If the user provides coordinates, infer the approximate location and refer to it in your response.
43
+
To use the tool, you strictly apply the provided tool specification.
44
+
45
+
- Explain your step-by-step process, and give brief updates before each step.
46
+
- Only use the Weather_Tool for data. Never guess or make up information.
47
+
- Repeat the tool use for subsequent requests if necessary.
48
+
- If the tool errors, apologize, explain weather is unavailable, and suggest other options.
49
+
- Report temperatures in °C (°F) and wind in km/h (mph). Keep weather reports concise. Sparingly use
50
+
emojis where appropriate.
51
+
- Only respond to weather queries. Remind off-topic users of your purpose.
52
+
- Never claim to search online, access external data, or use tools besides Weather_Tool.
53
+
- Complete the entire process until you have all required data before sending the complete response.
54
+
```
55
+
56
+
#### Weather tool specification
57
+
For strongly typed languages, you will need to use the Bedrock classes provided for tool specification.
58
+
59
+
```
60
+
"toolSpec": {
61
+
"name": "Weather_Tool",
62
+
"description": "Get the current weather for a given location, based on its WGS84 coordinates.",
63
+
"inputSchema": {
64
+
"json": {
65
+
"type": "object",
66
+
"properties": {
67
+
"latitude": {
68
+
"type": "string",
69
+
"description": "Geographical WGS84 latitude of the location.",
70
+
},
71
+
"longitude": {
72
+
"type": "string",
73
+
"description": "Geographical WGS84 longitude of the location.",
0 commit comments