microsoft/autogen · error · RuntimeError

No final model result in streaming mode.

Error message

No final model result in streaming mode.

What it means

AssistantAgent raised this after fully consuming model_client.create_stream() without ever receiving a CreateResult chunk. The ChatCompletionClient streaming contract requires string chunks as intermediate deltas and one final CreateResult carrying the complete response; when the stream ends with only deltas, the agent has no final message to add to context or yield.

Source

Thrown at python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py:1106

        tools = [tool for wb in workbench for tool in await wb.list_tools()] + handoff_tools

        if model_client_stream:
            model_result: Optional[CreateResult] = None

            async for chunk in model_client.create_stream(
                llm_messages,
                tools=tools,
                json_output=output_content_type,
                cancellation_token=cancellation_token,
            ):
                if isinstance(chunk, CreateResult):
                    model_result = chunk
                elif isinstance(chunk, str):
                    yield ModelClientStreamingChunkEvent(content=chunk, source=agent_name, full_message_id=message_id)
                else:
                    raise RuntimeError(f"Invalid chunk type: {type(chunk)}")
            if model_result is None:
                raise RuntimeError("No final model result in streaming mode.")
            yield model_result
        else:
            model_result = await model_client.create(
                llm_messages,
                tools=tools,
                cancellation_token=cancellation_token,
                json_output=output_content_type,
            )
            yield model_result

    @classmethod
    async def _process_model_result(
        cls,
        model_result: CreateResult,
        inner_messages: List[BaseAgentEvent | BaseChatMessage],
        cancellation_token: CancellationToken,
        agent_name: str,
        system_messages: List[SystemMessage],

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Fix the custom model client so create_stream() yields the complete CreateResult as its final item after all str deltas.
  2. If using a bundled client (autogen-ext), upgrade the autogen-ext package to match the autogen-agentchat version.
  3. Check client logs for swallowed exceptions that terminate the stream before the final result is produced.
  4. As a temporary workaround, construct the AssistantAgent with model_client_stream=False so the non-streaming create() path is used.

Example fix

// before (custom client)
async def create_stream(self, messages, **kwargs):
    async for delta in self._deltas(messages):
        yield delta  # never yields a final result

// after
async def create_stream(self, messages, **kwargs):
    text = ""
    async for delta in self._deltas(messages):
        text += delta
        yield delta
    yield CreateResult(finish_reason="stop", content=text, usage=..., cached=False)
Defensive patterns

Strategy: validation

Validate before calling

# Smoke-test the client's streaming contract before wiring it in
async def streams_final_result(client) -> bool:
    chunks = [c async for c in client.create_stream([SystemMessage(content="ping")])]
    return any(isinstance(c, CreateResult) for c in chunks)

assert await streams_final_result(model_client), "create_stream must end with a CreateResult"

Try / catch

try:
    async for msg in assistant.run_stream(task=task):
        ...
except RuntimeError as e:
    if "No final model result" in str(e):
        # fall back to non-streaming run
        result = await assistant.run(task=task)
    else:
        raise

Prevention

When it happens

Trigger: Running an AssistantAgent with model_client_stream=True where the model client's create_stream() implementation yields only str chunks and returns (typical of hand-rolled or mock clients), or where an internal client error aborts the stream before the final CreateResult.

Common situations: Custom ChatCompletionClient implementations (test doubles, replay/proxy clients, thin wrappers) that forget the final CreateResult; buggy or version-mismatched autogen-ext client packages; clients that swallow exceptions and end the generator early.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/59bceed098de982e. Report an issue: GitHub.