|
| 1 | +Vertex AI Server Tools |
| 2 | +====================== |
| 3 | + |
| 4 | +Server tools in Vertex AI are built-in capabilities provided by Google's Gemini models that allow the model to perform |
| 5 | +specific actions without requiring custom tool implementations. |
| 6 | +These tools run on Google's infrastructure and provide access to external data sources and execution environments. |
| 7 | + |
| 8 | +Overview |
| 9 | +-------- |
| 10 | + |
| 11 | +Vertex AI provides several server-side tools that can be enabled when calling the model: |
| 12 | + |
| 13 | +- **URL Context** - Fetches and analyzes content from URLs |
| 14 | +- **Grounding** - Lets a model output connect to verifiable sources of information. |
| 15 | +- **Code Execution** - Executes code in a sandboxed environment. |
| 16 | + |
| 17 | +Available Server Tools |
| 18 | +---------------------- |
| 19 | + |
| 20 | +**URL Context** |
| 21 | + |
| 22 | +The URL Context tool allows the model to fetch and analyze content from specified web pages. This is useful for: |
| 23 | + |
| 24 | +- Analyzing current web content |
| 25 | +- Extracting structured information from pages |
| 26 | +- Providing context from external documents |
| 27 | +- https://cloud.google.com/vertex-ai/generative-ai/docs/url-context |
| 28 | + |
| 29 | +:: |
| 30 | + |
| 31 | + $model = new VertexAi\Gemini\Model('gemini-2.5-pro'); |
| 32 | + |
| 33 | + $content = file_get_contents('https://www.euribor-rates.eu/en/current-euribor-rates/4/euribor-rate-12-months/'); |
| 34 | + $messages = new MessageBag( |
| 35 | + Message::ofUser("Based on the following page content, what was the 12-month Euribor rate a week ago?\n\n".$content) |
| 36 | + ); |
| 37 | + |
| 38 | + $result = $platform->invoke($model, $messages); |
| 39 | + |
| 40 | + |
| 41 | +**Grounding with Google Search** |
| 42 | +The Grounding tool allows the model to connect its responses to verifiable sources of information, enhancing the reliability |
| 43 | +of its outputs. More at https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview |
| 44 | +Below is an example of grounding a model's responses using Google Search, which uses publicly-available web data. |
| 45 | + |
| 46 | +* Grounding with Google Search * |
| 47 | + |
| 48 | +Ground a model's responses using Google Search, which uses publicly-available web data. |
| 49 | +More info can be found at https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview |
| 50 | + |
| 51 | +:: |
| 52 | + |
| 53 | + $model = new VertexAi\Gemini\Model('gemini-2.5-pro', [ |
| 54 | + 'tools' => [[ |
| 55 | + 'googleSearch' => new \stdClass() |
| 56 | + ]] |
| 57 | + ]); |
| 58 | + |
| 59 | + $messages = new MessageBag( |
| 60 | + Message::ofUser('What are the top breakthroughs in AI in 2025 so far?') |
| 61 | + ); |
| 62 | + |
| 63 | + $result = $platform->invoke($model, $messages); |
| 64 | + |
| 65 | +**Code Execution** |
| 66 | + |
| 67 | +Executes code in a Google-managed sandbox environment and returns both the code and its output. |
| 68 | +More info can be found at https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/code-execution |
| 69 | + |
| 70 | +:: |
| 71 | + |
| 72 | + $model = new Gemini('gemini-2.5-pro-preview-03-25', [ |
| 73 | + 'tools' => [[ |
| 74 | + 'codeExecution' => new \stdClass() |
| 75 | + ]] |
| 76 | + ]); |
| 77 | + |
| 78 | + $messages = new MessageBag( |
| 79 | + Message::ofUser('Write Python code to calculate the 50th Fibonacci number and run it') |
| 80 | + ); |
| 81 | + |
| 82 | + $result = $platform->invoke($model, $messages); |
| 83 | + |
| 84 | + |
| 85 | +Using Multiple Server Tools |
| 86 | +--------------------------- |
| 87 | + |
| 88 | +You can enable multiple tools in a single request:: |
| 89 | + |
| 90 | + $model = new Gemini('gemini-2.5-pro-preview-03-25', [ |
| 91 | + 'tools' => [[ |
| 92 | + 'googleSearch' => new \stdClass(), |
| 93 | + 'codeExecution' => new \stdClass() |
| 94 | + ]] |
| 95 | + ]); |
| 96 | + |
| 97 | +Example |
| 98 | +------- |
| 99 | + |
| 100 | +See `examples/vertexai/server-tools.php`_ for a complete working example. |
| 101 | + |
| 102 | +Limitations |
| 103 | +----------- |
| 104 | + |
| 105 | +- **Model support:** Not all Vertex AI Gemini model versions support all server tools — check the Vertex AI documentation for the chosen model ID. |
| 106 | +- **Permissions:** The Vertex AI service account and the models must have the required permissions or scopes to use server tools. |
| 107 | +- **Quotas:** Server tools are subject to usage limits and quotas configured in your Google Cloud project. |
| 108 | +- **Latency:** Using multiple tools or fetching from slow external sources can increase response time. |
| 109 | +- **Regional availability:** Ensure you are using a location that supports the selected model and tools. |
| 110 | + |
| 111 | +.. _`examples/vertexai/server-tools.php`: https://github.com/symfony/ai/blob/main/examples/vertexai/server-tools.php |
0 commit comments