crewAIInc/crewAI · error · BedrockAgentError

Error ({error_code}): {error_message}

Error message

Error ({error_code}): {error_message}

What it means

A BedrockAgentError raised when boto3 raises ClientError during InvokeAgent — i.e. the AWS API call itself failed. The handler extracts error_code and error_message from e.response['Error'] (Code/Message) when present, defaulting to 'Unknown' and str(e), and formats them as "Error (<code>): <message>".

Source

Thrown at lib/crewai-tools/src/crewai_tools/aws/bedrock/agents/invoke_agent_tool.py:172

                if "chunk" in response:
                    debug_info["chunk_keys"] = list(response["chunk"].keys())

                raise BedrockAgentError(
                    f"Failed to extract completion: {json.dumps(debug_info, indent=2)}"
                )

            return completion

        except ClientError as e:
            error_code = "Unknown"
            error_message = str(e)

            # Try to extract error code if available
            if hasattr(e, "response") and "Error" in e.response:
                error_code = e.response["Error"].get("Code", "Unknown")
                error_message = e.response["Error"].get("Message", str(e))

            raise BedrockAgentError(f"Error ({error_code}): {error_message}") from e
        except BedrockAgentError:
            # Re-raise BedrockAgentError exceptions
            raise
        except Exception as e:
            raise BedrockAgentError(f"Unexpected error: {e!s}") from e

View on GitHub (pinned to 754d7323be)

Solutions

  1. Read the code in the message: AccessDeniedException → grant bedrock:InvokeAgent and bedrock:InvokeModel; ResourceNotFoundException → verify agent_id/alias_id and region.
  2. Set the region explicitly: export AWS_REGION=us-east-1 (the tool defaults to us-west-2).
  3. Refresh credentials: aws sso login / aws sts get-caller-identity to verify the active identity.
  4. For ThrottlingException, add backoff/retry or reduce request rate.

Example fix

# before: Error (AccessDeniedException): ... because region defaults to us-west-2
# after — pin the correct region in the environment
import os
os.environ["AWS_REGION"] = "us-east-1"  # before creating the tool/agent
Defensive patterns

Strategy: try-catch

Validate before calling

import boto3, os

sts = boto3.client("sts")
sts.get_caller_identity()  # fail fast on bad credentials
os.environ.setdefault("AWS_REGION", "us-east-1")  # avoid silent us-west-2 default

Try / catch

from crewai_tools.aws.bedrock.agents.invoke_agent_tool import BedrockAgentError

try:
    result = tool._run(query)
except BedrockAgentError as e:
    msg = str(e)
    if "AccessDeniedException" in msg:
        fix_iam()          # grant bedrock:InvokeAgent
    elif "ResourceNotFound" in msg:
        check_ids_and_region()
    elif "ThrottlingException" in msg:
        backoff_and_retry()
    else:
        raise

Prevention

When it happens

Trigger: Any AWS-side failure: AccessDeniedException (bad/missing IAM credentials), ResourceNotFoundException (wrong agent_id/alias), ValidationException (bad request payload), ThrottlingException, ModelStreamErrorException, or expired AWS session tokens — all surface as botocore ClientError in _run and get re-wrapped here.

Common situations: Missing bedrock:InvokeAgent IAM permission; unset AWS credentials in the environment; wrong region (agent exists in us-east-1 but default us-west-2 is used — the code reads AWS_REGION/AWS_DEFAULT_REGION with us-west-2 fallback); expired SSO tokens; deleted agent or alias.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/33581e27124c82c9. Report an issue: GitHub.