microsoft/semantic-kernel · error · AgentInvokeException

Chat message content is expected but not found in the…

Error message

Chat message content is expected but not found in the response.

What it means

Raised by get_response when the agent's response events contain no chunk event (BedrockAgentEventType.CHUNK) or the chunk produces empty content. The loop over events only sets chat_message_content from a CHUNK event; if only FILES or TRACE events arrive (or nothing parseable), the guard at line 341 fires. This indicates the agent produced a non-text response or the event stream was malformed.

Solutions

  1. Inspect the raw events in the response (response['completion']) to see what event types arrived and whether a chunk exists.
  2. Verify the agent is PREPARED and has valid instructions and a foundation model that produces text output.
  3. Check streamingConfigurations — ensure streamFinalResponse is not suppressing the final chunk.
  4. Retry the invocation; if persistent, re-prepare the agent or test with a different foundation model.

Example fix

// before
response = await agent.get_response(message="summarize", thread=thread)
# raises: Chat message content is expected but not found

// after
# Debug: dump events first
raw = await agent._invoke_agent(thread.id, "summarize")
print(raw.get('completion'))  # inspect event types
# Then verify agent is prepared:
await agent.prepare_agent_and_wait_until_prepared()
Defensive patterns

Strategy: try-catch

Try / catch

from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException

try:
    resp = await agent.get_response(message="test", thread=thread)
except AgentInvokeException as e:
    if "Chat message content is expected" in str(e):
        # inspect raw events, verify agent is PREPARED, check streamingConfigurations
        raw = await agent._invoke_agent(thread.id, "test")
        event_types = [next(iter(k for k in ev)) for ev in raw.get("completion", [])]
        logger.error("Event types received: %s", event_types)
        await agent.prepare_agent_and_wait_until_prepared()
        resp = await agent.get_response(message="test", thread=thread)
    else:
        raise

Prevention

When it happens

Trigger: Triggered in get_response when, after exiting the RETURN_CONTROL branch, the events list contains no chunk event with decodable bytes — e.g. only trace/files events, or a chunk whose 'bytes' field decodes to an empty string.

Common situations: The agent returned only a trace or files event with no text; the foundation model returned an empty completion; streamingConfigurations suppressed the final chunk; the agent is misconfigured or the model produced an empty generation; partial/network truncation of the event stream.

Related errors


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

Appendix: source

Thrown at python/semantic_kernel/agents/bedrock/bedrock_agent.py:342

                        arguments,
                    )
                )
            else:
                # For the rest of the events, the chunk will become the chat message content.
                # If there are files or trace, they will be added to the chat message content.
                file_items: list[BinaryContent] | None = None
                trace_metadata: dict[str, Any] | None = None
                chat_message_content: ChatMessageContent | None = None
                for event in events:
                    if BedrockAgentEventType.CHUNK in event:
                        chat_message_content = self._handle_chunk_event(event)
                    elif BedrockAgentEventType.FILES in event:
                        file_items = self._handle_files_event(event)
                    elif BedrockAgentEventType.TRACE in event:
                        trace_metadata = self._handle_trace_event(event)

                if not chat_message_content or not chat_message_content.content:
                    raise AgentInvokeException("Chat message content is expected but not found in the response.")

                if file_items:
                    chat_message_content.items.extend(file_items)
                if trace_metadata:
                    chat_message_content.metadata.update({"trace": trace_metadata})

                if not chat_message_content:
                    raise AgentInvokeException("No response from the agent.")

                chat_message_content.metadata["thread_id"] = thread.id
                return AgentResponseItem(message=chat_message_content, thread=thread)

        raise AgentInvokeException(
            "Failed to get a response from the agent. Please consider increasing the auto invoke attempts."
        )

    @trace_agent_invocation
    @override

View on GitHub (pinned to c028a0c7dc)