Skip to main content

adk_tool/builtin/
google_search.rs

1use adk_core::{Result, Tool, ToolContext};
2use async_trait::async_trait;
3use serde_json::{Value, json};
4use std::sync::Arc;
5
6/// GoogleSearch is a built-in tool that is automatically invoked by Gemini
7/// models to retrieve search results from Google Search.
8/// The tool operates internally within the model and does not require or
9/// perform local code execution.
10#[derive(Default)]
11pub struct GoogleSearchTool;
12
13impl GoogleSearchTool {
14    /// Create a new `GoogleSearchTool`.
15    pub fn new() -> Self {
16        Self
17    }
18}
19
20#[async_trait]
21impl Tool for GoogleSearchTool {
22    fn name(&self) -> &str {
23        "google_search"
24    }
25
26    fn description(&self) -> &str {
27        "Performs a Google search to retrieve information from the web."
28    }
29
30    fn is_builtin(&self) -> bool {
31        true
32    }
33
34    fn declaration(&self) -> Value {
35        json!({
36            "name": self.name(),
37            "description": self.description(),
38            "x-adk-gemini-tool": {
39                "google_search": {}
40            }
41        })
42    }
43
44    async fn execute(&self, _ctx: Arc<dyn ToolContext>, _args: Value) -> Result<Value> {
45        // Google Search is handled internally by Gemini models
46        // This should not be called directly
47        Err(adk_core::AdkError::tool("GoogleSearch is handled internally by Gemini"))
48    }
49}