aws-agentcore
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAWS Bedrock AgentCore
AWS Bedrock AgentCore
Build production-grade AI agents on AWS infrastructure.
在AWS基础设施上构建生产级AI Agent。
Quick Start
快速开始
python
import boto3
from agentcore import Agent, Toolpython
import boto3
from agentcore import Agent, ToolInitialize AgentCore client
Initialize AgentCore client
client = boto3.client('bedrock-agent-runtime')
client = boto3.client('bedrock-agent-runtime')
Define a tool
Define a tool
@Tool(name="search_database", description="Search the product database")
def search_database(query: str, limit: int = 10) -> dict:
# Tool implementation
return {"results": [...]}
@Tool(name="search_database", description="Search the product database")
def search_database(query: str, limit: int = 10) -> dict:
# Tool implementation
return {"results": [...]}
Create agent
Create agent
agent = Agent(
model_id="anthropic.claude-3-sonnet",
tools=[search_database],
instructions="You are a helpful product search assistant."
)
agent = Agent(
model_id="anthropic.claude-3-sonnet",
tools=[search_database],
instructions="You are a helpful product search assistant."
)
Invoke agent
Invoke agent
response = agent.invoke("Find laptops under $1000")
undefinedresponse = agent.invoke("Find laptops under $1000")
undefinedAgentCore Components
AgentCore组件
AgentCore provides these primitives:
| Component | Purpose |
|---|---|
| Runtime | Serverless agent execution (framework-agnostic) |
| Gateway | Convert APIs/Lambda to MCP-compatible tools |
| Memory | Multi-strategy memory (semantic, user preference) |
| Identity | Auth with Cognito, Okta, Google, EntraID |
| Tools | Code Interpreter, Browser Tool |
| Observability | Deep analysis and tracing |
AgentCore提供以下基础组件:
| 组件 | 用途 |
|---|---|
| Runtime | 无服务器Agent执行(与框架无关) |
| Gateway | 将API/Lambda转换为MCP兼容工具 |
| Memory | 多策略记忆(语义、用户偏好) |
| Identity | 与Cognito、Okta、Google、EntraID集成认证 |
| Tools | 代码解释器、浏览器工具 |
| Observability | 深度分析与追踪 |
Lambda Tool Integration
Lambda工具集成
python
undefinedpython
undefinedLambda function as tool
Lambda function as tool
import json
def lambda_handler(event, context):
action = event.get('actionGroup')
function = event.get('function')
parameters = event.get('parameters', [])
# Parse parameters
params = {p['name']: p['value'] for p in parameters}
if function == 'get_weather':
result = get_weather(params['city'])
elif function == 'book_flight':
result = book_flight(params['origin'], params['destination'])
return {
'response': {
'actionGroup': action,
'function': function,
'functionResponse': {
'responseBody': {
'TEXT': {'body': json.dumps(result)}
}
}
}
}undefinedimport json
def lambda_handler(event, context):
action = event.get('actionGroup')
function = event.get('function')
parameters = event.get('parameters', [])
# Parse parameters
params = {p['name']: p['value'] for p in parameters}
if function == 'get_weather':
result = get_weather(params['city'])
elif function == 'book_flight':
result = book_flight(params['origin'], params['destination'])
return {
'response': {
'actionGroup': action,
'function': function,
'functionResponse': {
'responseBody': {
'TEXT': {'body': json.dumps(result)}
}
}
}
}undefinedAgent Orchestration
Agent编排
python
from agentcore import SupervisorAgent, SubAgentpython
from agentcore import SupervisorAgent, SubAgentCreate specialized sub-agents
Create specialized sub-agents
research_agent = SubAgent(
name="researcher",
model_id="anthropic.claude-3-sonnet",
instructions="You research and gather information."
)
writer_agent = SubAgent(
name="writer",
model_id="anthropic.claude-3-sonnet",
instructions="You write clear, engaging content."
)
research_agent = SubAgent(
name="researcher",
model_id="anthropic.claude-3-sonnet",
instructions="You research and gather information."
)
writer_agent = SubAgent(
name="writer",
model_id="anthropic.claude-3-sonnet",
instructions="You write clear, engaging content."
)
Create supervisor
Create supervisor
supervisor = SupervisorAgent(
model_id="anthropic.claude-3-opus",
sub_agents=[research_agent, writer_agent],
routing_strategy="supervisor" # or "intent_classification"
)
response = supervisor.invoke("Write a blog post about AI agents")
undefinedsupervisor = SupervisorAgent(
model_id="anthropic.claude-3-opus",
sub_agents=[research_agent, writer_agent],
routing_strategy="supervisor" # or "intent_classification"
)
response = supervisor.invoke("Write a blog post about AI agents")
undefinedGuardrails Integration
防护栏集成
python
from agentcore import Agent, Guardrailpython
from agentcore import Agent, GuardrailDefine guardrail
Define guardrail
guardrail = Guardrail(
guardrail_id="my-guardrail-id",
guardrail_version="1"
)
agent = Agent(
model_id="anthropic.claude-3-sonnet",
guardrails=[guardrail],
tools=[...],
)
undefinedguardrail = Guardrail(
guardrail_id="my-guardrail-id",
guardrail_version="1"
)
agent = Agent(
model_id="anthropic.claude-3-sonnet",
guardrails=[guardrail],
tools=[...],
)
undefinedAgentCore Gateway
AgentCore网关
Convert existing APIs to MCP-compatible tools:
python
undefined将现有API转换为MCP兼容工具:
python
undefinedgateway_setup.py
gateway_setup.py
from bedrock_agentcore import GatewayClient
gateway = GatewayClient()
from bedrock_agentcore import GatewayClient
gateway = GatewayClient()
Create gateway from OpenAPI spec
Create gateway from OpenAPI spec
gateway.create_target(
name="my-api",
type="OPENAPI",
openapi_spec_path="./api-spec.yaml"
)
gateway.create_target(
name="my-api",
type="OPENAPI",
openapi_spec_path="./api-spec.yaml"
)
Create gateway from Lambda function
Create gateway from Lambda function
gateway.create_target(
name="my-lambda-tool",
type="LAMBDA",
function_arn="arn:aws:lambda:us-east-1:123456789:function:my-tool"
)
undefinedgateway.create_target(
name="my-lambda-tool",
type="LAMBDA",
function_arn="arn:aws:lambda:us-east-1:123456789:function:my-tool"
)
undefinedAgentCore Memory
AgentCore记忆
python
from agentcore import Agent, Memorypython
from agentcore import Agent, MemoryCreate memory with multiple strategies
Create memory with multiple strategies
memory = Memory(
name="customer-support-memory",
strategies=["semantic", "user_preference"]
)
agent = Agent(
model_id="anthropic.claude-3-sonnet",
memory=memory,
tools=[...],
)
memory = Memory(
name="customer-support-memory",
strategies=["semantic", "user_preference"]
)
agent = Agent(
model_id="anthropic.claude-3-sonnet",
memory=memory,
tools=[...],
)
Memory persists across sessions
Memory persists across sessions
response = agent.invoke(
"What did we discuss last time?",
session_id="user-123"
)
undefinedresponse = agent.invoke(
"What did we discuss last time?",
session_id="user-123"
)
undefinedOfficial Use Cases Repository
官方用例库
AWS provides production-ready implementations:
AWS提供生产级可用的实现方案:
Available Use Cases (02-use-cases/
)
02-use-cases/可用用例(02-use-cases/
)
02-use-cases/| Use Case | Description |
|---|---|
| A2A Multi-Agent Incident Response | Agent-to-Agent with Strands + OpenAI SDK |
| Customer Support Assistant | Memory, Knowledge Base, Google OAuth |
| Market Trends Agent | LangGraph with browser tools |
| DB Performance Analyzer | PostgreSQL integration |
| Device Management Agent | IoT with Cognito auth |
| Enterprise Web Intelligence | Browser tools for research |
| Text to Python IDE | AgentCore Code Interpreter |
| Video Games Sales Assistant | Amplify + CDK deployment |
| 用例 | 描述 |
|---|---|
| A2A多Agent事件响应 | 基于Strands + OpenAI SDK的Agent-to-Agent架构 |
| 客户支持助手 | 集成记忆、知识库、Google OAuth |
| 市场趋势Agent | 结合LangGraph与浏览器工具 |
| 数据库性能分析器 | PostgreSQL集成 |
| 设备管理Agent | 集成IoT与Cognito认证 |
| 企业网络智能 | 基于浏览器工具的调研 |
| 文本转Python IDE | AgentCore代码解释器 |
| 视频游戏销售助手 | Amplify + CDK部署 |
Quick Start with Use Cases
快速开始使用用例
bash
git clone https://github.com/awslabs/amazon-bedrock-agentcore-samples.git
cd amazon-bedrock-agentcore-samples/02-use-cases/customer-support-assistantbash
git clone https://github.com/awslabs/amazon-bedrock-agentcore-samples.git
cd amazon-bedrock-agentcore-samples/02-use-cases/customer-support-assistantFollow README for deployment
Follow README for deployment
undefinedundefined