|
| 1 | +# Google Gemini Server Tools |
| 2 | + |
| 3 | +Server tools are built-in capabilities provided by Google Gemini that allow the model to perform specific actions without requiring custom tool implementations. These tools run on Google's servers and provide access to external data and execution environments. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Google Gemini provides several server-side tools that can be enabled when calling the model: |
| 8 | + |
| 9 | +- **URL Context** - Fetches and analyzes content from URLs |
| 10 | +- **Google Search** - Performs web searches using Google |
| 11 | +- **Code Execution** - Executes code in a sandboxed environment |
| 12 | + |
| 13 | +## Available Server Tools |
| 14 | + |
| 15 | +### URL Context |
| 16 | + |
| 17 | +The URL Context tool allows Gemini to fetch and analyze content from web pages. This is useful for: |
| 18 | + |
| 19 | +- Analyzing current web content |
| 20 | +- Extracting information from specific pages |
| 21 | +- Understanding context from external sources |
| 22 | + |
| 23 | +```php |
| 24 | +$llm = new Gemini('gemini-2.5-pro-preview-03-25', [ |
| 25 | + 'server_tools' => [ |
| 26 | + 'url_context' => true |
| 27 | + ] |
| 28 | +]); |
| 29 | + |
| 30 | +$messages = new MessageBag( |
| 31 | + Message::ofUser('What was the 12 month Euribor rate a week ago based on https://www.euribor-rates.eu/en/current-euribor-rates/4/euribor-rate-12-months/') |
| 32 | +); |
| 33 | + |
| 34 | +$response = $chain->call($messages); |
| 35 | +``` |
| 36 | + |
| 37 | +### Google Search |
| 38 | + |
| 39 | +The Google Search tool enables the model to search the web and incorporate search results into its responses: |
| 40 | + |
| 41 | +```php |
| 42 | +$llm = new Gemini('gemini-2.5-pro-preview-03-25', [ |
| 43 | + 'server_tools' => [ |
| 44 | + 'google_search' => true |
| 45 | + ] |
| 46 | +]); |
| 47 | + |
| 48 | +$messages = new MessageBag( |
| 49 | + Message::ofUser('What are the latest developments in quantum computing?') |
| 50 | +); |
| 51 | + |
| 52 | +$response = $chain->call($messages); |
| 53 | +``` |
| 54 | + |
| 55 | +### Code Execution |
| 56 | + |
| 57 | +The Code Execution tool provides a sandboxed environment for running code: |
| 58 | + |
| 59 | +```php |
| 60 | +$llm = new Gemini('gemini-2.5-pro-preview-03-25', [ |
| 61 | + 'server_tools' => [ |
| 62 | + 'code_execution' => true |
| 63 | + ] |
| 64 | +]); |
| 65 | + |
| 66 | +$messages = new MessageBag( |
| 67 | + Message::ofUser('Calculate the factorial of 20 and show me the code') |
| 68 | +); |
| 69 | + |
| 70 | +$response = $chain->call($messages); |
| 71 | +``` |
| 72 | + |
| 73 | +## Using Multiple Server Tools |
| 74 | + |
| 75 | +You can enable multiple server tools simultaneously: |
| 76 | + |
| 77 | +```php |
| 78 | +$llm = new Gemini('gemini-2.5-pro-preview-03-25', [ |
| 79 | + 'server_tools' => [ |
| 80 | + 'url_context' => true, |
| 81 | + 'google_search' => true, |
| 82 | + 'code_execution' => true |
| 83 | + ] |
| 84 | +]); |
| 85 | +``` |
| 86 | + |
| 87 | +## Example |
| 88 | + |
| 89 | +See [examples/google/server-tools.php](../examples/google/server-tools.php) for a complete working example. |
| 90 | + |
| 91 | +## Limitations |
| 92 | + |
| 93 | +- API key must have appropriate permissions |
| 94 | +- Server tools may have usage quotas |
| 95 | +- Response times may vary based on the complexity of server tool operations |
| 96 | +- Not all Gemini model versions support all server tools |
0 commit comments