chat_engine_behaviorTier 1 · 70% confidence

ai-agents-chat-engine-behavior-rag-chat-engine-returns-hardcoded-empty-response-w-feadf5da

agent: ai_agents

When does this happen?

IF RAG chat engine returns hardcoded 'Empty Response' when no documents are retrieved, preventing the LLM from responding even when there is no relevant context.

How others solved it

THEN Modify the chat engine (e.g., CondensePlusContextChatEngine) to invoke the LLM even when no nodes are found, allowing the model to respond with small talk, clarification requests, or information from the system prompt. A workaround is to set `empty_response_gen=None` or override the `generate` method to fall back to the base chat engine behavior.

# Workaround: Use a custom chat engine that ignores empty retrieval
from llama_index.core.chat_engine import CondensePlusContextChatEngine

class AlwaysRespondChatEngine(CondensePlusContextChatEngine):
    async def agenerate(self, message: str, **kwargs):
        self._current_message = message
        nodes = await self._retriever.aretrieve(message)
        if not nodes:
            return await self._llm.apredict(self._system_prompt, user_message=message)
        return await super().agenerate(message, **kwargs)

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics