mcpField
A
aws-agentcore

aws-agentcore

github.com/hoodiniAgent 工作流291148 次安装5 天前更新
代码仓库

关于 aws-agentcore

AWS Bedrock AgentCore 是一组用于构建和运行 AI Agent 的 AWS 基础组件,涵盖执行、记忆、身份验证、可观测性和编排,并可将 API 或 Lambda 转为兼容 MCP 的工具。

主要功能

  1. 01框架无关的无服务器 Agent 运行时
  2. 02将 API 和 Lambda 转为 MCP 工具
  3. 03语义与用户偏好记忆策略
  4. 04通过子 Agent 编排 Agent
  5. 05身份验证、护栏与可观测性

适用场景

  1. 01使用 API 或 Lambda 工具构建 Agent
  2. 02创建带语义记忆的 Agent
  3. 03协调专职研究子 Agent

MCP 相关

AgentCore Gateway 可将 API 和 Lambda 函数转换为兼容 MCP 的工具,供 Agent 使用。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/hoodini/ai-agents-skills --skill aws-agentcore

安装后在 Claude Code 中输入/aws-agentcore确认已加载。

详细介绍

AWS Bedrock AgentCore

在 AWS 基础设施上构建可用于生产环境的 AI Agent。

快速开始

import boto3
from agentcore import Agent, Tool

# Initialize AgentCore client
client = boto3.client('bedrock-agent-runtime')

# 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": [...]}

# Create agent
agent = Agent(
    model_id="anthropic.claude-3-sonnet",
    tools=[search_database],
    instructions="You are a helpful product search assistant."
)

# Invoke agent
response = agent.invoke("Find laptops under $1000")

AgentCore 组件

AgentCore 提供以下基础功能:

组件用途
Runtime无服务器 Agent 执行(与框架无关)
Gateway将 API/Lambda 转换为兼容 MCP 的工具
Memory多策略记忆(语义、用户偏好)
Identity使用 Cognito、Okta、Google、EntraID 进行身份验证
ToolsCode Interpreter、Browser Tool
Observability深度分析与追踪

Lambda 工具集成

# 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)}
                }
            }
        }
    }

Agent 编排

from agentcore import SupervisorAgent, SubAgent

# 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."
)

# 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")

Guardrails 集成

from agentcore import Agent, Guardrail

# Define guardrail
guardrail = Guardrail(
    guardrail_id="my-guardrail-id",
    guardrail_version="1"
)

agent = Agent(
    model_id="anthropic.claude-3-sonnet",
    guardrails=[guardrail],
    tools=[...],
)

AgentCore Gateway

将现有 API 转换为兼容 MCP 的工具:

# gateway_setup.py
from bedrock_agentcore import GatewayClient

gateway = GatewayClient()

# Create gateway from OpenAPI spec
gateway.create_target(
    name="my-api",
    type="OPENAPI",
    openapi_spec_path="./api-spec.yaml"
)

# 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"
)

AgentCore Memory

from agentcore import Agent, Memory

# 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 persists across sessions
response = agent.invoke(
    "What did we discuss last time?",
    session_id="user-123"
)

官方用例代码库

AWS 提供可用于生产环境的实现:

代码库:https://github.com/awslabs/amazon-bedrock-agentcore-samples

可用用例(02-use-cases/)
用例描述
A2A 多 Agent 事件响应使用 Strands + OpenAI SDK 实现 Agent-to-Agent
客户支持助手记忆、知识库、Google OAuth
市场趋势 Agent使用 LangGraph 和浏览器工具
数据库性能分析器PostgreSQL 集成
设备管理 Agent使用 Cognito 身份验证的 IoT
企业 Web 情报用于研究的浏览器工具
文本转 Python IDEAgentCore Code Interpreter
电子游戏销售助手Amplify + CDK 部署
使用用例快速开始
git clone https://github.com/awslabs/amazon-bedrock-agentcore-samples.git
cd amazon-bedrock-agentcore-samples/02-use-cases/customer-support-assistant
# Follow README for deployment

资源

评论

支持 Markdown