跳转到主要内容

BedrockInvokeAgentTool

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

安装

uv pip install 'crewai[tools]'

要求

  • 已配置 AWS 凭证(通过环境变量或 AWS CLI)
  • boto3python-dotenv 软件包
  • 访问 Amazon Bedrock 代理

用法

以下是如何在 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_alias_idstr代理别名的唯一标识符
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

高级用法

多代理工作流与会话管理

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()

用例

混合多代理协作

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

数据主权和合规性

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

无缝 AWS 服务集成

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

可扩展的混合代理架构

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

跨组织代理协作

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