category
|
July 28, 2025: The code and the steps of the demo have been updated to simplify the experience.
在短短几年内,基础模型(FM)已经从直接用于根据用户的提示创建内容发展到现在为人工智能智能体提供动力,人工智能智能体是一类新的软件应用程序,它使用FM进行推理、计划、行动、学习和适应,以在有限的人为监督下追求用户定义的目标。这种新的智能体AI浪潮是由标准化协议的出现所推动的,如模型上下文协议(MCP)和Agent2Agent(A2A),这些协议简化了智能体与其他工具和系统的连接方式。
事实上,由于CrewAI、LangGraph、LlamaIdex和Strands agents等开源框架的出现,构建能够可靠地执行复杂任务的AI智能体变得越来越容易。然而,从有前景的概念验证转向可扩展到数千用户的生产就绪智能体,带来了重大挑战。
开发人员和人工智能工程师不得不花费数月时间为会话管理、身份控制、内存系统和可观察性构建基础架构,同时支持安全性和合规性,而不是能够专注于智能体的核心功能。
今天,我们很高兴地宣布Amazon Bedrock AgentCore的预览版,这是一套全面的企业级服务,可帮助开发人员使用任何框架和模型快速、安全地大规模部署和操作AI智能体,托管在Amazon Bedrock或其他地方。
更具体地说,我们今天介绍:
- AgentCore Runtime-提供具有会话隔离的低延迟无服务器环境,支持任何智能体框架,包括流行的开源框架、工具和模型,并处理多模式工作负载和长时间运行的智能体。
- AgentCore内存–管理会话和长期内存,为模型提供相关上下文,同时帮助智能体从过去的交互中学习。
- AgentCore Observability–通过元数据标记、自定义评分、轨迹检查和故障排除/调试过滤器,提供智能体执行的逐步可视化。
- AgentCore Identity-使AI智能体能够代表用户或在预先授权的用户同意下自行安全地访问AWS服务和第三方工具和服务,如GitHub、Salesforce和Slack。
- AgentCore网关–将现有API和AWS Lambda函数转换为智能体就绪工具,提供跨协议(包括MCP)的统一访问和运行时发现。
- AgentCore Browser–提供托管的web浏览器实例,以扩展智能体的web自动化工作流程。
- AgentCore代码解释器——提供一个隔离的环境来运行智能体生成的代码。
这些服务可以单独使用,并经过优化以协同工作,因此开发人员不需要花时间拼凑组件。AgentCore可以与开源或自定义AI智能体框架配合使用,使团队能够灵活地维护他们喜欢的工具,同时获得企业能力。要将这些服务集成到现有代码中,开发人员可以使用AgentCore SDK。
现在,您可以使用AgentCore Runtime从AWS Marketplace发现、购买和运行预构建的智能体和智能体工具。只需几行代码,您的智能体就可以通过AgentCore Gateway安全地连接到AWS Marketplace中基于API的智能体和工具,以帮助您运行复杂的工作流,同时保持合规性和控制。
AgentCore消除了繁琐的基础设施工作和操作复杂性,因此开发团队可以更快地将突破性的智能体解决方案推向市场。
让我们看看这在实践中是如何运作的。在我们使用这些服务时,我将分享更多信息。
使用Amazon Bedrock AgentCore部署生产就绪的客户支持助理(预览版)
当客户发送电子邮件时,需要时间来提供回复。客户支持需要检查电子邮件的有效性,在客户关系管理(CRM)系统中找到实际客户,检查他们的订单,并使用特定于产品的知识库来查找准备答案所需的信息。
人工智能智能体可以通过连接到内部系统、使用语义数据源检索上下文信息以及为支持团队起草回复来简化这一过程。对于这个用例,我使用Strands Agent构建了一个简单的原型。为了简单起见并验证场景,使用Python函数模拟内部工具。
当我与开发人员交谈时,他们告诉我,许多公司正在构建涵盖不同用例的类似原型。当这些原型向公司领导层展示并得到确认后,开发团队必须确定如何投入生产,并满足安全性、性能、可用性和可扩展性的通常要求。这就是AgentCore可以提供帮助的地方。
步骤1–使用AgentCore Runtime部署到云端
AgentCore Runtime是一项新服务,用于安全地部署、运行和扩展AI智能体,提供隔离,使每个用户会话在其自己的受保护环境中运行,以帮助防止数据泄漏——这是处理敏感数据的应用程序的关键要求。
为了匹配不同的安全态势,智能体可以使用不同的网络配置:
公共–使用受管理的互联网接入运行。
仅限VPC(即将推出)-此选项将允许访问客户VPC中托管的资源或通过AWS PrivateLink端点连接的资源。
为了将智能体部署到云端并使用AgentCore Runtime获得安全的无服务器端点,我使用AgentCore SDK向原型添加了几行代码:
- 导入AgentCore SDK。
- 创建AgentCore应用程序。
- 指定哪个函数是调用智能体的入口点。
使用不同的或自定义的智能体框架是替换入口点函数内的智能体调用的问题。
这是原型的代码。我为使用AgentCore Runtime添加的三行是前面有注释的行。
The previous code needs the Strands Agents modules installed in the Python environment. To do so,
To install dependencies, I create and activate a virtual environment:
I add Strands Agents modules, AgentCore SDK, and AgentCore starter toolkit to the dependency file (requirements.txt
):
I then install all the requirements in the virtual environment:
Now the virtual environment, gives me access to the AgentCore command line interface (CLI) provided by the starter toolkit.
First, I use agentcore configure --entrypoint my_agent.py
to configure the agent. I press Enter
to auto-create the AWS Identity and Access Management (IAM) execution role and the Amazon Elastic Container Registry (Amazon ECR) repository and to confirm the detected dependency file.
In this case, the agent only needs access to Amazon Bedrock to invoke the model. The role can give access to other AWS resources used by an agent, such as an Amazon Simple Storage Service (Amazon S3) bucket or a Amazon DynamoDB table. The ECR repository is used to store the container image created when deploying the agent.
By default, the agent configuration enables observability. To enable trace delivery, I use the AWS Command Line Interface (AWS CLI) to set up Transaction Search in Amazon CloudWatch. This switches all trace ingestion for the entire account into cost effective collection mode using CloudWatch Application Signals pricing plan.
I check the result of these commands with:
I launch the agent locally with agentcore launch --local
. When running locally, I can interact with the agent using agentcore invoke --local <PAYLOAD>
. The payload is passed to the entry point function. Note that the JSON syntax of the invocations is defined in the entry point function. In this case, I look for prompt
in the JSON payload, but can use a different syntax depending on your use case.
When I am satisfied by local testing, I use agentcore launch
to deploy to the cloud.
After the deployment is succesful and an endpoint has been created, I check the status of the endpoint with agentcore status
and invoke the endpoint with agentcore invoke <PAYLOAD>
. For example, I pass a customer support request in the invocation:
agentcore invoke '{"prompt": "From: me@example.net – Hi, I bought a smartphone from your store.
I am traveling to Europe next week, will I be able to use the charger?
Also, I struggle to remove the cover. Thanks, Danilo"}'
Step 2 – Enabling memory for context
After an agent has been deployed in the AgentCore Runtime, the context needs to be persisted to be available for a new invocation. I add AgentCore Memory to maintain session context using its short-term memory capabilities.
First, I create a memory client and the memory store for the conversations:
I can now use create_event
to stores agent interactions into short-term memory:
I can load the most recent turns of a conversations from short-term memory using list_events
:
With this capability, the agent can maintain context during long sessions. But when a users come back with a new session, the conversation starts blank. Using long-term memory, the agent can personalize user experiences by retaining insights across multiple interactions.
To extract memories from a conversation, I can use built-in AgentCore Memory policies for user preferences, summarization, and semantic memory (to capture facts) or create custom policies for specialized needs. Data is stored encrypted using a namespace-based storage for data segmentation.
I change the previous code creating the memory store to include long-term capabilities by passing a semantic memory strategy. Note that an existing memory store can be updated to add strategies. In that case, the new strategies are applied to newer events as they are created.
After long-term memory has been configured for a memory store, calling create_event
will automatically apply those strategies to extract information from the conversations. I can then retrieve memories extracted from the conversation using a semantic query:
In this way, I can quickly improve the user experience so that the agent remembers customer preferences and facts that are outside of the scope of the CRM and use this information to improve the replies.
Step 3 – Adding identity and access controls
Without proper identity controls, access from the agent to internal tools always uses the same access level. To follow security requirements, I integrate AgentCore Identity so that the agent can use access controls scoped to the user’s or agent’s identity context.
I set up an identity client and create a workload identity, a unique identifier that represents the agent within the AgentCore Identity system:
Then, I configure the credential providers, for example:
然后,我可以将@requires_access_token Python修饰符(传递提供者名称、范围等)添加到需要访问令牌来执行其活动的函数中。
采用这种方法,智能体可以通过公司现有的身份基础设施验证身份,以一个独特的、经过身份验证的身份进行操作,以有限权限行事,并跨多个身份提供者(如Amazon Cognito、Okta或Microsoft Entra ID)和服务边界(包括AWS和第三方工具和服务,如Slack、GitHub和Salesforce)进行集成。
为了在简化终端用户和智能体构建者体验的同时提供稳健且安全的访问控制,AgentCore Identity实现了一个安全的令牌保险库,用于存储用户的令牌并允许智能体安全地检索它们。
对于与OAuth 2.0兼容的工具和服务,当用户首次授权智能体代表其执行操作时,AgentCore Identity会收集并存储该工具为其颁发的用户令牌,同时还会安全地存储智能体的OAuth客户端凭据。智能体以自身独特的身份运行,并在用户调用时,可以根据需要访问这些令牌,从而减少频繁获取用户授权的必要性。
当用户令牌过期时,AgentCore Identity会向用户触发一个新的授权提示,以便智能体获取更新的用户令牌。对于使用API密钥的工具,AgentCore Identity还会安全地存储这些密钥,并在需要时授予智能体受控访问权限以检索它们。这种安全存储方式在保持强大访问控制的同时简化了用户体验,使智能体能够在各种工具和服务中有效运行。
步骤4 - 使用AgentCore Gateway扩展智能体功能
到目前为止,所有内部工具都是在代码中模拟的。许多智能体框架(包括Strands Agents)都原生支持MCP以连接到远程工具。为了通过MCP接口访问内部系统(如客户关系管理和订单管理),我使用了AgentCore Gateway。
借助AgentCore Gateway,智能体可以使用Smithy模型、Lambda函数以及内部API和第三方提供商(使用OpenAPI规范)来访问AWS服务。它采用双重身份验证模型,对目标资源的传入请求和传出连接进行安全访问控制。Lambda函数可用于集成外部系统,特别是那些缺乏标准API或需要多个步骤来检索信息的应用程序。
AgentCore Gateway 提供了大多数客户原本需要自行构建的跨领域功能,包括身份验证、授权、限流、自定义请求/响应转换(以匹配底层API格式)、多租户和工具选择。
工具选择功能有助于为特定智能体的任务找到最相关的工具。AgentCore Gateway为所有这些工具提供了一个统一的MCP接口,并使用AgentCore Identity为那些不支持开箱即用OAuth的工具(如AWS服务)提供一个OAuth接口。
第五步——使用AgentCore代码解释器和浏览器工具添加功能
为了回应客户请求,客户支持智能体需要进行计算。为了简化这一过程,我使用了AgentCode SDK来添加对AgentCore代码解释器的访问。
同样,智能体所需的一些集成并未实现编程式API,而是需要通过Web界面进行访问。我授予AgentCore Browser访问权限,以便智能体能够自主浏览这些网站。
步骤6——通过可观察性提升可见性
既然智能体已投入生产,我需要了解其活动和性能。AgentCore提供了增强的可观察性,以帮助开发人员有效地调试、审核和监控其在生产环境中的智能体性能。它内置了仪表板,可跟踪关键操作指标,如会话计数、延迟、持续时间、令牌使用情况、错误率以及组件级别的延迟和错误细分。AgentCore还通过捕获和可视化端到端跟踪以及捕获智能体工作流每个步骤(包括工具调用、内存)的“跨度”,来了解智能体的行为
该服务提供的内置仪表板有助于揭示性能瓶颈,并确定某些交互失败的原因,从而推动持续改进,并在出现问题时缩短平均检测时间(MTTD)和平均修复时间(MTTR)。
AgentCore支持OpenTelemetry,有助于将智能体遥测数据与现有的可观察性平台(包括CloudWatch、Datadog、LangSmith和Langfuse)集成。我只需要在智能体配置中启用可观察性,然后重新启动它,即可开始向CloudWatch发送遥测数据。请检查智能体使用的IAM角色是否具有执行此操作所需的必要权限。
第7步 - 结论
通过这一历程,我们将一个本地原型转化为一个可投入生产的系统。我们采用AgentCore的模块化方法,逐步实现了企业需求——从基本部署到复杂的内存管理、身份认证和工具集成——同时保持了现有智能体代码的完整性。
须知事项
Amazon Bedrock AgentCore现已在美国东部(北弗吉尼亚州)、美国西部(俄勒冈州)、亚太地区(悉尼)和欧洲(法兰克福)提供预览版。您可以通过AWS管理控制台、AWS命令行界面(AWS CLI)、AWS开发工具包或AgentCore开发工具包开始使用AgentCore服务。
在2025年9月16日之前,您可以免费试用AgentCore服务。在使用AgentCore的过程中,如需使用任何额外的AWS服务,将按照标准AWS定价收费(例如,AgentCore Observability将按照CloudWatch定价收费)。自2025年9月17日起,AWS将根据本页面所述向您收取AgentCore服务使用费用。
无论您是在构建客户支持智能体、工作流程自动化,还是创新的人工智能体验,AgentCore都能为您提供从原型开发到生产部署所需的基础设施,让您信心满满。
要了解更多信息并开始部署可用于生产的智能体,请访问AgentCore文档。如需查看代码示例和集成指南,请访问AgentCore示例GitHub仓库。
加入AgentCore预览版Discord服务器,提供反馈并讨论用例。我们期待听到您的声音!
— 达尼洛
- 登录 发表评论
- 14 次浏览
最新内容
- 6 hours ago
- 6 hours 6 minutes ago
- 6 hours ago
- 6 hours 30 minutes ago
- 7 hours ago
- 7 hours ago
- 7 hours ago
- 7 hours ago
- 7 hours ago
- 7 hours 43 minutes ago