-
Notifications
You must be signed in to change notification settings - Fork 120
feat(ai-sdk-client): add tool support error detection and retry mechanism #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ai-sdk-client): add tool support error detection and retry mechanism #259
Conversation
…nism Added comprehensive tool support error detection and automatic retry functionality to handle models that don't support function calling. The system now: - Detects tool support errors from various providers (OpenAI, Anthropic, Ollama, etc.) - Automatically retries requests without tools when tool support errors are detected - Provides configuration options to disable tools globally or per model - Includes detailed logging for debugging tool-related issues Key changes: - Added tool-error-detector.ts with comprehensive error pattern matching - Enhanced chat-handler.ts with retry logic and tool configuration - Extended configuration types to support tool disabling per provider and model - Updated example configuration with disableToolModels example BREAKING CHANGE: Tool configuration now supports per-model disabling via disableToolModels array
…ction Adds unit tests for the ToolErrorDetector class to ensure proper error detection and retry logic functionality. Tests cover various error scenarios including tool call failures, invalid tool calls, and error categorization.
|
Error detection is great. I looked into it recently. Can you check if your use case can already be handled by just using the error types from AI SDK? I think this cvan be handled in a simpler way by using the native v6 error types: |
Thanks for the suggestion! I looked into the native AI SDK error types, but they serve a different purpose:
The native errors are thrown before sending to the provider, while my patterns detect provider rejection after the request is sent. This is specifically for local models (Ollama, llama.cpp) that don't support function calling. |
|
true, good point. I think in this case we have already an XML tool call fallback. But I am not remembering if we removed it or if it even handles this problem. @will-lamerton might know more 👓 BTW: this was not meant to sound discouraging. Just my two first thoughts from the top of my mind 😄 |
|
Hey @Githubguy132010 - this looks good! Is there any more work to make this a complete PR? :) |
Maybe resolving the merge conflicts. I will do that later. |
|
Let me know if there are questions regarding merge conflicts, i guess its my stuff :-) Would be happy to help |
|
I just clicked on keep current changes on both files and I am hoping for the best |
5699b46 to
3d26501
Compare
|
@DenizOkcu Could you help me resolve the conflicts? |
I can jump in and help. I'll review later :) |
jason1015-coder
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that looks great
|
Hey @Githubguy132010 - this looks really good! Could you quickly document the new agents.config.json key for skipping tools in the README. I'll then handle merge conflicts for you as a lot has changed upstream. Thanks :) |
|
@will-lamerton I documented the changes as requested. |
Resolves merge conflicts and adds tool prompt injection enhancement: - Merged tool support error detection with AI SDK error handling - Added tool definitions injection into system prompt when native tool calling is disabled, enabling XML-based tool usage for models that don't support function calling
Related to #252
Added comprehensive tool support error detection and automatic retry functionality to handle models that don't support function calling. The system now:
Key changes:
BREAKING CHANGE: Tool configuration now supports per-model disabling via disableToolModels array
Type of Change
Testing
Automated Tests
.spec.ts/tsxfilespnpm test:allcompletes successfully)Manual Testing
Checklist