This is a lengthy post. If you are not interested in the function calling section of the API ( Chamadas de funções | Gemini API | Google for Developers), you can safely skip to the end. If, on the other hand, you intend to use the function calling part of the API in applications, this post should be of interest.
The main point of the post is: the API developers have not properly considered the tradeoff when they decided to ban periods (the character ‘.’) from name
in FunctionDeclaration
( https://ai.google.dev/api/rest/v1beta/Tool#FunctionDeclaration). The purpose of a beta test is to uncover possible flaws in the API design, and I intend to show that this is a serious enough flaw that it warrants reconsideration, and ultimately lifting the ban on the period in name
.
The way I am structuring the argument in favor of periods is
1. Run-time loading of plugin modules is an established and useful pattern in application architecture
2. There are applications where it makes sense to have tools developed in plugin modules
3. Deviating from the OpenAPI 3.03 specification with respect to the allowed characters in names by removing the period from the set of allowed characters is unduly complicating the design of applications that try to use plugins.
To illustrate the points 1 and 2, let’s consider a real-world extension of the MovieFinder application that the Google documentation and tutorials use. It’s well explained in the documentation and I don’t have to start over with a business case. The MovieFinder startup has had great success with their product in the US and now want to go global.
A reasonable application design is to then package the workhorse functions like find_theaters
, find_movies
in a Python module, decide on a common interface, and clone that module as many times as countries for which support is expected. The real-world advantage in this application architecture is, there is no common source file that teams from diverse time zones all need to branch and merge, and the localization teams don’t even need to install or learn the GenerativeAI code, there is no dependency to it anywhere in the module. The guys working on the MovieFinder_UK.py module would change tool documentation to not refer to states and zip codes like “95616” but use postcodes and “W5 5RA” instead, and would adjust the internals of the workhorse functions for their locale.
To use the localized modules, the main application then only needs code like this:
#### Testing plugins
from FunctionDecl import func_register, func_decl_list_UI
import importlib
PLUGIN_NAME = "ToolModule" + country_code
plugin_module = importlib.import_module(PLUGIN_NAME, ".")
plugin = plugin_module.Plugin("config")
available = plugin.list_tool_names()
print(available)
for func_identifier in available:
func_register(plugin.make_name(PLUGIN_NAME, func_identifier),
plugin.get_doc(func_identifier),
plugin.get_func(func_identifier),
plugin.get_func_parameters(func_identifier),
plugin.get_func_required_parameters(func_identifier),
me
)
Which brings us to the third point of my argument. Although it is feasible to implement a plugin containing tool functions intended to be used in an application using the Google API, the solution requires a customized name-mangler that consolidates the module name with the function identifier without using periods, just to circumvent the no-periods-allowed restriction on the name
field of FunctionDeclaration
. That’s what make_name(PLUGIN_NAME, func_identifier)
does, and one needs a reverse name-mangler when trying to show names to a human.
While the prototype code above is working (I have ‘find_theaters’, ‘find_movies’ etc. in a plugin module), the solution is a workaround I would rather avoid. Names that appear in client-side logs of messages sent by the Google backend have the customized name-mangling instead of the natural Modulename.function syntax, which isn’t conducive to troubleshooting and handing over to long-term maintenance. Tooling like splunk that help with making sense of logs will have gaps if a name that means one thing sometimes shows up mangled and sometimes doesn’t.
To summarize: I have tried to understand what motivated the Google API design team to drop the period from identifiers, basically flattening the available namespace to global (non-namespaced) names only. I didn’t manage to come up with a good reason why they would do that. I might of course be overlooking something and if anyone has a good explanation why periods shouldn’t be used when naming tools, I am eager to hear it.
If in fact there is no good reason to eliminate periods from name
, I encourage fellow developers to lobby for reinstating the period as eligible to be used in names, which would then make the Google API design better conforming to the OpenAPI 3.03 specification.
Thank you for your patience in reading all of this.