While working on a React agent, I came to notice that if a question is asked and a resource error occurs, the agent stops due to that error. Then, when I ask the next question, the previous answer gets displayed again instead of a fresh response. How can I solve this? I’m thinking of deleting the last message from the state history after such an error. Is that a good approach? If so, how can I effectively delete it? Or is there a better solution?
Hi there!
For errors, if you want more intelligent handling you can use try / catch in the node or tool itself. This will stop the agent from completely stopping execution based on what you decide to raise to it. I think that approach would be simpler than deleting messages.
However, we do have a construct in LangGraph to delete messages (RemoveMessage). Here’s some docs describing how to use it: How to delete messages