AI  

How does CrewAI Integrate with AWS Bedrock?

☁️ Integration Overview

CrewAI integrates with AWS Bedrock through a dedicated tool—BedrockInvokeAgentTool—that lets your Crews or Flows invoke managed Bedrock Agents and models as if they were native CrewAI agents. This tight coupling ensures:

  • Data Sovereignty: All API calls stay within your AWS account and VPC.

  • Compliance: Leverage IAM roles, KMS encryption, and CloudTrail logging.

  • Seamless Orchestration: Mix lightweight CrewAI steps with heavyweight Bedrock compute in hybrid workflows.

https://docs.aws.amazon.com/images/prescriptive-guidance/latest/security-reference-architecture/images/workload-integration.png

🔗 BedrockInvokeAgentTool in CrewAI

The BedrockInvokeAgentTool is your bridge to Bedrock. Add it to any agent class to enable Bedrock calls:

from crewai import Agent
from crewai.tools import BedrockInvokeAgentTool

# Configure the Bedrock tool
bedrock_tool = BedrockInvokeAgentTool(
    agent_name="invoice-processor-agent",
    model_id="amazon.titan-code-large",
    region="us-west-2"
)

class InvoiceAgent(Agent):
    tools = [bedrock_tool]

    def run(self, invoice_text):
        # This invokes the Bedrock model under the hood
        return self.tools[0].invoke(f"Extract line items from:\n{invoice_text}")

🔨 End‑to‑End Workflow Example

Below is a hybrid Flow that uses CrewAI for orchestration and Bedrock for heavy NLP:

from crewai import Flow, Agent
from crewai.tools import BedrockInvokeAgentTool

# Define tools and agents
bedrock_tool = BedrockInvokeAgentTool(
    agent_name="nlp-agent",
    model_id="anthropic.claude-v2"
)

class ParserAgent(Agent):
    tools = [bedrock_tool]

    def run(self, text):
        return self.tools[0].invoke(f"Summarize the following text:\n{text}")

# Build and run the flow
flow = Flow()
flow.add_step("load", lambda path: open(path).read())
flow.add_step("parse", ParserAgent().run)
flow.add_step("save", lambda summary: open("summary.txt", "w").write(summary))

# Execute
flow.run("document.txt")

🔒 Security & Compliance

  • IAM Integration: BedrockInvokeAgentTool inherits the IAM role of the executing environment, so you can restrict which Bedrock models or agents are callable.

  • VPC‑Only Mode: Use AWS PrivateLink to ensure all Bedrock traffic remains inside your VPC.

  • Audit Trails: CloudTrail captures every Bedrock API invocation for governance and forensics.

🚀 Benefits of the Integration

  1. Developer Productivity: Treat Bedrock models as local agents—no custom API wiring.

  2. Performance: Offload intensive NLP or vision tasks to Bedrock while CrewAI handles orchestration.

  3. Scalability: Dynamically route large workloads to Bedrock’s scalable infrastructure.

  4. Cost Control: Pay Bedrock only for the compute you use, separate from CrewAI runtime costs.

With this integration, CrewAI and AWS Bedrock form a powerful duo, letting you orchestrate secure, scalable multi‑agent pipelines while harnessing the latest foundation models in Production.