BedrockInvokeAgentTool

BedrockInvokeAgentTool 使 CrewAI Agent 能够调用 Amazon Bedrock Agent 并在您的工作流程中利用其能力。

安装

uv pip install 'crewai[tools]'

要求

  • 已配置 AWS 凭据(通过环境变量或 AWS CLI)
  • boto3python-dotenv
  • 访问 Amazon Bedrock Agent 的权限

用法

以下是如何在 CrewAI Agent 中使用此工具

from crewai import Agent, Task, Crew
from crewai_tools.aws.bedrock.agents.invoke_agent_tool import BedrockInvokeAgentTool

# Initialize the tool
agent_tool = BedrockInvokeAgentTool(
    agent_id="your-agent-id",
    agent_alias_id="your-agent-alias-id"
)

# Create a CrewAI agent that uses the tool
aws_expert = Agent(
    role='AWS Service Expert',
    goal='Help users understand AWS services and quotas',
    backstory='I am an expert in AWS services and can provide detailed information about them.',
    tools=[agent_tool],
    verbose=True
)

# Create a task for the agent
quota_task = Task(
    description="Find out the current service quotas for EC2 in us-west-2 and explain any recent changes.",
    agent=aws_expert
)

# Create a crew with the agent
crew = Crew(
    agents=[aws_expert],
    tasks=[quota_task],
    verbose=2
)

# Run the crew
result = crew.kickoff()
print(result)

工具参数

参数类型必需默认值描述
agent_idstrBedrock Agent 的唯一标识符
agent_alias_idstrAgent 别名的唯一标识符
session_idstr时间戳会话的唯一标识符
enable_traceboolFalse是否启用跟踪进行调试
end_sessionboolFalse是否在调用后结束会话
descriptionstr工具的自定义描述

环境变量

BEDROCK_AGENT_ID=your-agent-id           # Alternative to passing agent_id
BEDROCK_AGENT_ALIAS_ID=your-agent-alias-id # Alternative to passing agent_alias_id
AWS_REGION=your-aws-region               # Defaults to us-west-2
AWS_ACCESS_KEY_ID=your-access-key        # Required for AWS authentication
AWS_SECRET_ACCESS_KEY=your-secret-key    # Required for AWS authentication

高级用法

具有会话管理的 Agent 工作流程

from crewai import Agent, Task, Crew, Process
from crewai_tools.aws.bedrock.agents.invoke_agent_tool import BedrockInvokeAgentTool

# Initialize tools with session management
initial_tool = BedrockInvokeAgentTool(
    agent_id="your-agent-id",
    agent_alias_id="your-agent-alias-id",
    session_id="custom-session-id"
)

followup_tool = BedrockInvokeAgentTool(
    agent_id="your-agent-id",
    agent_alias_id="your-agent-alias-id",
    session_id="custom-session-id"
)

final_tool = BedrockInvokeAgentTool(
    agent_id="your-agent-id",
    agent_alias_id="your-agent-alias-id",
    session_id="custom-session-id",
    end_session=True
)

# Create agents for different stages
researcher = Agent(
    role='AWS Service Researcher',
    goal='Gather information about AWS services',
    backstory='I am specialized in finding detailed AWS service information.',
    tools=[initial_tool]
)

analyst = Agent(
    role='Service Compatibility Analyst',
    goal='Analyze service compatibility and requirements',
    backstory='I analyze AWS services for compatibility and integration possibilities.',
    tools=[followup_tool]
)

summarizer = Agent(
    role='Technical Documentation Writer',
    goal='Create clear technical summaries',
    backstory='I specialize in creating clear, concise technical documentation.',
    tools=[final_tool]
)

# Create tasks
research_task = Task(
    description="Find all available AWS services in us-west-2 region.",
    agent=researcher
)

analysis_task = Task(
    description="Analyze which services support IPv6 and their implementation requirements.",
    agent=analyst
)

summary_task = Task(
    description="Create a summary of IPv6-compatible services and their key features.",
    agent=summarizer
)

# Create a crew with the agents and tasks
crew = Crew(
    agents=[researcher, analyst, summarizer],
    tasks=[research_task, analysis_task, summary_task],
    process=Process.sequential,
    verbose=2
)

# Run the crew
result = crew.kickoff()

用例

混合多 Agent 协作

  • 创建 CrewAI Agent 与在 AWS 中作为服务运行的托管 Bedrock Agent 协作的工作流程
  • 支持敏感数据处理在您的 AWS 环境中进行,而其他 Agent 在外部运行的场景
  • 连接本地 CrewAI Agent 与云端 Bedrock Agent,以实现分布式智能工作流程

数据主权和合规性

  • 将数据敏感的 Agent 工作流程保留在您的 AWS 环境中,同时允许外部 CrewAI Agent 编排任务
  • 通过仅在您的 AWS 账户内处理敏感信息来维持数据驻留要求的合规性
  • 实现安全的 Agent 协作,其中一些 Agent 无法访问您组织的私有数据

无缝 AWS 服务集成

  • 通过 Amazon Bedrock Actions 访问任何 AWS 服务,无需编写复杂的集成代码
  • 使 CrewAI Agent 能够通过自然语言请求与 AWS 服务交互
  • 利用预构建的 Bedrock Agent 功能与 Bedrock 知识库、Lambda 等 AWS 服务交互

可扩展的混合 Agent 架构

  • 将计算密集型任务卸载到托管 Bedrock Agent,同时在 CrewAI 中运行轻量级任务
  • 通过在本地 CrewAI Agent 和云端 Bedrock Agent 之间分配工作负载来扩展 Agent 处理能力

跨组织 Agent 协作

  • 实现您组织的 CrewAI Agent 与合作伙伴组织的 Bedrock Agent 之间的安全协作
  • 创建可整合来自 Bedrock Agent 的外部专业知识而不会暴露敏感数据的工作流程
  • 构建跨越组织边界的 Agent 生态系统,同时保持安全和数据控制