crewAIInc/crewAI · error · BedrockValidationError

agent_id must be a string

Error message

agent_id must be a string

What it means

A BedrockValidationError raised when agent_id is truthy but not a str instance (e.g. an int or a list). The empty check passed, but AWS requires agent_id to be a string, so isinstance(self.agent_id, str) fails. The outer except re-wraps it as "Parameter validation failed: agent_id must be a string".

Source

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

        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
        except ImportError as e:
            raise ImportError(

View on GitHub (pinned to 754d7323be)

Solutions

  1. Convert to str at the call site: `agent_id=str(agent_id)`.
  2. Fix the config source so the ID is quoted as a string (YAML/JSON schema or pydantic model with agent_id: str).
  3. Unwrap collections: if you have a list, pick one ID — the tool invokes a single agent.

Example fix

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

# after
tool = BedrockAgentTools(agent_id=str(1234567890), agent_alias_id="TSTALIASID")
Defensive patterns

Strategy: type-guard

Validate before calling

agent_id = str(agent_id).strip()
if not agent_id:
    raise ValueError("agent_id empty")

Type guard

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

Try / catch

try:
    tool = BedrockAgentTools(agent_id=agent_id, agent_alias_id=alias)
except BedrockValidationError as e:
    if "agent_id must be a string" in str(e):
        tool = BedrockAgentTools(agent_id=str(agent_id), agent_alias_id=alias)
    else:
        raise

Prevention

When it happens

Trigger: Passing agent_id as a non-string truthy value: an int from JSON config, a list/tuple from a misparsed YAML, or a dict. Constructed tools validate in __init__, so the error appears at creation time.

Common situations: Config parsed with a numeric-looking ID kept as a number, programmatic ID from another SDK returned as bytes/enum, or passing a list of IDs intending multi-agent use (not supported by this tool).

Related errors


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