Can configTool be defined in a subsequent API call, not to override the configTool defined in cached content?
I am going to use a list of functions, and I need the model to be limited to only a subset of functions. I also want to use cachedContent and include the function schema on cached content. But every request is going to have totally different `allowedFunctionNames`, which is a property in `configTool`.
From my experience, it seems like when I define toolConfig to make a request by `sendMessageStream`, it overrides the default config defined altogether and loses access to function calls.
Maybe I made the question too complicated earlier.
Here’s the short version:
Is allowedFunctionNames in configTool considered part of the prompt that’s applied earlier or later in the prompt sequence?
This matters because if allowedFunctionNames is appended after the cached content, then we can efficiently use cached content for the full tool schema and dynamically restrict function access per request.
Hello,
Currently, CachedContent cannot be used with a GenerateContent request that also sets system_instruction, tools, or tool_config. These parameters must be provided within the CachedContent object itself.
As a potential workaround, you could create a function that generates a new cache based on the allowed functions required for a subsequent API call.
def create_cache(allowed_function_names: list):
cache = client.caches.create(
model=model_version,
config=types.CreateCachedContentConfig(
display_name=display_name,
contents=cached_contents,
tools=[{"function_declarations": tool_declarations}],
tool_config=types.FunctionCallingConfig(allowedFunctionNames=allowed_function_names),
)
)
return cache
cache = create_cache(allowed_function_names=["func1","func2"])
Please note that the provided code snippet is an example; you will need to update certain parameters as needed before using it in your application.