diff --git a/llama-index-core/llama_index/core/agent/react/step.py b/llama-index-core/llama_index/core/agent/react/step.py index 69df6ed4dca3d..beee2fdc55e1c 100644 --- a/llama-index-core/llama_index/core/agent/react/step.py +++ b/llama-index-core/llama_index/core/agent/react/step.py @@ -341,13 +341,13 @@ def _infer_stream_chunk_is_final(self, chunk: ChatResponse) -> bool: """ latest_content = chunk.message.content if latest_content: - if not latest_content.startswith( + # doesn't follow thought-action format + if len(latest_content) > len("Thought") and not latest_content.startswith( "Thought" - ): # doesn't follow thought-action format + ): + return True + elif "Answer: " in latest_content: return True - else: - if "Answer: " in latest_content: - return True return False def _add_back_chunk_to_stream(