feat: enforce maximum length for tool names in MCPTool

- Introduced a constant `maxFunctionNameLength` set to 64 characters to comply with OpenAI API constraints on tool names.
- Updated the `Name` method in `MCPTool` to truncate tool names exceeding the maximum length, ensuring unique identification while preventing potential collisions.
- Enhanced the logic to handle long service IDs by using only the first 8 characters when necessary, maintaining the integrity of tool naming conventions.

These changes improve compliance with API requirements and enhance the robustness of tool name generation.
This commit is contained in:
wizardchen
2026-03-05 12:01:32 +08:00
committed by lyingbug
parent 90c32b5926
commit a1c0682aa3
2 changed files with 22 additions and 2 deletions
+4
View File
@@ -1,5 +1,9 @@
package tools
// maxFunctionNameLength is the maximum length for a tool/function name
// imposed by the OpenAI API.
const maxFunctionNameLength = 64
// Tool names constants
const (
ToolThinking = "thinking"