Skip to content

docs: Add comprehensive documentation for Google Gemini server tools #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ $response = $chain->call($messages, [
To integrate LLMs with your application, LLM Chain supports [tool calling](https://platform.openai.com/docs/guides/function-calling) out of the box.
Tools are services that can be called by the LLM to provide additional features or process data.

#### Server Tools

Some platforms provide built-in server-side tools for enhanced capabilities without custom implementations:

1. **[Google Gemini](docs/google-gemini-server-tools.md)** - URL Context, Google Search, Code Execution

Tool calling can be enabled by registering the processors in the chain:

```php
Expand Down
96 changes: 96 additions & 0 deletions docs/google-gemini-server-tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Google Gemini Server Tools

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.

## Overview

Google Gemini provides several server-side tools that can be enabled when calling the model:

- **URL Context** - Fetches and analyzes content from URLs
- **Google Search** - Performs web searches using Google
- **Code Execution** - Executes code in a sandboxed environment

## Available Server Tools

### URL Context

The URL Context tool allows Gemini to fetch and analyze content from web pages. This is useful for:

- Analyzing current web content
- Extracting information from specific pages
- Understanding context from external sources

```php
$llm = new Gemini('gemini-2.5-pro-preview-03-25', [
'server_tools' => [
'url_context' => true
]
]);

$messages = new MessageBag(
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/')
);

$response = $chain->call($messages);
```

### Google Search

The Google Search tool enables the model to search the web and incorporate search results into its responses:

```php
$llm = new Gemini('gemini-2.5-pro-preview-03-25', [
'server_tools' => [
'google_search' => true
]
]);

$messages = new MessageBag(
Message::ofUser('What are the latest developments in quantum computing?')
);

$response = $chain->call($messages);
```

### Code Execution

The Code Execution tool provides a sandboxed environment for running code:

```php
$llm = new Gemini('gemini-2.5-pro-preview-03-25', [
'server_tools' => [
'code_execution' => true
]
]);

$messages = new MessageBag(
Message::ofUser('Calculate the factorial of 20 and show me the code')
);

$response = $chain->call($messages);
```

## Using Multiple Server Tools

You can enable multiple server tools simultaneously:

```php
$llm = new Gemini('gemini-2.5-pro-preview-03-25', [
'server_tools' => [
'url_context' => true,
'google_search' => true,
'code_execution' => true
]
]);
```

## Example

See [examples/google/server-tools.php](../examples/google/server-tools.php) for a complete working example.

## Limitations

- API key must have appropriate permissions
- Server tools may have usage quotas
- Response times may vary based on the complexity of server tool operations
- Not all Gemini model versions support all server tools