Skip to content

Conversation

@Githubguy132010
Copy link
Contributor

@Githubguy132010 Githubguy132010 commented Jan 3, 2026

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:

  • 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

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

…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.
@DenizOkcu
Copy link
Collaborator

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:

import {
	generateText,
	InvalidToolInputError,
	NoSuchToolError,
	stepCountIs,
	ToolCallRepairError,
} from 'ai';

@Githubguy132010
Copy link
Contributor Author

Githubguy132010 commented Jan 3, 2026

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:

import {
	generateText,
	InvalidToolInputError,
	NoSuchToolError,
	stepCountIs,
	ToolCallRepairError,
} from 'ai';

Thanks for the suggestion! I looked into the native AI SDK error types, but they serve a different purpose:

  • NoSuchToolError/InvalidToolInputError: Thrown when the AI SDK validates tool schemas (e.g., model tries to call a tool not in your tools object)

  • My isToolSupportError: Detects when the provider/model doesn't support tools at all (e.g., Ollama models rejecting tool definitions with "400 Bad Request")

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.

@DenizOkcu
Copy link
Collaborator

DenizOkcu commented Jan 3, 2026

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 😄

@will-lamerton
Copy link
Member

Hey @Githubguy132010 - this looks good! Is there any more work to make this a complete PR? :)

@Githubguy132010 Githubguy132010 marked this pull request as ready for review January 8, 2026 13:16
@Githubguy132010
Copy link
Contributor Author

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.

@DenizOkcu
Copy link
Collaborator

Let me know if there are questions regarding merge conflicts, i guess its my stuff :-) Would be happy to help

@Githubguy132010
Copy link
Contributor Author

I just clicked on keep current changes on both files and I am hoping for the best

@Githubguy132010 Githubguy132010 force-pushed the Fix-issue-#252 branch 2 times, most recently from 5699b46 to 3d26501 Compare January 8, 2026 16:25
@Githubguy132010
Copy link
Contributor Author

@DenizOkcu Could you help me resolve the conflicts?

@will-lamerton
Copy link
Member

@DenizOkcu Could you help me resolve the conflicts?

I can jump in and help. I'll review later :)

Copy link

@jason1015-coder jason1015-coder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that looks great

@will-lamerton
Copy link
Member

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 :)

@Githubguy132010
Copy link
Contributor Author

@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
@will-lamerton will-lamerton merged commit bd6866a into Nano-Collective:main Jan 15, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants