Skip to main content

adk_tool/builtin/
url_context.rs

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