crewAIInc/crewAI · error · BedrockValidationError

agent_id cannot be empty

Error message

agent_id cannot be empty

What it means

A BedrockValidationError raised in BedrockAgentTools._validate_parameters when the agent_id parameter is falsy (None, empty string). It is immediately re-wrapped as "Parameter validation failed: agent_id cannot be empty" by the except block, so the surfaced message is the wrapped form. Validation runs in __init__, so the tool never constructs with an empty agent_id.

Source

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

        # Get values from environment variables if not provided
        self.agent_id = agent_id or os.getenv("BEDROCK_AGENT_ID")
        self.agent_alias_id = agent_alias_id or os.getenv("BEDROCK_AGENT_ALIAS_ID")
        self.session_id = session_id or str(
            int(time.time())
        )  # Use timestamp as session ID if not provided
        self.enable_trace = enable_trace
        self.end_session = end_session

        if description:
            self.description = description

        self._validate_parameters()

    def _validate_parameters(self) -> None:
        """Validate the parameters according to AWS API requirements."""
        try:
            if not self.agent_id:
                raise BedrockValidationError("agent_id cannot be empty")
            if not isinstance(self.agent_id, str):
                raise BedrockValidationError("agent_id must be a string")

            if not self.agent_alias_id:
                raise BedrockValidationError("agent_alias_id cannot be empty")
            if not isinstance(self.agent_alias_id, str):
                raise BedrockValidationError("agent_alias_id must be a string")

            if self.session_id and not isinstance(self.session_id, str):
                raise BedrockValidationError("session_id must be a string")

        except BedrockValidationError as e:
            raise BedrockValidationError(f"Parameter validation failed: {e!s}") from e

    def _run(self, query: str) -> str:
        try:
            import boto3
            from botocore.exceptions import ClientError

View on GitHub (pinned to 754d7323be)

Solutions

  1. Supply a real Bedrock agent ID: it looks like 'XXXXXXXXXX' (10 alphanumeric chars) from the Bedrock Agents console.
  2. If reading from config/env, fail fast: `agent_id = os.environ['BEDROCK_AGENT_ID']` instead of a silent default.
  3. Check for typos: agent_id is the agent identifier, not the agent name or the alias.

Example fix

# before
tool = BedrockAgentTools(agent_id="", agent_alias_id="TSTALIASID")

# after
import os
tool = BedrockAgentTools(
    agent_id=os.environ["BEDROCK_AGENT_ID"],
    agent_alias_id=os.environ["BEDROCK_AGENT_ALIAS_ID"],
)
Defensive patterns

Strategy: validation

Validate before calling

import re

def valid_agent_id(v) -> bool:
    return isinstance(v, str) and bool(v.strip())

Type guard

def is_agent_id(v) -> bool:
    return isinstance(v, str) and bool(v)

Try / catch

try:
    tool = BedrockAgentTools(agent_id=agent_id, agent_alias_id=alias)
except BedrockValidationError as e:
    raise ValueError(f"Bad Bedrock agent config: {e}") from e

Prevention

When it happens

Trigger: Creating BedrockAgentTools (or the underlying invoke-agent tool) with agent_id='' or agent_id=None. Because the empty check precedes the isinstance check, a non-string truthy value fails the next check instead. The except clause at line 90 re-raises the wrapped message.

Common situations: Loading agent_id from an env var or config that is unset (defaults to '' or None), template code where the placeholder was never filled in, or passing agentAliasId where agentId was expected so agent_id is left blank.

Related errors


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