fix(tool): don't truncate auto tool name at hyphens in the module path#205
Open
Ricardo-M-L wants to merge 1 commit into
Open
fix(tool): don't truncate auto tool name at hyphens in the module path#205Ricardo-M-L wants to merge 1 commit into
Ricardo-M-L wants to merge 1 commit into
Conversation
getFunctionName stripped the runtime's -fm method-value suffix with strings.Index(fullName, "-"), which cuts at the *first* hyphen. Go's runtime function names include the full module path, and module paths routinely contain hyphens — including this SDK's own github.com/MoonshotAI/kimi-agent-sdk/go. So a tool created without WithName() got its name truncated at the first path hyphen: a function "...kimi-agent-sdk/go.Search" became "github_com/MoonshotAI/kimi", dropping the function name entirely. Strip only the exact "-fm" suffix with strings.TrimSuffix. For names without path hyphens this is identical to the old behavior; it just stops mangling names whose import path contains a hyphen. Adds tests: the auto-derived name now ends with the real function name, and method values still have -fm stripped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
getFunctionNamederives a tool's name from the Go function whenWithName()isn't provided. To drop the-fmsuffix that the runtime appends to method values, it does:strings.Indexfinds the first hyphen. Butruntime.FuncForPC(...).Name()returns the full module path, and module paths routinely contain hyphens — including this SDK's own module,github.com/MoonshotAI/kimi-agent-sdk/go. So the name is truncated at the first path hyphen and the function name is lost entirely.Reproduced on
main(functionSearchdefined inpackage kimi):The
Searchpart is gone — any user whose module path contains a hyphen and who relies on auto-naming gets a wrong, collision-prone tool name.Fix
Strip only the exact
-fmsuffix:For names without a path hyphen this is identical to the previous behavior (the
-fmmethod-value suffix is the only-in such names). It just stops mangling names whose import path contains a hyphen.Tests
TestCreateTool_AutoNamePreservesFunctionName— the auto-derived name now ends with_Searchinstead of being truncated.TestGetFunctionName_StripsMethodValueSuffix— method values still have-fmstripped, with the path/name preserved.Verification