Skip to content

fix: enforce tool name uniqueness - #592

Merged
johanandren merged 7 commits into
agent-devfrom
octonato/unique-function-tool-names
Jun 18, 2025
Merged

johanandren merged 7 commits into
agent-devfrom
octonato/unique-function-tool-names

Conversation

@octonato

Copy link
Copy Markdown
Contributor

No description provided.

if (toolAnno.name() == null || toolAnno.name().isBlank) {
// if the annotation does not specify a name,
// we use the name passed to this method plus the sanitized class name
method.getDeclaringClass.getSimpleName + "_" + resolvedName

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For now, adding only the simple name + resolved name.

I tried to use the full qualified class name, but LC4J is quite restricted.
First it only allows alphanumeric, dashes and underscores. This is easy to solve.

But it also limits the name to 64 chars and this will require us to start to trim the name.

Using simpleName + resolvedName must cover most cases, but if user has to class with same name in different packages and having same method names, they will clash.

I need to add a check for that. If we don't, the last added method will shadow the first because we are using a Map(methodName -> Method).

Maybe it's a far fetch case, but better to simply make it fail.

.filter(m => m.hasAnnotation[FunctionTool])
.filter(m => m.isPublic || allowNonPublic)
// tool methods in agent don't need to be public
.filter(m => m.isPublic || isAgent(cls))

@octonato octonato Jun 18, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wonder if it isn't better so simply allow private methods for all kinds of classes.

I was checking LC4J and they accept private methods in tools.
The fact that we allow for Agents, but not for other classes might create confusion.

Our rational makes sense, IMO. The agent has 'access' to its private methods. On the other hand, the difference in behavior might be confusing.

@johanandren johanandren Jun 18, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that agent being able to use its own private methods but not private methods of other classes (external tools) is what is most reasonable ("the path of least astonishment")

@johanandren
johanandren merged commit cb5a21f into agent-dev Jun 18, 2025
@johanandren
johanandren deleted the octonato/unique-function-tool-names branch June 18, 2025 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants