microsoft/semantic-kernel · error · ValueError

Only user messages are supported for invoking a Bedrock agen

Error message

Only user messages are supported for invoking a Bedrock agent.

What it means

Raised by BedrockAgentBase._invoke_agent when the message argument is a ChatMessageContent whose role is not AuthorRole.USER. Bedrock's invoke_agent API only accepts a single user inputText, so assistant/system/tool messages are rejected before the call.

Source

Thrown at python/semantic_kernel/agents/bedrock/bedrock_agent_base.py:363

        except ClientError as e:
            logger.error(f"Failed to list associated knowledge bases for agent {self.agent_model.agent_id}.")
            raise e

    # endregion Knowledge Base Management

    async def _invoke_agent(
        self,
        thread_id: str,
        message: str | ChatMessageContent,
        agent_alias: str | None = None,
        **kwargs,
    ) -> dict[str, Any]:
        """Invoke an agent."""
        if not self.agent_model.agent_id:
            raise ValueError("Agent does not exist. Please create the agent before invoking it.")

        if isinstance(message, ChatMessageContent) and message.role != AuthorRole.USER:
            raise ValueError("Only user messages are supported for invoking a Bedrock agent.")

        agent_alias = agent_alias or self.WORKING_DRAFT_AGENT_ALIAS

        try:
            return await run_in_executor(
                None,
                partial(
                    self.bedrock_runtime_client.invoke_agent,
                    agentAliasId=agent_alias,
                    agentId=self.agent_model.agent_id,
                    sessionId=thread_id,
                    inputText=message if isinstance(message, str) else message.content,
                    **kwargs,
                ),
            )
        except ClientError as e:
            logger.error(f"Failed to invoke agent {self.agent_model.agent_id}.")
            raise e

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass a plain str, or a ChatMessageContent explicitly constructed with role=AuthorRole.USER.
  2. Extract only the user-authored text when forwarding history: use message.content with role check.
  3. Keep system-level instructions in the agent's instruction field, not as a message passed to invoke.
  4. Normalize your message pipeline so only USER-role content reaches the Bedrock agent.

Example fix

// before
msg = ChatMessageContent(role=AuthorRole.SYSTEM, content='be concise')
await agent._invoke_agent(thread_id, msg)  # raises
// after
await agent._invoke_agent(thread_id, 'be concise')  # str is fine
// or
msg = ChatMessageContent(role=AuthorRole.USER, content='hello')
await agent._invoke_agent(thread_id, msg)
Defensive patterns

Strategy: type-guard

Validate before calling

from semantic_kernel.contents.utils.author_role import AuthorRole
from semantic_kernel.contents.chat_message_content import ChatMessageContent

def to_bedrock_input(message):
    if isinstance(message, ChatMessageContent):
        if message.role != AuthorRole.USER:
            raise ValueError('Only USER-role messages are accepted by Bedrock invoke')
        return message.content
    return message

Type guard

def is_user_message(message) -> bool:
    return isinstance(message, str) or (
        isinstance(message, ChatMessageContent) and message.role == AuthorRole.USER
    )

Try / catch

try:
    await agent.get_response(msg)
except ValueError as e:
    if 'Only user messages' in str(e):
        msg = ChatMessageContent(role=AuthorRole.USER, content=msg.content if hasattr(msg,'content') else str(msg))
        await agent.get_response(msg)
    else: raise

Prevention

When it happens

Trigger: Passing a ChatMessageContent with role SYSTEM, ASSISTANT, or TOOL into the Bedrock invoke path; feeding back an assistant response object as the next input; using a chat history item of non-user role as the invoke message.

Common situations: Reusing message objects from a prior turn without role normalization; passing a system prompt wrapped in ChatMessageContent instead of using agent instructions; loops that feed the last history message regardless of role.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/3e6ec6b7e3d8a1fb. Report an issue: GitHub.