|
39 | 39 |
|
40 | 40 |
|
41 | 41 | class GemmaFunctionCallingMixin: |
42 | | - """Mixin providing function calling support for Gemma models. |
| 42 | + """Mixin providing function calling support for Gemma 3 models. |
43 | 43 |
|
44 | | - Gemma models don't have native function calling support, so this mixin |
| 44 | + Gemma 3 models don't have native function calling support, so this mixin |
45 | 45 | provides the logic to: |
46 | 46 | 1. Convert function declarations to system instruction prompts |
47 | 47 | 2. Convert function call/response parts to text in the conversation |
48 | 48 | 3. Extract function calls from model text responses |
| 49 | +
|
| 50 | + This mixin is NOT needed for Gemma 4+, which supports function calling |
| 51 | + natively through the standard Gemini/LiteLLM integrations. |
49 | 52 | """ |
50 | 53 |
|
51 | 54 | def _move_function_calls_into_system_instruction( |
@@ -161,31 +164,29 @@ class GemmaFunctionCallModel(BaseModel): |
161 | 164 |
|
162 | 165 |
|
163 | 166 | class Gemma(GemmaFunctionCallingMixin, Gemini): |
164 | | - """Integration for Gemma models exposed via the Gemini API. |
| 167 | + """Integration for Gemma 3 models exposed via the Gemini API. |
| 168 | +
|
| 169 | + This class is for **Gemma 3 only**. It provides workarounds for Gemma 3's |
| 170 | + lack of native function calling and system instruction support: |
| 171 | + - Tools are injected into text prompts (not passed via the API) |
| 172 | + - Function calls are parsed from model text responses |
| 173 | + - System instructions are converted to user-role messages |
| 174 | +
|
| 175 | + For Gemma 4 and later, use the standard ``Gemini`` class directly:: |
| 176 | +
|
| 177 | + # Gemma 4 — use Gemini (native function calling & system instructions) |
| 178 | + agent = Agent(model=Gemini(model="gemma-4-<size>"), ...) |
| 179 | +
|
| 180 | + # Gemma 3 — use this class (workarounds applied automatically) |
| 181 | + agent = Agent(model=Gemma(model="gemma-3-27b-it"), ...) |
165 | 182 |
|
166 | | - Only Gemma 3 models are supported at this time. For agentic use cases, |
167 | | - use of gemma-3-27b-it and gemma-3-12b-it are strongly recommended. |
| 183 | + For agentic use cases with Gemma 3, ``gemma-3-27b-it`` and ``gemma-3-12b-it`` |
| 184 | + are strongly recommended. |
168 | 185 |
|
169 | 186 | For full documentation, see: https://ai.google.dev/gemma/docs/core/ |
170 | 187 |
|
171 | | - NOTE: Gemma does **NOT** support system instructions. Any system instructions |
172 | | - will be replaced with an initial *user* prompt in the LLM request. If system |
173 | | - instructions change over the course of agent execution, the initial content |
174 | | - **SHOULD** be replaced. Special care is warranted here. |
175 | | - See: |
176 | | - https://ai.google.dev/gemma/docs/core/prompt-structure#system-instructions |
177 | | -
|
178 | | - NOTE: Gemma's function calling support is limited. It does not have full |
179 | | - access to the |
180 | | - same built-in tools as Gemini. It also does not have special API support for |
181 | | - tools and |
182 | | - functions. Rather, tools must be passed in via a `user` prompt, and extracted |
183 | | - from model |
184 | | - responses based on approximate shape. |
185 | | -
|
186 | | - NOTE: Vertex AI API support for Gemma is not currently included. This **ONLY** |
187 | | - supports |
188 | | - usage via the Gemini API. |
| 188 | + NOTE: This class only supports the Gemini API (Google AI Studio). |
| 189 | + Vertex AI API support is not included. |
189 | 190 | """ |
190 | 191 |
|
191 | 192 | model: str = ( |
@@ -365,12 +366,20 @@ def _get_last_valid_json_substring(text: str) -> tuple[bool, str | None]: |
365 | 366 | class Gemma3Ollama(GemmaFunctionCallingMixin, LiteLlm): |
366 | 367 | """Integration for Gemma 3 models running locally via Ollama. |
367 | 368 |
|
368 | | - This enables fully local agent workflows using Gemma 3 models. |
369 | | - Requires Ollama to be running with a Gemma 3 model pulled. |
| 369 | + This class is for **Gemma 3 only**. It provides the same function calling |
| 370 | + workarounds as the ``Gemma`` class, but routes through Ollama via LiteLLM. |
| 371 | +
|
| 372 | + For Gemma 4 and later on Ollama, use the standard ``LiteLlm`` class:: |
| 373 | +
|
| 374 | + # Gemma 4 on Ollama — use LiteLlm directly |
| 375 | + agent = Agent(model=LiteLlm(model="ollama_chat/gemma4:<size>"), ...) |
| 376 | +
|
| 377 | + # Gemma 3 on Ollama — use this class |
| 378 | + agent = Agent(model=Gemma3Ollama(), ...) |
| 379 | +
|
| 380 | + Requires Ollama to be running with a Gemma 3 model pulled:: |
370 | 381 |
|
371 | | - Example: |
372 | | - ollama pull gemma3:12b |
373 | | - model = Gemma3Ollama(model="ollama/gemma3:12b") |
| 382 | + ollama pull gemma3:12b |
374 | 383 | """ |
375 | 384 |
|
376 | 385 | def __init__(self, model: str = 'ollama/gemma3:12b', **kwargs): |
|
0 commit comments