Agent always changes behavior / forgets context in the middle

This issue has been bothering me in a very painful way recently. With the Sonnet 3.7 model, it ofen changes topic suddenly in the middle of resolving some issue or generating codes - it looks like the agent suddenly changed to another different one, and starts to read document, analyze codes from beginning and eventually gives a whole bunch of summary of the project - totally forgot its original task and target. Someone from the cusor team could explain why, and when this issue could be fixed?

This issue is mostly caused by LLMs losing focus due to long or complex context. You can check out this project: mcp-shrimp-task-manager
It breaks down complex tasks into smaller steps and keeps guiding the LLM to stay on track. Even if the context gets too long and the model starts to drift, you can start a new conversation and ask it to continue. Shrimp will help the LLM pick up where it left off.