Skip to content

Unhandled exception when conent field is empty in the Agent TextMessage for AWSBedrock Model using SemanticKernel Adapter #6479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
amardeepjaiman opened this issue May 7, 2025 · 1 comment

Comments

@amardeepjaiman
Copy link

What happened?

Describe the bug
I am using Autogen Extension for SemanticKernel Adapter to use AWS Bedrock Nova-lite model as model client.
Team Type: Swarm

While I am running the flow using couple of AssitantAgent, I am getting following exception while running the flow where in one of the TextMessage sent by AssistantAgent "content" field is not set and this agent is not able to publish the message to next agent in the flow and exception is not handled in the the autogen framework.

Stacktrace:

2025-05-07 18:22:49,181 - autogen_core.trace - INFO - message type: <class 'autogen_agentchat.messages.TextMessage'>
2025-05-07 18:22:49,181 - autogen_core.trace - INFO - msg packet content: {'source': 'AnalyzeAgent', 'models_usage': {'prompt_tokens': 1215, 'completion_tokens': 0}, 'metadata': {}, 'content': '', 'type': 'TextMessage'}
Error processing publish message for AnalyzeAgent_5ebb3cf0-4391-4a6b-8fd1-490bafca300e/5ebb3cf0-4391-4a6b-8fd1-490bafca300e
Traceback (most recent call last):
File ".venv2\Lib\site-packages\autogen_core_single_threaded_agent_runtime.py", line 533, in _on_message
return await agent.on_message(
^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_core_base_agent.py", line 113, in on_message
return await self.on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File .venv2\Lib\site-packages\autogen_agentchat\teams_group_chat_sequential_routed_agent.py", line 67, in on_message_impl
return await super().on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ajaiman\Projects\code\Official\AgenticAI-ITSM.venv2\Lib\site-packages\autogen_core_routed_agent.py", line 485, in on_message_impl
return await h(self, message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ajaiman\Projects\code\Official\AgenticAI-ITSM.venv2\Lib\site-packages\autogen_core_routed_agent.py", line 268, in wrapper
return_value = await func(self, message, ctx) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv2\Lib\site-packages\autogen_agentchat\teams_group_chat_chat_agent_container.py", line 79, in handle_request
async for msg in self._agent.on_messages_stream(self._message_buffer, ctx.cancellation_token):
File ".venv2\Lib\site-packages\autogen_agentchat\agents_assistant_agent.py", line 827, in on_messages_stream
async for inference_output in self._call_llm(
File ".venv2\Lib\site-packages\autogen_agentchat\agents_assistant_agent.py", line 955, in _call_llm
model_result = await model_client.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ajaiman\Projects\code\Official\AgenticAI-ITSM.venv2\Lib\site-packages\autogen_ext\models\semantic_kernel_sk_chat_completion_adapter.py", line 482, in create
result = await self._sk_client.get_chat_message_contents(chat_history, settings=settings, kernel=kernel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\semantic_kernel\connectors\ai\chat_completion_client_base.py", line 134, in get_chat_message_contents
return await self._inner_get_chat_message_contents(chat_history, settings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\semantic_kernel\utils\telemetry\model_diagnostics\decorators.py", line 112, in wrapper_decorator
return await completion_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv2\Lib\site-packages\semantic_kernel\connectors\ai\bedrock\services\bedrock_chat_completion.py", line 118, in _inner_get_chat_message_contents
response = await self._async_converse(**prepared_settings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File .venv2\Lib\site-packages\semantic_kernel\connectors\ai\bedrock\services\bedrock_chat_completion.py", line 276, in _async_converse
return await run_in_executor(
^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\semantic_kernel\utils\async_utils.py", line 11, in run_in_executor
return await asyncio.get_event_loop().run_in_executor(executor, partial(func, *args, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv2\Lib\site-packages\botocore\client.py", line 570, in _api_call
return self._make_api_call(operation_name, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv2\Lib\site-packages\botocore\context.py", line 124, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\botocore\client.py", line 1031, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the Converse operation: The content field in the Message object at messages.5 is empty. Add a ContentBlock object to the content field and try again.
Error processing publish message for PlanningAgent_5ebb3cf0-4391-4a6b-8fd1-490bafca300e/5ebb3cf0-4391-4a6b-8fd1-490bafca300e
Traceback (most recent call last):
File venv2\Lib\site-packages\autogen_core_single_threaded_agent_runtime.py", line 533, in _on_message
return await agent.on_message(
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ajaiman\Projects\code\Official\AgenticAI-ITSM.venv2\Lib\site-packages\autogen_core_base_agent.py", line 113, in on_message
return await self.on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_agentchat\teams_group_chat_sequential_routed_agent.py", line 72, in on_message_impl
return await super().on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File .venv2\Lib\site-packages\autogen_core_routed_agent.py", line 486, in on_message_impl
return await self.on_unhandled_message(message, ctx) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_agentchat\teams_group_chat_chat_agent_container.py", line 133, in on_unhandled_message
raise ValueError(f"Unhandled message in agent container: {type(message)}")
ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'>
Error processing publish message for ApplicationInsightsAgent_5ebb3cf0-4391-4a6b-8fd1-490bafca300e/5ebb3cf0-4391-4a6b-8fd1-490bafca300e
Traceback (most recent call last):
File ".venv2\Lib\site-packages\autogen_core_single_threaded_agent_runtime.py", line 533, in _on_message
return await agent.on_message(
^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_core_base_agent.py", line 113, in on_message
return await self.on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_agentchat\teams_group_chat_sequential_routed_agent.py", line 72, in on_message_impl
return await super().on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv2\Lib\site-packages\autogen_core_routed_agent.py", line 486, in on_message_impl
return await self.on_unhandled_message(message, ctx) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_agentchat\teams_group_chat_chat_agent_container.py", line 133, in on_unhandled_message
raise ValueError(f"Unhandled message in agent container: {type(message)}")
ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'>
Error processing publish message for LogsAnalyzeAgent_5ebb3cf0-4391-4a6b-8fd1-490bafca300e/5ebb3cf0-4391-4a6b-8fd1-490bafca300e
Traceback (most recent call last):
File .venv2\Lib\site-packages\autogen_core_single_threaded_agent_runtime.py", line 533, in _on_message
return await agent.on_message(
^^^^^^^^^^^^^^^^^^^^^^^
File "venv2\Lib\site-packages\autogen_core_base_agent.py", line 113, in on_message
return await self.on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_agentchat\teams_group_chat_sequential_routed_agent.py", line 72, in on_message_impl
return await super().on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_core_routed_agent.py", line 486, in on_message_impl
return await self.on_unhandled_message(message, ctx) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\Lib\site-packages\autogen_agentchat\teams_group_chat_chat_agent_container.py", line 133, in on_unhandled_message
raise ValueError(f"Unhandled message in agent container: {type(message)}")
ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'>
Error processing publish message for IncidentCreationAgent_5ebb3cf0-4391-4a6b-8fd1-490bafca300e/5ebb3cf0-4391-4a6b-8fd1-490bafca300e
Traceback (most recent call last):
File .venv2\Lib\site-packages\autogen_core_single_threaded_agent_runtime.py", line 533, in _on_message
return await agent.on_message(
^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_core_base_agent.py", line 113, in on_message
return await self.on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_agentchat\teams_group_chat_sequential_routed_agent.py", line 72, in on_message_impl
return await super().on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_core_routed_agent.py", line 486, in on_message_impl
return await self.on_unhandled_message(message, ctx) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_agentchat\teams_group_chat_chat_agent_container.py", line 133, in on_unhandled_message
raise ValueError(f"Unhandled message in agent container: {type(message)}")
ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'>
Error processing publish message for ResearchAgent_5ebb3cf0-4391-4a6b-8fd1-490bafca300e/5ebb3cf0-4391-4a6b-8fd1-490bafca300e
Traceback (most recent call last):
File ".venv2\Lib\site-packages\autogen_core_single_threaded_agent_runtime.py", line 533, in _on_message
return await agent.on_message(
^^^^^^^^^^^^^^^^^^^^^^^
File .venv2\Lib\site-packages\autogen_core_base_agent.py", line 113, in on_message
return await self.on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_agentchat\teams_group_chat_sequential_routed_agent.py", line 72, in on_message_impl
return await super().on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv2\Lib\site-packages\autogen_core_routed_agent.py", line 486, in on_message_impl
return await self.on_unhandled_message(message, ctx) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ajaiman\Projects\code\Official\AgenticAI-ITSM.venv2\Lib\site-packages\autogen_agentchat\teams_group_chat_chat_agent_container.py", line 133, in on_unhandled_message
raise ValueError(f"Unhandled message in agent container: {type(message)}")
ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'>
Error processing publish message for KnowledgeAgent_5ebb3cf0-4391-4a6b-8fd1-490bafca300e/5ebb3cf0-4391-4a6b-8fd1-490bafca300e
Traceback (most recent call last):
File ".venv2\Lib\site-packages\autogen_core_single_threaded_agent_runtime.py", line 533, in _on_message
return await agent.on_message(
^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_core_base_agent.py", line 113, in on_message
return await self.on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File Lib\site-packages\autogen_agentchat\teams_group_chat_sequential_routed_agent.py", line 72, in on_message_impl
return await super().on_message_impl(message, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "venv2\Lib\site-packages\autogen_core_routed_agent.py", line 486, in on_message_impl
return await self.on_unhandled_message(message, ctx) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv2\Lib\site-packages\autogen_agentchat\teams_group_chat_chat_agent_container.py", line 133, in on_unhandled_message
raise ValueError(f"Unhandled message in agent container: {type(message)}")
ValueError: Unhandled message in agent container: <class 'autogen_agentchat.teams._group_chat._events.GroupChatError'>
2025-05-07 18:22:49,514 - autogen_core.trace - ERROR - Exception occured while team is processing the workflow: ValidationException: An error occurred (ValidationException) when calling the Converse operation: The content field in the Message object at messages.5 is empty. Add a ContentBlock object to the content field and try again.
Traceback:
Traceback (most recent call last):

File ".venv2\Lib\site-packages\autogen_agentchat\teams_group_chat_chat_agent_container.py", line 79, in handle_request
async for msg in self._agent.on_messages_stream(self._message_buffer, ctx.cancellation_token):

File "venv2\Lib\site-packages\autogen_agentchat\agents_assistant_agent.py", line 827, in on_messages_stream
async for inference_output in self._call_llm(

File ".venv2\Lib\site-packages\autogen_agentchat\agents_assistant_agent.py", line 955, in _call_llm
model_result = await model_client.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^

File ".venv2\Lib\site-packages\autogen_ext\models\semantic_kernel_sk_chat_completion_adapter.py", line 482, in create
result = await self._sk_client.get_chat_message_contents(chat_history, settings=settings, kernel=kernel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File ".venv2\Lib\site-packages\semantic_kernel\connectors\ai\chat_completion_client_base.py", line 134, in get_chat_message_contents
return await self._inner_get_chat_message_contents(chat_history, settings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\ajaiman\Projects\code\Official\AgenticAI-ITSM.venv2\Lib\site-packages\semantic_kernel\utils\telemetry\model_diagnostics\decorators.py", line 112, in wrapper_decorator
return await completion_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File ".venv2\Lib\site-packages\semantic_kernel\connectors\ai\bedrock\services\bedrock_chat_completion.py", line 118, in _inner_get_chat_message_contents
response = await self._async_converse(**prepared_settings)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File ".venv2\Lib\site-packages\semantic_kernel\connectors\ai\bedrock\services\bedrock_chat_completion.py", line 276, in _async_converse
return await run_in_executor(
^^^^^^^^^^^^^^^^^^^^^^

File ".venv2\Lib\site-packages\semantic_kernel\utils\async_utils.py", line 11, in run_in_executor
return await asyncio.get_event_loop().run_in_executor(executor, partial(func, *args, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File .venv2\Lib\site-packages\botocore\client.py", line 570, in _api_call
return self._make_api_call(operation_name, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "Lib\site-packages\botocore\context.py", line 124, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^

File ".venv2\Lib\site-packages\botocore\client.py", line 1031, in _make_api_call
raise error_class(parsed_response, operation_name)

botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the Converse operation: The content field in the Message object at messages.5 is empty. Add a ContentBlock object to the content field and try again.

To Reproduce
Steps to reproduce the behavior. Please include code and outputs such as stacktrace.

  • If your input is just "I tried X, and it didn't work" or
    "X is not working", your issue will be ignored.
  • If your input is not well formatted, it will hurt readability and
    may be ignored as well.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Which packages was the bug in?

Python AgentChat (autogen-agentchat>=0.4.0)

AutoGen library version.

Python 0.5.6

Other library version.

No response

Model used

amazon.nova-lite-v1:0

Model provider

AWS Bedrock

Other model provider

No response

Python version

3.11

.NET version

None

Operating system

Ubuntu

@amardeepjaiman
Copy link
Author

amardeepjaiman commented May 7, 2025

This is a blocking issue for me as I am not able to use AWS Bedrock models in Autogen application. May be some issue in semantic_kernel/connectors/ai/bedrock/services package while using the Converse API. but can it be handled in Autogen Groupchat level to continue the flow as currently its exiting the team run?

@amardeepjaiman amardeepjaiman changed the title Unhandled exception when conent field is empty in the Agent TextMessage Unhandled exception when conent field is empty in the Agent TextMessage for AWSBedrock Model using SemanticKernel Adapter May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant