AWS Machine Learning Blog 12小时前
Innovate business logic by implementing return of control in Amazon Bedrock Agents
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文深入探讨了Amazon Bedrock Agents在分布式系统和微服务架构中的应用,尤其关注其简化代理创建和实现控制返回功能的能力。通过构建个性化的投资组合解决方案,展示了如何利用Amazon Bedrock Agents调用第三方API、分析用户数据,并生成个性化的投资建议。文章详细介绍了解决方案的架构、关键代码片段和部署步骤,强调了控制返回功能在处理外部函数和业务逻辑方面的优势,以及在构建更自然、响应更强的交互体验中的作用。读者将了解到如何利用Amazon Bedrock Agents简化应用集成,并构建更智能、更灵活的系统。

🤖 Amazon Bedrock Agents简化了分布式系统中代理的创建、部署和管理,开发者无需过多关注基础设施管理,专注于构建可扩展的应用程序。

🔄 代理的“控制返回”能力允许在用户或系统层面进行更自然的交互,使得用户能够掌控流程,同时受益于代理的指导和自动化功能。

💡 本文演示的个性化投资组合解决方案,展示了如何利用Amazon Bedrock Agents调用第三方API获取用户投资组合数据,并结合基础模型生成个性化投资建议。

📧 该方案通过同步数据检索和生成式AI,为用户提供符合其财务目标和风险承受能力的定制化投资组合建议,并支持通过邮件发送推荐结果。

🛠️ Amazon Bedrock Agents允许应用程序管理外部交互并返回响应,这在调用现有API或处理超过15分钟的任务时尤为有用,简化了应用集成。

In the context of distributed systems and microservices architecture, orchestrating communication between diverse components presents significant challenges. However, with the launch of Amazon Bedrock Agents, the landscape is evolving, offering a simplified approach to agent creation and seamless integration of the return of control capability. In this post, we explore how Amazon Bedrock Agents revolutionizes agent creation and demonstrates the efficacy of the return of control capability in orchestrating complex interactions between multiple systems.

Amazon Bedrock Agents simplifies the creation, deployment, and management of agents in distributed systems. By using the power of AWS Lambda and AWS Step Functions, Amazon Bedrock Agents abstracts away the complexities of agent implementation, which means developers can focus on building robust and scalable applications without worrying about infrastructure management.

You can use agents in Amazon Bedrock in various scenarios where you need to handle the return of control to the user or the system. Use cases include conversational assistants, task automation, decision support systems, interactive tutorials and walkthroughs, and virtual assistants. In these use cases, the key aspect of the agents is their ability to handle the return of control to the user or the system. This allows for a more natural and responsive interaction, where the user feels in control of the process while still benefiting from the agent’s guidance and automation capabilities.

Solution overview

In this post, we demonstrate an automated personalized investment portfolio solution using Amazon Bedrock Agents. The solution calls a third-party API to fetch a user’s current investment portfolio. These are then analyzed using foundation models (FMs) available on Amazon Bedrock to produce recommendations inline to the inputs provided by the end user, showcasing a return of control capability integrated with Amazon Bedrock Agents.

This solution uses a combination of synchronous data retrieval and generative AI to provide tailored investment recommendations that align with users’ specific financial goals and risk tolerance. By incorporating machine learning (ML) and simulation techniques, the system can generate personalized portfolios and assess their potential performance, making sure the recommended solutions are optimized for individual needs.

With Amazon Bedrock Agents, the capability to return control to the application invoking the agent can handle external functions and business logic at the application level instead of using a Lambda function. This way, an application can manage external interactions and return the response while the agent continues its orchestration. This is illustrated in the following diagram.

The option to return control is particularly useful in two main scenarios:

    Calling an API from an existing application rather than building a new Lambda function with the required authentication and networking configurations Handling tasks that might run longer than 15 minutes and can’t be accommodated through a Lambda function, instead requiring containers, virtual servers, or workflow orchestration tools such as AWS Step Functions

The following sample code uses Amazon Bedrock Agents with handling return of control in the code. With the Amazon Bedrock Agents feature, you can manage Amazon Bedrock Agents return of control in your backend services and simplify application integrations. To demonstrate this, we have the following four code snippets: external-bedrock-agent-api.py, streamlit-app-portfolio-recommender.py, Portfolio-Recommender-CFN-Template.yaml, and requirements.txt, along with detailed steps to replicate the scenario.

The external-bedrock-agent-api code implements a portfolio recommendation system using Amazon Bedrock Agents and Flask. Here’s a high-level overview of the functions used:

The streamlit-app-portfolio-recommender code is a Streamlit web application for investment portfolio recommendations. The code sets up the webpage with a title and configuration. The app collects several pieces of information through form elements:

The system operates through a Portfolio Generation Function that actively sending POST requests to a local API endpoint. This function transforms user preferences into JSON data and delivers either an API response or error message back to the user.

The process to display results begins when user click the Submit button, which triggers the custom_portfolio function with their specific inputs. The system then displays the portfolio recommendation in a text area for successful executions, while immediately alerting users with an error message if any issues occur during the process.

Solution walkthrough

