跳转到主要内容

BedrockInvokeAgentTool

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

安装

uv pip install 'crewai[tools]'

要求

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

用法

以下是如何在 CrewAI 智能体中使用此工具
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_idstrtimestamp会话的唯一标识符
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 功能与 AWS 服务(如 Bedrock 知识库、Lambda 等)进行交互

可扩展的混合 Agent 架构

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

跨组织的 Agent 协作

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