microsoft/semantic-kernel · error · RuntimeError

Run failed with status: `{run_failed.status}` for agent `{ag

Error message

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}

What it means

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.

Source

Thrown at python/semantic_kernel/agents/azure_ai/agent_thread_actions.py:805

                    logger.info(f"Run completed with ID: {run.id}")
                    if active_messages:
                        for msg_id, step in active_messages.items():
                            message = await cls._retrieve_message(agent=agent, thread_id=thread_id, message_id=msg_id)
                            if message and hasattr(message, "content"):
                                final_content = generate_message_content(agent.name, message, step)
                                if output_messages is not None:
                                    output_messages.append(final_content)
                    return

                elif event_type == AgentStreamEvent.THREAD_RUN_FAILED:
                    run_failed = cast(ThreadRun, event_data)
                    error_message = "None"
                    if run_failed.last_error and run_failed.last_error.message:
                        error_message = run_failed.last_error.message
                    incomplete_details_reason = "None"
                    if run_failed.incomplete_details and run_failed.incomplete_details.reason:
                        incomplete_details_reason = run_failed.incomplete_details.reason
                    raise RuntimeError(
                        f"Run failed with status: `{run_failed.status}` for agent `{agent.name}` "
                        f"thread `{thread_id}` with error: {error_message} and incomplete details reason: "
                        f"{incomplete_details_reason}"
                    )
            else:
                break
        return

    # endregion

    # region Messaging Handling Methods

    @classmethod
    async def create_thread(
        cls: type[_T],
        client: "AIProjectClient",
        **kwargs: Any,
    ) -> str:

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Parse the embedded last_error / incomplete_details_reason to find the root cause and remediate (content, quota, tool).
  2. Retry the stream with backoff for transient failures; consider a shorter run or reduced output.
  3. Catch RuntimeError (or AgentInvokeException) around the async-for and fall back to non-streaming invoke if streaming keeps failing.
  4. Verify function tools complete successfully before streaming heavy outputs.
Defensive patterns

Strategy: retry

Type guard

def stream_event_is_run_failed(event_type) -> bool:
    return str(event_type) == 'thread.run.failed'

Try / catch

import time
for attempt in range(3):
    try:
        async for chunk in agent.invoke_stream(thread=thread):
            ...
        break
    except RuntimeError as e:
        if 'Run failed' in str(e) and attempt < 2:
            time.sleep(2 ** attempt)
            continue
        # fall back to non-streaming
        async for r in agent.invoke(thread=thread):
            ...
        break

Prevention

When it happens

Trigger: Streaming an AzureAIAgent via invoke_stream and the server-side run fails (content filter, tool error, cancellation, rate limit) partway through token delivery.

Common situations: Long streaming runs hitting token/time limits; content policy triggers mid-response; function-tool failures during streaming; transient Azure failures.

Related errors


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