主题
Bedrock Invoke Agent 工具
使 CrewAI 智能体能够调用 Amazon Bedrock Agents,并在你的工作流中利用其能力
BedrockInvokeAgentTool
BedrockInvokeAgentTool 使 CrewAI 智能体能够调用 Amazon Bedrock Agents,并在你的工作流中利用其能力。
安装
bash
uv pip install 'crewai[tools]'要求
- 已配置 AWS 凭证(通过环境变量或 AWS CLI)
boto3和python-dotenv包- 对 Amazon Bedrock Agents 的访问权限
用量
以下是如何在 CrewAI 智能体中使用该工具:
python
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_id | str | 是 | None | Bedrock 智能体的唯一标识符 |
| agent_alias_id | str | 是 | None | 智能体别名的唯一标识符 |
| session_id | str | 否 | timestamp | 会话的唯一标识符 |
| enable_trace | bool | 否 | False | 是否启用追踪以便调试 |
| end_session | bool | 否 | False | 是否在调用结束后结束会话 |
| description | str | 否 | None | 该工具的自定义描述 |
环境变量
bash
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高级用法
带会话管理的多智能体工作流
python
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 Knowledge Bases、Lambda 等 AWS 服务交互
可扩展的混合智能体架构
- 将计算密集型任务卸载到托管 Bedrock 智能体,而轻量任务在 CrewAI 中运行
- 通过在本地 CrewAI 智能体与云端 Bedrock 智能体之间分配工作负载来扩展智能体的处理能力
跨组织的智能体协作
- 支持组织的 CrewAI 智能体与合作伙伴组织的 Bedrock 智能体之间安全协作
- 创建可引入 Bedrock 智能体的外部专业能力、同时不暴露敏感数据的工作流
- 构建跨越组织边界、同时保持安全与数据控制的智能体生态