跳转到主要内容
Chinese, Simplified

category

生成性人工智能能力的整合正在推动许多行业的变革。尽管天气信息可以通过多种渠道获取,但严重依赖气象数据的企业需要强大且可扩展的解决方案来有效管理和使用这些关键见解,并减少手动流程。该解决方案演示了如何创建一个由人工智能驱动的虚拟气象学家,可以用自然语言回答复杂的天气相关查询。我们使用各种AWS服务来部署一个完整的解决方案,您可以使用该解决方案与提供实时天气信息的API进行交互。在这个解决方案中,我们使用亚马逊基岩代理。

Amazon Bedrock Agents有助于简化工作流程并自动化重复性任务。Amazon Bedrock Agents可以安全地连接到您公司的数据源,并通过准确的响应来增强用户的请求。您可以使用Amazon Bedrock代理来构建一个根据您的需求量身定制的操作模式,在代理启动指定操作时授予您控制权。这种多功能的方法使您能够在首选后端服务中无缝集成和执行业务逻辑,从而实现功能和灵活性的紧密结合。在整个交互过程中也有记忆保留,允许更个性化的用户体验。

在这篇文章中,我们介绍了一种通过结合Amazon Bedrock Agents和基础模型(FM)来部署人工智能代理的简化方法。我们将指导您完成配置代理和实现虚拟气象学家提供准确的天气相关响应所需的特定逻辑的过程。此外,我们还使用各种AWS服务,包括用于托管前端的AWS Amplify、用于处理请求逻辑的AWS Lambda函数、用于用户身份验证的Amazon Cognito以及用于控制对代理访问的AWS身份和访问管理(IAM)。

解决方案概述

该图给出了概述并突出了关键组件。该架构使用Amazon Cognito进行用户身份验证,并使用Amplify作为我们前端应用程序的托管环境。Amazon Bedrock代理将用户查询的详细信息转发给操作组,操作组进一步调用自定义Lambda函数。每个动作组和Lambda函数都处理一个特定的任务:

  • 地理坐标–处理地理坐标(geo坐标)以获取特定位置的详细信息
  • 天气–收集所提供位置的天气信息
  • date time–获取当前日期和时间

Prerequisites

You must have the following in place to complete the solution in this post:

Deploy solution resources using AWS CloudFormation

When you run the AWS CloudFormation template, the following resources are deployed (note that costs will be incurred for the AWS resources used):

  • Amazon Cognito resources:
  • Lambda resources:
    • Function – <Stack name>-geo-coordinates-<auto-generated>
    • Function – <Stack name>-weather-<auto-generated>
    • Function – <Stack name>-date-time-<auto-generated>
  • Amazon Bedrock Agents: virtual-meteorologist
    • Action groups (1) – obtain-latitude-longitude-from-place-name
    • Action groups (2) – obtain-weather-information-with-coordinates
    • Action groups (3) – get-current-date-time-from-timezone

After you deploy the CloudFormation template, copy the following from the Outputs tab on the CloudFormation console to be used during the configuration of your application after it’s deployed in AWS Amplify.

  • AWSRegion
  • BedrockAgentAliasId
  • BedrockAgentId
  • BedrockAgentName
  • IdentityPoolId
  • UserPoolClientId
  • UserPoolId

CloudFormation Output Tab

Deploy the AWS Amplify application

You need to manually deploy the Amplify application using the front-end code found on GitHub. Complete the following steps:

  1. Download the front-end code AWS-Amplify-Frontend.zip from GitHub.
  2. Use the .zip file to manually deploy the application in Amplify.
  3. Return to the Amplify page and use the domain it automatically generated to access the application.

Use Amazon Cognito for user authentication

Amazon Cognito is an identity service that you can use to authenticate and authorize users. We use Amazon Cognito in our solution to verify the user before they can use the application. We also use identity pool to provide temporary AWS credentials for the user while they interact with Amazon Bedrock API.

Use Amazon Bedrock Agents to automate application tasks

With Amazon Bedrock Agents, you can build and configure autonomous agents in your application. An agent helps your end users complete actions based on organization data and user input. Agents orchestrate interactions between FMs, data sources, software applications, and user conversations.

Use action group to define actions that Amazon Bedrock agents perform

