{"record":{"id":"dcfbfac287e8d1f6","repo":"microsoft/semantic-kernel","slug":"chat-message-content-is-expected-but-not-found-in","errorCode":null,"errorMessage":"Chat message content is expected but not found in the response.","messagePattern":"Chat message content is expected but not found in the response\\.","errorType":"exception","errorClass":"AgentInvokeException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/bedrock/bedrock_agent.py","lineNumber":342,"sourceCode":"                        arguments,\n                    )\n                )\n            else:\n                # For the rest of the events, the chunk will become the chat message content.\n                # If there are files or trace, they will be added to the chat message content.\n                file_items: list[BinaryContent] | None = None\n                trace_metadata: dict[str, Any] | None = None\n                chat_message_content: ChatMessageContent | None = None\n                for event in events:\n                    if BedrockAgentEventType.CHUNK in event:\n                        chat_message_content = self._handle_chunk_event(event)\n                    elif BedrockAgentEventType.FILES in event:\n                        file_items = self._handle_files_event(event)\n                    elif BedrockAgentEventType.TRACE in event:\n                        trace_metadata = self._handle_trace_event(event)\n\n                if not chat_message_content or not chat_message_content.content:\n                    raise AgentInvokeException(\"Chat message content is expected but not found in the response.\")\n\n                if file_items:\n                    chat_message_content.items.extend(file_items)\n                if trace_metadata:\n                    chat_message_content.metadata.update({\"trace\": trace_metadata})\n\n                if not chat_message_content:\n                    raise AgentInvokeException(\"No response from the agent.\")\n\n                chat_message_content.metadata[\"thread_id\"] = thread.id\n                return AgentResponseItem(message=chat_message_content, thread=thread)\n\n        raise AgentInvokeException(\n            \"Failed to get a response from the agent. Please consider increasing the auto invoke attempts.\"\n        )\n\n    @trace_agent_invocation\n    @override","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/bedrock/bedrock_agent.py#L324-L360","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the raw events in the response (response['completion']) to see what event types arrived and whether a chunk exists.","Verify the agent is PREPARED and has valid instructions and a foundation model that produces text output.","Check streamingConfigurations — ensure streamFinalResponse is not suppressing the final chunk.","Retry the invocation; if persistent, re-prepare the agent or test with a different foundation model."],"exampleFix":"// before\nresponse = await agent.get_response(message=\"summarize\", thread=thread)\n# raises: Chat message content is expected but not found\n\n// after\n# Debug: dump events first\nraw = await agent._invoke_agent(thread.id, \"summarize\")\nprint(raw.get('completion'))  # inspect event types\n# Then verify agent is prepared:\nawait agent.prepare_agent_and_wait_until_prepared()","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInvokeException\n\ntry:\n    resp = await agent.get_response(message=\"test\", thread=thread)\nexcept AgentInvokeException as e:\n    if \"Chat message content is expected\" in str(e):\n        # inspect raw events, verify agent is PREPARED, check streamingConfigurations\n        raw = await agent._invoke_agent(thread.id, \"test\")\n        event_types = [next(iter(k for k in ev)) for ev in raw.get(\"completion\", [])]\n        logger.error(\"Event types received: %s\", event_types)\n        await agent.prepare_agent_and_wait_until_prepared()\n        resp = await agent.get_response(message=\"test\", thread=thread)\n    else:\n        raise","preventionTips":["Ensure the agent is in PREPARED status before invoking.","Verify streamingConfigurations does not suppress the final response chunk.","Inspect the raw completion events when debugging to identify missing chunk events.","Confirm the foundation model produces text output for the given prompt."],"tags":["bedrock","response-parsing","empty-response","chunk-event","get-response"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}