ai
ai copied to clipboard
Support continue generation when tool calling fails
Description
Currently, when errors happen in tool execution, an exception is thrown and the generation stops. However, error is actually a valid result for function calling in OpenAI/Anthropic. So it would be great if the user can decide if they want to use the error as tool result.
Right now, I've got a hacky way to do it: I catch the error in the tool's execute function and return it instead of throwing it. Then, when streaming, I check if the tool result is an instance of an error. While this works, I'm hoping for a more standard way to achieve this.