Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Creating a Generative Model with multiple tools with vertexai

Hi all, I am building a chat bot using vertex ai, with access to multiple tool (e.g., a tool to access RAG, a tool to run an experiment, etc.). However I have found that I am getting this error:

```<_InactiveRpcError of RPC that terminated with:
status = StatusCode.INVALID_ARGUMENT
details = "Request contains an invalid argument."
debug_error_string = "UNKNOWN:Error received from peer ipv4:142.250.68.42:443 {created_time:"2024-05-12T18:15:58.005737-07:00", grpc_status:3, grpc_message:"Request contains an invalid argument."}"
>```

The error happens when I add 2 tools to the tools list when defining a model. However, tested separately, and the model works fine with just 1 tool (for both tools). Has anyone faced a similar problem? Do you know how to address it?

For reference, here are the code snippets I use to communicate with the API:

```

import vertexai
from vertexai.generative_models import (
GenerativeModel,
ChatSession,
Part,
Tool,
FunctionDeclaration
)

###

tools = [get_extra_content_tool, run_db_experiment_dedicated_env_tool]
gemini_model = GenerativeModel(
env('GEMINI_MODEL'),
tools=tools,
system_instruction=[main_bot_prompt]
)

###

chat = gemini_model.start_chat(response_validation=False)

###

# the error is throwing here, but it's connected to tools

gemini_response = chat.send_message(
[question],
generation_config=get_generation_config()
)

```

4 3 5,459
3 REPLIES 3

Update: got a response from the support, and Gemini API currently supports only one tool. 

As far as I understood you can haven’t tool in the model.tools 

    GenerativeModel(
        env('GEMINI_MODEL'),
        tools=tools, # this is a list but only accepts one item for whatever reason 
        system_instruction=[main_bot_prompt]

    )

 

if you want multiple „tools“ it is only possible by entering several FunctionDeclarations for the one tool, like so:
    

model = GenerativeModel(

    …

    tools=[

        Tool(

            FuntionDeclaration1,

            FunctionDeclaration2,

            …

        )

    ]
)

 

I’m not saying this makes sense or aligns with the docs, but it’s what works and is also in the examples of the Gemini cookbook on github