Principle:Googleapis Python genai Tool Definition
| Knowledge Sources | |
|---|---|
| Domains | Function_Calling, Tool_Use |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
A mechanism for declaring external functions and tools that a language model can invoke during generation to access real-world data or perform actions.
Description
Tool Definition enables language models to interact with external systems by declaring available functions with their names, descriptions, and parameter schemas. The model uses these declarations to decide when and how to call functions during generation. Tools can be defined manually (specifying JSON Schema parameters), automatically (by inspecting Python function signatures), or via the Model Context Protocol (MCP) for external tool servers. This principle bridges the gap between the model's language understanding and real-world capabilities like database queries, API calls, or calculations.
Usage
Use tool definition when the model needs access to real-time data (weather, stock prices), external systems (databases, APIs), or computational functions (calculators, code execution). Define tools with clear descriptions so the model can determine when to call them. For Python functions, the SDK can auto-generate declarations from type annotations and docstrings.
Theoretical Basis
Tool use in language models follows a Plan-Execute-Observe loop:
- Plan: The model analyzes the user's request and selects an appropriate tool
- Execute: The selected function is called with model-generated arguments
- Observe: The function result is fed back to the model as context
Tools are declared using JSON Schema (OpenAPI 3.0 format):
# Abstract tool declaration
tool = {
"name": "get_weather",
"description": "Get current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"}
},
"required": ["location"]
}
}