AWS Machine Learning Blog 11月05日 02:41
Amazon Bedrock AgentCore推出Python直接代码部署
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

Amazon Bedrock AgentCore Runtime新增直接代码部署功能(目前支持Python),旨在简化代理的构建和部署流程。此前主要依赖容器部署,需要Dockerfile和ECR等。现在,开发者可以将Python代码及其依赖打包为zip文件上传,无需关注Docker和容器基础设施,从而加快原型设计和迭代速度。这种方式特别适合不希望管理Docker相关复杂性的用户。文章对比了容器部署和直接代码部署的步骤、优势和适用场景,并提供了一个使用Strands Agents SDK和AgentCore starter toolkit进行直接代码部署的Python代理示例。

🚀 AgentCore Runtime推出新的直接代码部署方式,简化Python代理部署流程,开发者无需创建Dockerfile和管理ECR镜像。

⏱️ 直接代码部署通过zip文件上传代码和依赖,显著缩短了代理更新的部署时间,从容器部署的平均30秒降至约10秒,提升开发效率。

📦 容器部署适用于超过250MB的软件包、已有的容器CI/CD流程以及需要高度定制化依赖和打包的场景;而直接代码部署则更适合小于250MB、使用常见Python框架且追求快速原型设计的项目。

🛠️ AgentCore starter toolkit简化了直接代码部署,能够自动检测依赖、打包并上传至S3,用户只需少量配置即可完成部署。

💡 混合部署策略也是一种选择,可以使用直接代码部署进行快速原型开发和实验,然后在需要更大包体积、多语言支持或复杂构建流程时切换到容器部署。

Amazon Bedrock AgentCore is an agentic platform for building, deploying, and operating effective agents securely at scale. Amazon Bedrock AgentCore Runtime is a fully managed service of Bedrock AgentCore, which provides low latency serverless environments to deploy agents and tools. It provides session isolation, supports multiple agent frameworks including popular open-source frameworks, and handles multimodal workloads and long-running agents.

AgentCore Runtime supports container based deployments where the container definition is provided in a Dockerfile, and the agent is built as a container image. Customers who have container build and deploy pipelines benefit from this method, where agent deployment can be integrated into existing pipelines. 

Today, AgentCore Runtime has launched a second method to deploy agents – direct code deployment (for Python). Agent code and its dependencies can be packaged as a zip archive, alleviating the need for Docker definition and ECR dependencies. This makes it straightforward for developers to prototype and iterate faster. This method is a good fit for customers who prefer not to worry about Docker expertise and container infrastructure when deploying agents.

In this post, we’ll demonstrate how to use direct code deployment (for Python).

Introducing AgentCore Runtime direct code deployment

With the container deployment method, developers create a Dockerfile, build ARM-compatible containers, manage ECR repositories, and upload containers for code changes. This works well where container DevOps pipelines have already been established to automate deployments. 

However, customers looking for fully managed deployments can benefit from direct code deployment, which can significantly improve developer time and productivity. Direct code deployment provides a secure and scalable path forward for rapid prototyping agent capabilities to deploying production workloads at scale.

We’ll discuss the strengths of each deployment option to help you choose the right approach for your use case. 

With direct code deployment, developers create a zip archive of code and dependencies, upload to Amazon S3, and configure the bucket in the agent configuration. When using the AgentCore starter toolkit, the toolkit handles dependency detection, packaging, and upload which provides a much-simplified developer experience. Direct code deployment is also supported using the API.

Let’s compare the deployment steps at a high level between the two methods:

Container-based deployment

The container-based deployment method involves the following steps:

    Create a Dockerfile Build ARM-compatible container Create ECR repository Upload to ECR Deploy to AgentCore Runtime

Direct code deployment

The direct code deployment method involves the following steps:

How to use direct code deployment

Let’s illustrate how direct code deployment works with an agent created with Strands Agents SDK and using the AgentCore starter-toolkit to deploy the agent.

Prerequisites

Before you begin, make sure you have the following:

Step 1: Initialize your project

Set up a new Python project using the uv package manager, then navigate into the project directory:

uv init <project> --python 3.13cd <project>

Step 2: Add the dependencies for the project

Install the required Bedrock AgentCore libraries and development tools for your project. In this example, dependencies are added using .toml file, alternatively they can be specified in requirements.txt file:

uv add bedrock-agentcore strands-agents strands-agents-toolsuv add --dev bedrock-agentcore-starter-toolkitsource .venv/bin/activate

Step 3: Create an agent.py file

