{"record":{"id":"33c2d62d06fea355","repo":"run-llama/llama_index","slug":"streaming-is-not-enabled-please-use-achat-inste","errorCode":null,"errorMessage":"Streaming is not enabled. Please use achat() instead.","messagePattern":"Streaming is not enabled\\. Please use achat\\(\\) instead\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/chat_engine/condense_question.py","lineNumber":374,"sourceCode":"        )\n\n        # Record response\n        if isinstance(query_response, AsyncStreamingResponse):\n            # override the generator to include writing to chat history\n            # TODO: query engine does not support async generator yet\n            await self._memory.aput(ChatMessage(role=MessageRole.USER, content=message))\n            response = StreamingAgentChatResponse(\n                achat_stream=aresponse_gen_from_query_engine(\n                    query_response.async_response_gen()\n                ),\n                sources=[tool_output],\n            )\n            response.awrite_response_to_history_task = asyncio.create_task(\n                response.awrite_response_to_history(self._memory)\n            )\n\n        else:\n            raise ValueError(\"Streaming is not enabled. Please use achat() instead.\")\n        return response\n\n    def reset(self) -> None:\n        # Clear chat history\n        self._memory.reset()\n\n    @property\n    def chat_history(self) -> List[ChatMessage]:\n        \"\"\"Get chat history.\"\"\"\n        return self._memory.get_all()\n","sourceCodeStart":356,"sourceCodeEnd":385,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/chat_engine/condense_question.py#L356-L385","documentation":"Async counterpart of the sync error: CondenseQuestionChatEngine.astream_chat() raises ValueError when the underlying query engine produced a non-streaming response, i.e. it has no async_response_gen. The engine needs an async token generator to return a StreamingAgentChatResponse; without streaming enabled at query-engine construction there is nothing to iterate.","triggerScenarios":"await engine.astream_chat('hi') where the engine was built from index.as_query_engine() (default streaming=False) or any query engine that returns a plain CompletionResponse. The else-branch after the streaming check raises.","commonSituations":"Async web servers (FastAPI) calling astream_chat for token streaming while the query engine was built synchronously by default; mixing chat()/stream_chat() code paths and assuming streaming is a property of the chat engine rather than the query engine.","solutions":["Create the query engine with streaming enabled: index.as_query_engine(streaming=True) before constructing the chat engine","Or use await engine.achat('hi') which returns a complete AgentChatResponse without streaming","Confirm the bound LLM supports async streaming (implements astream_complete)"],"exampleFix":"# before\nqe = index.as_query_engine()\nchat = CondenseQuestionChatEngine.from_defaults(query_engine=qe)\nresp = await chat.astream_chat('hello')  # ValueError\n\n# after\nqe = index.as_query_engine(streaming=True)\nchat = CondenseQuestionChatEngine.from_defaults(query_engine=qe)\nresp = await chat.astream_chat('hello')\nasync for token in resp.async_response_gen():\n    print(token, end='')","handlingStrategy":"validation","validationCode":"qe = index.as_query_engine(streaming=True)\n# ensure the LLM supports async streaming before astream_chat\nassert hasattr(Settings.llm, 'astream_complete'), 'LLM must support astream_complete'","typeGuard":null,"tryCatchPattern":"try:\n    resp = await engine.astream_chat(msg)\nexcept ValueError as e:\n    if 'Streaming is not enabled' in str(e):\n        resp = await engine.achat(msg)\n    else:\n        raise","preventionTips":["Build query engines with streaming=True in async servers that call astream_chat","Test the streaming path in CI, not only the non-streaming path"],"tags":["llama-index","chat-engine","streaming","async"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}