{"record":{"id":"ca822a1f92534e93","repo":"microsoft/semantic-kernel","slug":"run-failed-with-status-run-failed-status-for","errorCode":null,"errorMessage":"Run failed with status: `{run_failed.status}` for agent `{agent.name}` thread `{thread_id}` with error: {error_message} and incomplete details reason: {incomplete_details_reason}","messagePattern":"Run failed with status: `(.+?)` for agent `(.+?)` thread `(.+?)` with error: (.+?) and incomplete details reason: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/azure_ai/agent_thread_actions.py","lineNumber":805,"sourceCode":"                    logger.info(f\"Run completed with ID: {run.id}\")\n                    if active_messages:\n                        for msg_id, step in active_messages.items():\n                            message = await cls._retrieve_message(agent=agent, thread_id=thread_id, message_id=msg_id)\n                            if message and hasattr(message, \"content\"):\n                                final_content = generate_message_content(agent.name, message, step)\n                                if output_messages is not None:\n                                    output_messages.append(final_content)\n                    return\n\n                elif event_type == AgentStreamEvent.THREAD_RUN_FAILED:\n                    run_failed = cast(ThreadRun, event_data)\n                    error_message = \"None\"\n                    if run_failed.last_error and run_failed.last_error.message:\n                        error_message = run_failed.last_error.message\n                    incomplete_details_reason = \"None\"\n                    if run_failed.incomplete_details and run_failed.incomplete_details.reason:\n                        incomplete_details_reason = run_failed.incomplete_details.reason\n                    raise RuntimeError(\n                        f\"Run failed with status: `{run_failed.status}` for agent `{agent.name}` \"\n                        f\"thread `{thread_id}` with error: {error_message} and incomplete details reason: \"\n                        f\"{incomplete_details_reason}\"\n                    )\n            else:\n                break\n        return\n\n    # endregion\n\n    # region Messaging Handling Methods\n\n    @classmethod\n    async def create_thread(\n        cls: type[_T],\n        client: \"AIProjectClient\",\n        **kwargs: Any,\n    ) -> str:","sourceCodeStart":787,"sourceCodeEnd":823,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/azure_ai/agent_thread_actions.py#L787-L823","documentation":"The streaming counterpart of error 716: raised as a RuntimeError when an AgentStreamEvent.THREAD_RUN_FAILED event arrives during streaming invoke. It reports run_failed.status, agent name, thread id, last_error message, and incomplete_details reason so the caller knows the run died mid-stream.","triggerScenarios":"Streaming an AzureAIAgent via invoke_stream and the server-side run fails (content filter, tool error, cancellation, rate limit) partway through token delivery.","commonSituations":"Long streaming runs hitting token/time limits; content policy triggers mid-response; function-tool failures during streaming; transient Azure failures.","solutions":["Parse the embedded last_error / incomplete_details_reason to find the root cause and remediate (content, quota, tool).","Retry the stream with backoff for transient failures; consider a shorter run or reduced output.","Catch RuntimeError (or AgentInvokeException) around the async-for and fall back to non-streaming invoke if streaming keeps failing.","Verify function tools complete successfully before streaming heavy outputs."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"def stream_event_is_run_failed(event_type) -> bool:\n    return str(event_type) == 'thread.run.failed'","tryCatchPattern":"import time\nfor attempt in range(3):\n    try:\n        async for chunk in agent.invoke_stream(thread=thread):\n            ...\n        break\n    except RuntimeError as e:\n        if 'Run failed' in str(e) and attempt < 2:\n            time.sleep(2 ** attempt)\n            continue\n        # fall back to non-streaming\n        async for r in agent.invoke(thread=thread):\n            ...\n        break","preventionTips":["Apply backoff for transient streaming run failures.","Keep runs within token/time limits to avoid mid-stream failures.","Have a non-streaming fallback path."],"tags":["azure-ai","streaming","run-status","retry","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}