Follow the steps to set up the environment and test the application in the US East (N. Virginia) us-east-1 Region.

To enable Anthropic’s Claude model on Amazon Bedrock in your AWS account:

    On the Amazon Bedrock console, in the left navigation pane under Amazon Bedrock configurations, select Model access Select Claude 3 Sonnet, as shown in the following screenshot

    To create the Amazon Bedrock agents, related action groups, Amazon SageMaker AI domain, sample user profile, and JupyterLab space, follow these steps:

    Select the checkbox to acknowledge that the template contains AWS Identity and Access Management (IAM) resources, as shown in the following screenshot

    Monitor AWS CloudFormation until it completes the resource creation process. You can verify the successful deployment by checking the Stack details output tab, which will display the AgentId and AgentAliasId values, as shown in the screenshot below.

You will receive an email address verification request email from AWS for in the US East (N. Virginia) Region. Select the link in the email to verify.

After creating your CloudFormation resources, follow these steps to access Amazon SageMaker Studio:

    On the Amazon SageMaker AI console, under Admin configurations in the left navigation pane, select Domains Select the bedrock-return-of-control-demo domain created by the CloudFormation template, as shown in the following screenshot

    Select the User profiles tab To open the SageMaker Studio environment, under User profiles, next to the sagemakeruser profile on the right, select Launch. From the dropdown menu, choose Studio, as shown in the following screenshot

You should now observe the SageMaker Studio home page. This environment is where you will execute Python scripts to set up your application.

To access the JupyterLab environment for this lab, follow these steps:

    On the SageMaker Studio console, in the left navigation pane under Applications, select JupyterLab You’ll find bedrock-agent-space that has been preprovisioned for this lab. Its Status should be Stopped. On the right side under Action, choose Run Within 30–40 seconds, the JupyterLab application status will change from Starting to Running

    When it’s running, under Action, choose Open, as shown in the following screenshot

Three required files are copied under the /home/sagemaker-user/scripts directory: two Python files (external-bedrock-agent-api and streamlit-app-portfolio-recommender) and one requirements.txt file, as shown in the following screenshot. The JupyterLab application environment is under the default directory.

    In the File menu, select New. In the dropdown menu, select Terminal to open a new terminal window, as shown in the following screenshot.
    Go to the scripts directory where you have the required files in the terminal and enter:
    pip install -r requirements.txt
    Enter the following command on the terminal:
    python3 external-bedrock-agent-api.py
    Open a new terminal and go to the /home/sagemaker-user/scripts directory and enter:
    streamlit run streamlit-app-portfolio-recommender.py
    From the command execution in the terminal, note the port number (8501) and studio URL from the browser. The URL will be in the format of: https://{domainid}.studio.{region}-1.sagemaker.aws/jupyterlab/default/lab/tree/scripts To access the Streamlit app, modify the Studio URL, replacing everything after the default/ lab/tree/scripts with proxy/[PORT NUMBER]/. The modified Streamlit UI URL will look like this: https://{domainid}.studio.{region}.sagemaker.aws/jupyterlab/default/proxy/8501/ Select all appropriate inputs for generating your custom portfolio recommendation. Choose whether you prefer to receive email notifications or inline recommendations through the application interface by checking the corresponding box. Then choose Submit. Provide the same email address that was verified earlier in this walkthrough.

The sample output and email response are shown in the following demo screenshot.

Cleanup

When you’re done, delete resources you no longer need to avoid ongoing costs. Follow these steps:

    Go to the SageMaker AI JupyterLab environment and stop the Amazon SageMaker Studio application or running instance Delete the resources created by deleting the CloudFormation stack.

The following screenshot demonstrates how to view and stop running instances in the SageMaker AI JupyterLab environment. For more information, refer to Delete a stack from the CloudFormation console.

Amazon Bedrock Agents return of control considerations

When implementing return of control, consider the following:

Conclusion

In this post, we’ve demonstrated how Amazon Bedrock Agents simplifies agent creation and streamlines the orchestration of complex interactions between microservices using the return of control capability. By abstracting away infrastructure management and providing seamless integration with your application, Amazon Bedrock Agents empowers developers to build resilient and scalable applications with ease. As organizations embrace microservices architecture and distributed systems, tools such as Amazon Bedrock Agents play a pivotal role in accelerating innovation and driving digital transformation.

Resources

For the most current and specific information, refer to:


About the Authors


Vishwanatha Handadi
is a Sr. Solutions Architect within the Global Financial Services vertical, working with Amazon Web Services (AWS) for over 2 years and has over 22 years of experience in the IT industry primarily in data and analytics. At AWS, he drives customers through their cloud transformation journeys by converting complex challenges into actionable roadmaps for both technical and business audiences. He is based out of Bangalore, India.


Mohammed Asadulla Baig
is a Sr. Technical Account Manager with Amazon Web Services (AWS) Enterprise Support. Asad helps customers architect scalable, resilient, and secure solutions. With a keen eye for innovation and a passion for delivering customer success, Asad has established himself as a thought leader in the industry, helping enterprises navigate their cloud transformation journeys with confidence and ease.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Amazon Bedrock Agents 微服务 AI代理 分布式系统
相关文章