Create the main agent implementation file that defines your AI agent’s behavior:

from bedrock_agentcore import BedrockAgentCoreApp from strands import Agent, tool from strands_tools import calculator  from strands.models import BedrockModel import logging app = BedrockAgentCoreApp(debug=True) # Logging setup logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # Create a custom tool  @tool def weather():      """ Get weather """       return "sunny" model_id = "us.anthropic.claude-sonnet-4-20250514-v1:0" model = BedrockModel(      model_id=model_id, ) agent = Agent(      model=model,      tools=[calculator, weather],      system_prompt="You're a helpful assistant. You can do simple math calculation, and tell the weather." ) @app.entrypoint def invoke(payload):      """Your AI agent function"""      user_input = payload.get("prompt", "Hello! How can I help you today?")      logger.info("\n User input: %s", user_input)      response = agent(user_input)      logger.info("\n Agent result: %s ", response.message)      return response.message['content'][0]['text'] if __name__ == "__main__":      app.run() 

Step 4: Deploy to AgentCore Runtime

Configure and deploy your agent to the AgentCore Runtime environment:

agentcore configure --entrypoint agent.py --name <agent-name>

This will launch an interactive session where you configure the S3 bucket to upload the zip deployment package to and choose a deployment configuration type (as shown in the following configuration). To opt for direct code deployment, choose option 1 – Code Zip.

Deployment Configuration

Select deployment type:

    Code Zip (recommended) – Simple, serverless, no Docker required Container – For custom runtimes or complex dependencies
agentcore launch

This command creates a zip deployment package, uploads it to the specified S3 bucket, and launches the agent in the AgentCore Runtime environment, making it ready to receive and process requests.

To test the solution, let’s prompt the agent to see how the weather is:

agentcore invoke '{"prompt":"How is the weather today?"}'

The first deployment takes approximately 30 seconds to complete, but subsequent updates to the agent benefit from the streamlined direct code deployment process and should take less than half the time, supporting faster iteration cycles during development.

When to choose direct code instead of container-based deployment

Let’s look at some of the dimensions and see how the direct code and container-based deployment options are different. This will help you choose the option that’s right for you:

Our general guidance is:

Container-based deployment is the right choice when your package exceeds 250MB, you have existing container CI/CD pipelines, or you need highly specialized dependencies and custom packaging requirements. Choose containers if you require multi-language support, custom system dependencies or direct control over artifact storage and versioning in your account.

Direct code deployment is the right choice when your package is under 250MB, you use Python 3.10-3.13 with common frameworks like LangGraph, Strands, or CrewAI, and you need rapid prototyping with fast iteration cycles. Choose direct code if your build process is straightforward without complex dependencies, and you want to remove the Docker/ECR/CodeBuild setup.

A hybrid approach works well for many teams, use direct code for rapid prototyping and experimentation where fast iteration and simple setup accelerate development, then graduate to containers for production when package size, multi-language requirements, or specialized build processes demand it.

Conclusion

Amazon Bedrock AgentCore direct code deployment makes iterative agent development cycles even faster, while still benefiting from enterprise security and scale of deployments. Developers can now rapidly prototype and iterate by deploying their code directly, without having to create a container. To get started with Amazon Bedrock AgentCore direct code deployment, visit the AWS documentation.


About the authors

Chaitra Mathur is as a GenAI Specialist Solutions Architect at AWS. She works with customers across industries in building scalable generative AI platforms and operationalizing them. Throughout her career, she has shared her expertise at numerous conferences and has authored several blogs in the Machine Learning and Generative AI domains.

Qingwei Li is a Machine Learning Specialist at Amazon Web Services. He received his Ph.D. in Operations Research after he broke his advisor’s research grant account and failed to deliver the Nobel Prize he promised. Currently he helps customers in the financial service and insurance industry build machine learning solutions on AWS. In his spare time, he likes reading and teaching.

Kosti Vasilakakis is a Principal PM at AWS on the Agentic AI team, where he has led the design and development of several Bedrock AgentCore services from the ground up, including Runtime, Browser, Code Interpreter, and Identity. He previously worked on Amazon SageMaker since its early days, launching AI/ML capabilities now used by thousands of companies worldwide. Earlier in his career, Kosti was a data scientist. Outside of work, he builds personal productivity automations, plays tennis, and enjoys life with his wife and kids.

Fish AI Reader

Fish AI Reader

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

FishAI

FishAI

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

联系邮箱 441953276@qq.com

相关标签

Amazon Bedrock AgentCore 直接代码部署 Python 代理 云服务
相关文章