{"record":{"id":"771d318447c0eba4","repo":"run-llama/llama_index","slug":"response-gen-is-only-available-for-streaming-respo","errorCode":null,"errorMessage":"response_gen is only available for streaming responses. Set is_dummy_stream=True if you still want a generator.","messagePattern":"response_gen is only available for streaming responses\\. Set is_dummy_stream=True if you still want a generator\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/chat_engine/types.py","lineNumber":84,"sourceCode":"    metadata: Optional[Dict[str, Any]] = None\n\n    def set_source_nodes(self) -> None:\n        if self.sources and not self.source_nodes:\n            for tool_output in self.sources:\n                if isinstance(tool_output.raw_output, (Response, StreamingResponse)):\n                    self.source_nodes.extend(tool_output.raw_output.source_nodes)\n\n    def __post_init__(self) -> None:\n        self.set_source_nodes()\n\n    def __str__(self) -> str:\n        return self.response\n\n    @property\n    def response_gen(self) -> Generator[str, None, None]:\n        \"\"\"Used for fake streaming, i.e. with tool outputs.\"\"\"\n        if not self.is_dummy_stream:\n            raise ValueError(\n                \"response_gen is only available for streaming responses. \"\n                \"Set is_dummy_stream=True if you still want a generator.\"\n            )\n\n        for token in self.response.split(\" \"):\n            yield token + \" \"\n            time.sleep(0.1)\n\n    async def async_response_gen(self) -> AsyncGenerator[str, None]:\n        \"\"\"Used for fake streaming, i.e. with tool outputs.\"\"\"\n        if not self.is_dummy_stream:\n            raise ValueError(\n                \"response_gen is only available for streaming responses. \"\n                \"Set is_dummy_stream=True if you still want a generator.\"\n            )\n\n        for token in self.response.split(\" \"):\n            yield token + \" \"","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/chat_engine/types.py#L66-L102","documentation":"AgentChatResponse.response_gen is a fake-streaming property that yields whitespace-joined tokens of an already-complete response; it only exists so non-streaming responses (e.g. tool outputs) can mimic a token stream. Accessing it when is_dummy_stream is False raises ValueError, because a real streaming response carries its generator elsewhere (StreamingAgentChatResponse.response_gen) and this object has none.","triggerScenarios":"resp = engine.chat('hi') (returns AgentChatResponse with is_dummy_stream=False) followed by resp.response_gen — the property's guard raises. Also hit in UI code that calls list(response.response_gen) on every response regardless of engine method.","commonSituations":"Unified render loops that iterate response_gen for both chat() and stream_chat() results; switching an endpoint from streaming to non-streaming while keeping the generator consumption; tool-calling engines where the final response is an AgentChatResponse.","solutions":["Use stream_chat()/astream_chat() to get a StreamingAgentChatResponse whose response_gen is a true token generator","For non-streaming responses, print/consume resp.response directly (the full string)","If you deliberately want simulated token-by-token display of a finished response, construct AgentChatResponse(..., is_dummy_stream=True)"],"exampleFix":"# before\nresp = engine.chat('hello')\nfor token in resp.response_gen:  # ValueError\n    print(token, end='')\n\n# after\nresp = engine.stream_chat('hello')\nfor token in resp.response_gen:\n    print(token, end='')\n# or for non-streaming: print(resp.response)","handlingStrategy":"type-guard","validationCode":"from llama_index.core.chat_engine import StreamingAgentChatResponse\nif not isinstance(resp, StreamingAgentChatResponse):\n    print(resp.response)  # full text; no generator available","typeGuard":"from llama_index.core.chat_engine import StreamingAgentChatResponse, AgentChatResponse\n\ndef has_real_stream(resp) -> bool:\n    return isinstance(resp, StreamingAgentChatResponse)\n\n# or for AgentChatResponse specifically:\ndef can_fake_stream(resp: AgentChatResponse) -> bool:\n    return bool(resp.is_dummy_stream)","tryCatchPattern":"try:\n    for token in resp.response_gen:\n        print(token, end='')\nexcept ValueError as e:\n    if 'only available for streaming' in str(e):\n        print(resp.response)\n    else:\n        raise","preventionTips":["Branch on the response type: iterate response_gen only for StreamingAgentChatResponse","Standardize endpoints on either chat() or stream_chat() instead of mixing both behind one consumer","If you need token-like output from a finished AgentChatResponse, create it with is_dummy_stream=True"],"tags":["llama-index","chat-engine","streaming","response-type"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}