Bedrock Invoke Agent Tool
BedrockInvokeAgentTool
Section titled “BedrockInvokeAgentTool”BedrockInvokeAgentTool 让 CrewAI agents 能够调用 Amazon Bedrock Agents,并在你的工作流中利用它们的能力。
uv pip install 'crewai[tools]'- 已配置 AWS 凭据(通过环境变量或 AWS CLI)
boto3和python-dotenv包- 可访问 Amazon Bedrock Agents
下面展示如何在 CrewAI agent 中使用该工具:
from crewai import Agent, Task, Crewfrom crewai_tools.aws.bedrock.agents.invoke_agent_tool import BedrockInvokeAgentTool
# Initialize the toolagent_tool = BedrockInvokeAgentTool( agent_id="your-agent-id", agent_alias_id="your-agent-alias-id")
# Create a CrewAI agent that uses the toolaws_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 agentquota_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 agentcrew = Crew( agents=[aws_expert], tasks=[quota_task], verbose=2)
# Run the crewresult = crew.kickoff()print(result)| Argument | Type | Required | Default | Description |
|---|---|---|---|---|
| agent_id | str | Yes | None | Bedrock agent 的唯一标识符 |
| agent_alias_id | str | Yes | None | agent alias 的唯一标识符 |
| session_id | str | No | timestamp | session 的唯一标识符 |
| enable_trace | bool | No | False | 是否启用 trace 用于调试 |
| end_session | bool | No | False | 是否在调用后结束 session |
| description | str | No | None | 工具的自定义描述 |
BEDROCK_AGENT_ID=your-agent-id # Alternative to passing agent_idBEDROCK_AGENT_ALIAS_ID=your-agent-alias-id # Alternative to passing agent_alias_idAWS_REGION=your-aws-region # Defaults to us-west-2AWS_ACCESS_KEY_ID=your-access-key # Required for AWS authenticationAWS_SECRET_ACCESS_KEY=your-secret-key # Required for AWS authentication带 Session 管理的多 Agent 工作流
Section titled “带 Session 管理的多 Agent 工作流”from crewai import Agent, Task, Crew, Processfrom crewai_tools.aws.bedrock.agents.invoke_agent_tool import BedrockInvokeAgentTool
# Initialize tools with session managementinitial_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 stagesresearcher = 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 tasksresearch_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 taskscrew = Crew( agents=[researcher, analyst, summarizer], tasks=[research_task, analysis_task, summary_task], process=Process.sequential, verbose=2)
# Run the crewresult = crew.kickoff()混合多 Agent 协作
Section titled “混合多 Agent 协作”- 创建工作流,让 CrewAI agents 与运行在 AWS 中的托管 Bedrock agents 协作
- 让敏感数据处理在你的 AWS 环境中进行,同时其他 agents 在外部运行
- 将本地 CrewAI agents 与基于云的 Bedrock agents 连接起来,实现分布式智能工作流
数据主权与合规
Section titled “数据主权与合规”- 让数据敏感型 agentic 工作流留在你的 AWS 环境中,同时允许外部 CrewAI agents 编排任务
- 只在你的 AWS account 内处理敏感信息,以满足数据驻留要求
- 让一些 agents 无法访问组织私有数据的同时,依然实现安全的多 agent 协作
无缝 AWS 服务集成
Section titled “无缝 AWS 服务集成”- 无需编写复杂的集成代码,即可通过 Amazon Bedrock Actions 访问任意 AWS 服务
- 让 CrewAI agents 通过自然语言请求与 AWS 服务交互
- 利用预构建的 Bedrock agent 能力与 Bedrock Knowledge Bases、Lambda 等 AWS 服务交互
可扩展的混合 agent 架构
Section titled “可扩展的混合 agent 架构”- 将计算密集型任务卸载给托管 Bedrock agents,而轻量任务在 CrewAI 中运行
- 通过在本地 CrewAI agents 与云端 Bedrock agents 之间分配工作负载来扩展 agent 处理能力
跨组织 agent 协作
Section titled “跨组织 agent 协作”- 让你组织内的 CrewAI agents 与合作方组织的 Bedrock agents 安全协作
- 创建工作流,使来自 Bedrock agents 的外部专业能力能够在不暴露敏感数据的前提下被纳入
- 构建跨越组织边界的 agent 生态系统,同时保持安全与数据控制