Class Tool (1.121.0)

Tool(
 function_declarations: typing.List[
 vertexai.generative_models._generative_models.FunctionDeclaration
 ],
)

A collection of functions that the model may use to generate response.

Usage: Create tool from function declarations:

```
get_current_weather_func = generative_models.FunctionDeclaration(...)
weather_tool = generative_models.Tool(
 function_declarations=[get_current_weather_func],
)
```
Use tool in `GenerativeModel.generate_content`:
```
model = GenerativeModel("gemini-pro")
print(model.generate_content(
 "What is the weather like in Boston?",
 # You can specify tools when creating a model to avoid having to send them with every request.
 tools=[weather_tool],
))
```
Use tool in chat:
```
model = GenerativeModel(
 "gemini-pro",
 # You can specify tools when creating a model to avoid having to send them with every request.
 tools=[weather_tool],
)
chat = model.start_chat()
print(chat.send_message("What is the weather like in Boston?"))
print(chat.send_message(
 Part.from_function_response(
 name="get_current_weather",
 response={
 "content": {"weather_there": "super nice"},
 }
 ),
))
```

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月30日 UTC.