跳转到内容

Bedrock Invoke Agent Tool

BedrockInvokeAgentTool 让 CrewAI agents 能够调用 Amazon Bedrock Agents,并在你的工作流中利用它们的能力。

Terminal window
uv pip install 'crewai[tools]'
  • 已配置 AWS 凭据(通过环境变量或 AWS CLI)
  • boto3python-dotenv
  • 可访问 Amazon Bedrock Agents

下面展示如何在 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)
ArgumentTypeRequiredDefaultDescription
agent_idstrYesNoneBedrock agent 的唯一标识符
agent_alias_idstrYesNoneagent alias 的唯一标识符
session_idstrNotimestampsession 的唯一标识符
enable_traceboolNoFalse是否启用 trace 用于调试
end_sessionboolNoFalse是否在调用后结束 session
descriptionstrNoNone工具的自定义描述
Terminal window
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 agents 与运行在 AWS 中的托管 Bedrock agents 协作
  • 让敏感数据处理在你的 AWS 环境中进行,同时其他 agents 在外部运行
  • 将本地 CrewAI agents 与基于云的 Bedrock agents 连接起来,实现分布式智能工作流
  • 让数据敏感型 agentic 工作流留在你的 AWS 环境中,同时允许外部 CrewAI agents 编排任务
  • 只在你的 AWS account 内处理敏感信息,以满足数据驻留要求
  • 让一些 agents 无法访问组织私有数据的同时,依然实现安全的多 agent 协作
  • 无需编写复杂的集成代码,即可通过 Amazon Bedrock Actions 访问任意 AWS 服务
  • 让 CrewAI agents 通过自然语言请求与 AWS 服务交互
  • 利用预构建的 Bedrock agent 能力与 Bedrock Knowledge Bases、Lambda 等 AWS 服务交互
  • 将计算密集型任务卸载给托管 Bedrock agents,而轻量任务在 CrewAI 中运行
  • 通过在本地 CrewAI agents 与云端 Bedrock agents 之间分配工作负载来扩展 agent 处理能力
  • 让你组织内的 CrewAI agents 与合作方组织的 Bedrock agents 安全协作
  • 创建工作流,使来自 Bedrock agents 的外部专业能力能够在不暴露敏感数据的前提下被纳入
  • 构建跨越组织边界的 agent 生态系统,同时保持安全与数据控制