An action group defines a set of related actions that an Amazon Bedrock agent can perform to assist users. When configuring an action group, you have options for handling user-provided information, including adding user input to the agent’s action group, passing data to a Lambda function for custom business logic, or returning control directly through the InvokeAgent response. In our application, we created three action groups to give the Amazon Bedrock agent these essential functionalities: retrieving coordinates for specific locations, obtaining current date and time information, and fetching weather data for given locations. These action groups enable the agent to access and process crucial information, enhancing its ability to respond accurately and comprehensively to user queries related to location-based services and weather conditions.

Use Lambda for Amazon Bedrock action group

As part of this solution, three Lambda functions are deployed to support the action groups defined for our Amazon Bedrock agent:

  1. Location coordinates Lambda function – This function is triggered by the obtain-latitude-longitude-from-place-name action group. It takes a place name as input and returns the corresponding latitude and longitude coordinates. The function uses a geocoding service or database to perform this lookup.
  2. Date and time Lambda function – Invoked by the get-current-date-time-from-timezone action group, this function provides the current date and time information.
  3. Weather information Lambda function – This function is called by the obtain-weather-information-with-coordinates action group. It accepts geo-coordinates from the first Lambda function and returns current weather conditions and forecasts for the specified area. This Lambda function used a weather API to fetch up-to-date meteorological data.

Each of these Lambda functions receives an input event containing relevant metadata and populated fields from the Amazon Bedrock agent’s API operation or function parameters. The functions process this input, perform their specific tasks, and return a response with the required information. This response is then used by the Amazon Bedrock agent to formulate its reply to the user’s query. By using these Lambda functions, our Amazon Bedrock agent gains the ability to access external data sources and perform complex computations, significantly enhancing its capabilities in handling user requests related to location, time, and weather information.

Use AWS Amplify for front-end code

Amplify offers a development environment for building secure, scalable mobile and web applications. Developers can focus on their code rather than worrying about the underlying infrastructure. Amplify also integrates with many Git providers. For this solution, we manually upload our front-end code using the method outlined earlier in this post.

Application walkthrough

Navigate to the URL provided after you created the application in Amplify. Upon accessing the application URL, you’ll be prompted to provide information related to Amazon Cognito and Amazon Bedrock Agents. This information is required to securely authenticate users and allow the front end to interact with the Amazon Bedrock agent. It enables the application to manage user sessions and make authorized API calls to AWS services on behalf of the user.

You can enter information with the values you collected from the CloudFormation stack outputs. You’ll be required to enter the following fields, as shown in the following screenshot:

  • User Pool ID
  • User Pool ClientID
  • Identity Pool ID
  • Region
  • Agent Name
  • Agent ID
  • Agent Alias ID
  • Region

Front-end configuration Page

You need to sign in with your username and password. A temporary password was automatically generated during deployment and sent to the email address you provided when launching the CloudFormation template. At first sign-in attempt, you’ll be asked to reset your password, as shown in the following video.

virtual-meteorologist-figure-4

Now you can start asking questions in the application, for example, “Can we do barbecue today in Dallas, TX?” In a few seconds, the application will provide you detailed results mentioning if you can do barbecue in Dallas, TX. The following video shows this chat.

virtual-meteorologist-figure-5

Example use cases

Here are a few sample queries to demonstrate the capabilities of your virtual meteorologist:

  1. “What’s the weather like in New York City today?”
  2. “Should I plan an outdoor birthday party in Miami next weekend?”
  3. “Will it snow in Denver on Christmas Day?”
  4. “Can I go swimming on a beach in Chicago today?

These queries showcase the agent’s ability to provide current weather information, offer advice based on weather forecasts, and predict future weather conditions. You can even ask a question related to an activity such as swimming, and it will answer based on the weather conditions if that activity is okay to do.

Clean up

If you decide to discontinue using the virtual meteorologist, you can follow these steps to remove it, its associated resources deployed using AWS CloudFormation, and the Amplify deployment:

  1. Delete the CloudFormation stack:
    1. On the AWS CloudFormation console, choose Stacks in the navigation pane.
    2. Locate the stack you created during the deployment process (you assigned a name to it).
    3. Select the stack and choose Delete.
  2. Delete the Amplify application and its resources. For instructions, refer to Clean Up Resources.

Conclusion

This solution demonstrates the power of combining Amazon Bedrock Agents with other AWS services to create an intelligent, conversational weather assistant. By using AI and cloud technologies, businesses can automate complex queries and provide valuable insights to their users.

Additional resources

To learn more about Amazon Bedrock, refer to the following resources:

To learn more about the Anthropic’s Claude 3.5 Sonnet model, refer to the following resources:

本文地址
最后修改
星期二, 九月 23, 2025 - 21:54
Tags
 
Article