async def afinalize_task(self, task: Task, **kwargs: Any) -> None:
        """Finalize task, after all the steps are completed."""
        messages = task.extra_state["new_memory"].get_all()
        # reset new memory before aputting messages for async race conditions
        task.extra_state["new_memory"].reset()
        # add new messages to memory
        await task.memory.aput_messages(messages)
Finalize task, after all the steps are completed.
llama-index-integrations/agent/llama-index-agent-openai/llama_index/agent/openai/step.py