# override the generator to include writing to chat history self._memory.put(ChatMessage(role=MessageRole.USER, content=message)) response = StreamingAgentChatResponse( chat_stream=response_gen_from_query_engine(query_response.response_gen), sources=[tool_output], ) thread = Thread( target=response.write_response_to_history, args=(self._memory, True) ) thread.start()