Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CrewAIInc CrewAI Bedrock Invoke Agent Tool

From Leeroopedia
Knowledge Sources
Domains Cloud_Integration, AWS_Bedrock, Agent_Orchestration
Last Updated 2026-02-11 00:00 GMT

Overview

Concrete tool for invoking Amazon Bedrock Agents from CrewAI provided by CrewAI.

Description

The BedrockInvokeAgentTool class extends BaseTool to enable CrewAI agents to invoke and interact with Amazon Bedrock Agents. It uses the boto3 Bedrock Agent Runtime client to send queries to a specified Bedrock agent identified by agent_id and agent_alias_id. The tool supports session management through session_id (defaulting to a timestamp-based ID), optional execution tracing via enable_trace, and session termination with end_session. Each query is formatted with the current UTC time for temporal context. The tool handles Bedrock's streaming response format by extracting bytes from completion chunks, with fallback to direct response format. Comprehensive parameter validation checks for required IDs and proper types using custom BedrockValidationError and BedrockAgentError exception classes. Configuration values can be provided via constructor parameters or environment variables (BEDROCK_AGENT_ID, BEDROCK_AGENT_ALIAS_ID).

Usage

Import and instantiate BedrockInvokeAgentTool when you need CrewAI agents to delegate tasks to Amazon Bedrock managed agents. This enables hybrid architectures where CrewAI handles orchestration while Bedrock agents handle domain-specific operations within the AWS security perimeter.

Code Reference

Source Location

  • Repository: CrewAI
  • File: lib/crewai-tools/src/crewai_tools/aws/bedrock/agents/invoke_agent_tool.py
  • Lines: 1-187

Signature

class BedrockInvokeAgentTool(BaseTool):
    def __init__(
        self,
        agent_id: str | None = None,
        agent_alias_id: str | None = None,
        session_id: str | None = None,
        enable_trace: bool = False,
        end_session: bool = False,
        description: str | None = None,
        **kwargs,
    ):

Import

from crewai_tools.aws.bedrock.agents import BedrockInvokeAgentTool

I/O Contract

Inputs (Constructor)

Name Type Required Description
agent_id None No Unique identifier of the Bedrock agent; falls back to BEDROCK_AGENT_ID env var
agent_alias_id None No Unique identifier of the agent alias; falls back to BEDROCK_AGENT_ALIAS_ID env var
session_id None No Session identifier for conversation continuity; defaults to timestamp
enable_trace bool No Whether to enable trace for agent invocation (default: False)
end_session bool No Whether to end the session with the agent (default: False)
description None No Custom description override for the tool

Inputs (_run)

Name Type Required Description
query str Yes The query to send to the Bedrock agent

Outputs

Name Type Description
return str The completion text extracted from the Bedrock agent's streaming or direct response

Usage Examples

Basic Usage

from crewai_tools.aws.bedrock.agents import BedrockInvokeAgentTool

# Initialize with explicit IDs
tool = BedrockInvokeAgentTool(
    agent_id="ABCDE12345",
    agent_alias_id="FGHIJ67890",
    description="Policy analysis agent for compliance queries",
)

# Use with a CrewAI agent
agent = Agent(
    role="compliance_officer",
    tools=[tool],
)

Environment Variable Configuration

import os
os.environ["BEDROCK_AGENT_ID"] = "ABCDE12345"
os.environ["BEDROCK_AGENT_ALIAS_ID"] = "FGHIJ67890"

tool = BedrockInvokeAgentTool(enable_trace=True)
result = tool._run(query="What is the refund policy for premium customers?")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment