run-llama/llama_index · error · ValueError

Got empty streaming response

Error message

Got empty streaming response

What it means

In AgentWorkflow's streaming path (_call_llm with streaming), the loop over chat deltas is expected to produce at least one ChatResponse chunk. If the loop finishes with last_response still None — zero chunks yielded — the workflow raises ValueError('Got empty streaming response') rather than proceeding with nothing.

Source

Thrown at llama-index-core/llama_index/core/agent/workflow/multi_agent_workflow.py:343

                raw = (
                    last_response.raw.model_dump()
                    if isinstance(last_response.raw, BaseModel)
                    else last_response.raw
                )
                if ctx.is_running:
                    ctx.write_event_to_stream(
                        AgentStream(
                            delta=last_response.delta or "",
                            response=last_response.message.content or "",
                            raw=raw,
                            current_agent_name=agent.name,
                            thinking_delta=last_response.additional_kwargs.get(
                                "thinking_delta", None
                            ),
                        )
                    )
            if last_response is None:
                raise ValueError("Got empty streaming response")
            return last_response
        else:
            return await agent.llm.achat(llm_input)

    async def _call_tool(
        self,
        ctx: Context,
        tool: AsyncBaseTool,
        tool_input: dict,
    ) -> ToolOutput:
        """Call the given tool with the given input."""
        try:
            if (
                isinstance(tool, FunctionTool)
                and tool.requires_context
                and tool.ctx_param_name is not None
            ):
                new_tool_input = {**tool_input}

View on GitHub (pinned to afd0fef371)

Solutions

  1. Retry the run — empty streams from hosted LLMs are frequently transient.
  2. Verify streaming works outside AgentWorkflow: `async for c in llm.astream_chat(...)` should yield at least one chunk.
  3. If the endpoint/proxy doesn't support streaming, run without streaming or use a non-streaming-compatible integration.
  4. For test doubles, make the mock astream_chat yield at least one ChatResponse with delta content.

Example fix

# before (mock yields nothing -> ValueError)
async def astream_chat(self, messages, **kwargs):
    return
    yield

# after
async def astream_chat(self, messages, **kwargs):
    yield ChatResponse(message=ChatMessage(role="assistant", content="ok"), delta="ok")
Defensive patterns

Strategy: retry

Validate before calling

async def probe_stream(llm, prompt="ping"):
    n = 0
    async for _ in llm.astream_chat([ChatMessage(role="user", content=prompt)]):
        n += 1
    return n > 0  # false -> streaming will raise 'Got empty streaming response'

Try / catch

from llama_index.core.workflow.errors import WorkflowRuntimeError

for attempt in range(3):
    try:
        handler = wf.run(user_msg=q, stream=True)
        async for ev in handler.stream_events():
            ...
        result = await handler
        break
    except ValueError as e:
        if "empty streaming response" not in str(e) or attempt == 2:
            raise
        continue

Prevention

When it happens

Trigger: Running the agent with stream=True against an LLM that returns an empty SSE stream, closes the connection before the first chunk, or whose streaming mode is misconfigured (e.g. stream mode not actually enabled server-side). Also seen with mock/fake LLMs that yield no chunks.

Common situations: Switching a provider integration to streaming when the endpoint doesn't support it; a transient network drop right after headers; OpenAI-compatible proxies that return 200 but an empty body; unit tests with stub LLMs that forget to emit deltas.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/1b521f3aedf31c65. Report an issue: GitHub.