run-llama/llama_index · error · ValueError
Streaming is not enabled. Please use achat() instead.
Error message
Streaming is not enabled. Please use achat() instead.
What it means
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.
Source
Thrown at llama-index-core/llama_index/core/chat_engine/condense_question.py:374
)
# Record response
if isinstance(query_response, AsyncStreamingResponse):
# override the generator to include writing to chat history
# TODO: query engine does not support async generator yet
await self._memory.aput(ChatMessage(role=MessageRole.USER, content=message))
response = StreamingAgentChatResponse(
achat_stream=aresponse_gen_from_query_engine(
query_response.async_response_gen()
),
sources=[tool_output],
)
response.awrite_response_to_history_task = asyncio.create_task(
response.awrite_response_to_history(self._memory)
)
else:
raise ValueError("Streaming is not enabled. Please use achat() instead.")
return response
def reset(self) -> None:
# Clear chat history
self._memory.reset()
@property
def chat_history(self) -> List[ChatMessage]:
"""Get chat history."""
return self._memory.get_all()
View on GitHub (pinned to afd0fef371)
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)
Example fix
# before
qe = index.as_query_engine()
chat = CondenseQuestionChatEngine.from_defaults(query_engine=qe)
resp = await chat.astream_chat('hello') # ValueError
# after
qe = index.as_query_engine(streaming=True)
chat = CondenseQuestionChatEngine.from_defaults(query_engine=qe)
resp = await chat.astream_chat('hello')
async for token in resp.async_response_gen():
print(token, end='') Defensive patterns
Strategy: validation
Validate before calling
qe = index.as_query_engine(streaming=True) # ensure the LLM supports async streaming before astream_chat assert hasattr(Settings.llm, 'astream_complete'), 'LLM must support astream_complete'
Try / catch
try:
resp = await engine.astream_chat(msg)
except ValueError as e:
if 'Streaming is not enabled' in str(e):
resp = await engine.achat(msg)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Streaming is not enabled. Please use chat() instead.
- response_gen is only available for streaming responses. Set
- achat_stream is None. Cannot asynchronously write to history
- achat_stream is None!
- astream_complete is not supported by default.
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/33c2d62d06fea355.
Report an issue: GitHub.