अंतर्निर्मित टूल

ADK-Rust कई अंतर्निर्मित टूल प्रदान करता है, जो कस्टम कार्यान्वयन की आवश्यकता के बिना एजेंट की क्षमताओं का विस्तार करते हैं। ये टूल तुरंत उपयोग के लिए तैयार हैं और एजेंट फ़्रेमवर्क के साथ सहज रूप से एकीकृत होते हैं।

प्रदाता-नेटिव टूल अब प्रदाता-विशिष्ट GenerateContentConfig.extensions ब्लॉब के बजाय सामान्य Tool API के माध्यम से घोषित किए जाते हैं। इसका अर्थ है कि आप एक ही एजेंट में Gemini Google Search, Anthropic Web Search, या OpenAI Responses web search जैसे नेटिव टूल को सामान्य FunctionTool इंस्टेंस के साथ मिला सकते हैं।

अवलोकन

उपकरणउद्देश्यउपयोग का मामला
#[tool] मैक्रोबिना अतिरिक्त बॉयलरप्लेट के कस्टम उपकरणकोई भी कस्टम फ़ंक्शन — फ़ंक्शन उपकरण देखें
FunctionToolमैन्युअल कस्टम उपकरण पंजीकरणडायनेमिक उपकरण, क्लोज़र
GoogleSearchToolGemini के माध्यम से वेब खोजरीयल-टाइम जानकारी प्राप्त करना
UrlContextToolGemini URL ग्राउंडिंगलाइव URLs का सारांश या तर्कपूर्ण विश्लेषण
GoogleMapsToolGemini Google Maps ग्राउंडिंगस्थान, मार्ग और स्थानीय संदर्भ
GeminiCodeExecutionToolGemini का मूल कोड निष्पादनसर्वर-साइड Python निष्पादन
WebSearchToolAnthropic नेटिव वेब सर्चClaude सर्वर-साइड वेब सर्च
OpenAIWebSearchToolOpenAI Responses वेब सर्चOpenAI-होस्टेड रिट्रीवल
AgentToolएजेंट को कॉल करने योग्य टूल के रूप में रैप करेंएजेंट संयोजन और प्रत्यायोजन
ExitLoopToolलूप समाप्तिLoopAgent पुनरावृत्तियों को नियंत्रित करना
LoadArtifactsToolआर्टिफैक्ट लोड करनासंग्रहीत बाइनरी डेटा तक पहुंच

GoogleSearchTool

GoogleSearchTool एजेंट को Google Search का उपयोग करके वेब पर खोज करने में सक्षम बनाता है। यह टूल Gemini मॉडल द्वारा grounding सुविधा के माध्यम से आंतरिक रूप से संभाला जाता है, जिसका अर्थ है कि खोज मॉडल द्वारा स्वयं सर्वर-साइड पर की जाती है।

बुनियादी उपयोग

use adk_rust::prelude::*;
use std::sync::Arc;

#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
    let api_key = std::env::var("GOOGLE_API_KEY")?;
    let model = GeminiModel::new(&api_key, "gemini-3.7-flash")?;

    // Create the GoogleSearchTool
    let search_tool = GoogleSearchTool;

    // Add to agent
    let agent = LlmAgentBuilder::new("research_assistant")
        .description("An assistant that can search the web for information")
        .instruction(
            "You are a research assistant. When asked about current events, \
             recent news, or factual information, use the google_search tool \
             to find accurate, up-to-date information."
        )
        .model(Arc::new(model))
        .tool(Arc::new(search_tool))
        .build()?;

    println!("Agent created with Google Search capability!");
    Ok(())
}

यह कैसे काम करता है

नियमित फ़ंक्शन टूल के विपरीत, GoogleSearchTool अलग तरीके से काम करता है:

  1. सर्वर-साइड निष्पादन: खोज स्थानीय रूप से नहीं, बल्कि Gemini की grounding सुविधा द्वारा की जाती है
  2. स्वचालित आह्वान: मॉडल क्वेरी के आधार पर तय करता है कि कब खोज करनी है
  3. एकीकृत परिणाम: खोज परिणाम सीधे मॉडल की प्रतिक्रिया में शामिल किए जाते हैं

यदि सीधे कॉल किया जाए तो टूल का कार्यान्वयन एक त्रुटि लौटाता है, क्योंकि वास्तविक खोज Gemini API के भीतर होती है:

// This is handled internally - you don't call it directly
async fn execute(&self, _ctx: Arc<dyn ToolContext>, _args: Value) -> Result<Value> {
    Err(AdkError::tool("GoogleSearch is handled internally by Gemini"))
}

टूल का विवरण

गुणमान
नामgoogle_search
विवरण"वेब से जानकारी प्राप्त करने के लिए Google खोज करता है।"
पैरामीटरGemini मॉडल द्वारा निर्धारित
निष्पादनसर्वर-साइड (Gemini grounding)

उपयोग के मामले

  • समसामयिक घटनाएँ: "आज समाचारों में क्या हुआ?"
  • तथ्यात्मक प्रश्न: "टोक्यो की जनसंख्या कितनी है?"
  • हाल की जानकारी: "AI में नवीनतम प्रगति क्या हैं?"
  • अनुसंधान कार्य: "नवीकरणीय ऊर्जा के रुझानों के बारे में जानकारी खोजें"

उदाहरण प्रश्न

// The agent will automatically use Google Search for queries like:
// - "What's the weather forecast for New York this week?"
// - "Who won the latest championship game?"
// - "What are the current stock prices for tech companies?"

AgentTool

AgentTool किसी भी एजेंट को कॉल किए जा सकने वाले टूल के रूप में लपेटता है और प्रतिनिधि-करो-और-वापस-आओ संयोजन सक्षम करता है: कॉलर चाइल्ड को आमंत्रित करता है, उसका परिणाम प्राप्त करता है, और फिर आगे बढ़ता है। चाइल्ड द्वारा उत्सर्जित स्टेट और आर्टिफैक्ट डेल्टा पैरेंट टूल इवेंट में मर्ज कर दिए जाते हैं। चाइल्ड सेशन भी प्रत्येक इवेंट को तुरंत लागू करता है, इसलिए प्रतिनिधित वर्कफ़्लो के बाद के चरणों में पहले के स्टेट/इतिहास परिवर्तन दिखाई देते हैं।

लीगेसी डिफ़ॉल्ट अलग-थलग और पिछली-संगत बने रहते हैं। पोर्टेबल टीमें पैरेंट इतिहास/स्टेट स्नैपशॉट, मेमोरी फ़ॉरवर्डिंग, प्रसारित विफलताएँ, सीमित प्रतिनिधिमंडल गहराई, सटीक स्टेट/इतिहास प्रक्षेपण, और पंजीकृत चाइल्ड हैंडऑफ़ के आंतरिक निष्पादन को स्पष्ट रूप से सक्षम करती हैं। उपभोग किया गया चाइल्ड हैंडऑफ़ एक इवेंट के रूप में दिखाई देता रहता है, लेकिन फ़ॉरवर्ड करने से पहले उसकी ट्रांसफ़र कार्रवाई साफ़ कर दी जाती है, ताकि पैरेंट Runner उसे दो बार निष्पादित न कर सके। अनुरोध मेटाडेटा, रद्दीकरण, स्कोप, सीक्रेट, आर्टिफैक्ट और समानांतर साझा स्टेट कॉन्फ़िगर की गई फ़ॉरवर्डिंग नीति का पालन करते हैं। AgentTool स्वयं Runner के वैश्विक हैंडऑफ़ लूप को नहीं चलाता; एक संकलित TeamSpec मिश्रित टोपोलॉजी के लिए सटीक नेस्टेड हैंडऑफ़ रजिस्ट्री उपलब्ध कराता है। संकलित टीमें नेस्टेड इवेंट फ़ॉरवर्डिंग को भी स्पष्ट रूप से सक्षम करती हैं, ताकि प्रतिनिधित गतिविधि पैरेंट इवेंट स्ट्रीम पर दिखाई देती रहे; स्टैंडअलोन AgentTool लीगेसी इवेंट आउटपुट बनाए रखता है, जब तक कि forward_events(true) का चयन न किया जाए।

नियंत्रित राइट-बैक के लिए, इनपुट state_keys प्रोजेक्शन से स्वतंत्र रूप से output_state_keys का उपयोग करें। state_merge_policy(RejectConflicts) वर्तमान पैरेंट मान की तुलना प्रतिनिधिमंडल शुरू होने के समय लिए गए स्नैपशॉट से करता है और विरोधी राइट को परमाण्विक रूप से अस्वीकार करता है। artifact_prefixes आर्टिफैक्ट नामों पर भी यही अनुमत-सूची सिद्धांत लागू करता है। पिछली संगतता के लिए स्टैंडअलोन डिफ़ॉल्ट अंतिम-लेखक-विजेता बने रहते हैं और अप्रतिबंधित आउटपुट की अनुमति देते हैं; संकलित टीमें अपनी सटीक एज नीति चुनती हैं।

मूल उपयोग

use adk_rust::prelude::*;
use adk_tool::AgentTool;
use std::sync::Arc;

let sub_agent = LlmAgentBuilder::new("summarizer")
    .description("Summarizes text content")
    .instruction("Summarize the provided text concisely.")
    .model(model.clone())
    .build()?;

let agent_tool = AgentTool::new(Arc::new(sub_agent));

let coordinator = LlmAgentBuilder::new("coordinator")
    .instruction("Use the summarizer tool when asked to summarize content.")
    .model(model.clone())
    .tool(Arc::new(agent_tool))
    .build()?;

यह कैसे काम करता है

  1. पैरेंट एजेंट रैप किए गए एजेंट को एक टूल के रूप में कॉल करने का निर्णय लेता है
  2. AgentTool, StreamingMode::None के साथ एक इनवोकेशन संदर्भ बनाता है
  3. सब-एजेंट पूरा होने तक चलता है और अपनी पूरी प्रतिक्रिया संचित करता है
  4. प्रतिक्रिया का पाठ पैरेंट एजेंट को लौटाया जाता है
  5. स्थिति डेल्टा और आर्टिफैक्ट डेल्टा पैरेंट संदर्भ को अग्रेषित किए जाते हैं

टूल विवरण

गुणधर्ममान
नामरैप किए गए एजेंट के नाम के समान
विवरणरैप किए गए एजेंट के विवरण के समान
पैरामीटरrequest: string (सब-एजेंट को भेजा जाने वाला इनपुट)
लौटाता है{"response": "..."} जिसमें सब-एजेंट का टेक्स्ट आउटपुट होता है

मुख्य व्यवहार

  • विश्वसनीय प्रतिक्रिया प्राप्ति के लिए उप-एजेंट आंतरिक रूप से गैर-स्ट्रीमिंग मोड में चलते हैं
  • उप-एजेंट से होने वाले स्थिति परिवर्तन (output_key) पैरेंट सत्र में प्रसारित होते हैं
  • उप-एजेंट द्वारा सहेजे गए आर्टिफैक्ट पैरेंट संदर्भ में भेजे जाते हैं
  • एजेंट संयोजन पैटर्न के बारे में अधिक जानकारी के लिए मल्टी-एजेंट सिस्टम देखें

ExitLoopTool

ExitLoopTool एक नियंत्रण टूल है, जिसका उपयोग LoopAgent के साथ यह संकेत देने के लिए किया जाता है कि पुनरावृत्त प्रक्रिया कब समाप्त होनी चाहिए। कॉल किए जाने पर, यह escalate फ्लैग सेट करता है, जिससे लूप बाहर निकल जाता है।

मूल उपयोग

use adk_rust::prelude::*;
use std::sync::Arc;

#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
    let api_key = std::env::var("GOOGLE_API_KEY")?;
    let model = GeminiModel::new(&api_key, "gemini-3.7-flash")?;

    // Create an agent with ExitLoopTool for iterative refinement
    let refiner = LlmAgentBuilder::new("content_refiner")
        .description("Iteratively improves content quality")
        .instruction(
            "Review the content and improve it. Check for:\n\
             1. Clarity and readability\n\
             2. Grammar and spelling\n\
             3. Logical flow\n\n\
             If the content meets all quality standards, call the exit_loop tool.\n\
             Otherwise, provide an improved version."
        )
        .model(Arc::new(model))
        .tool(Arc::new(ExitLoopTool::new()))
        .build()?;

    // Use in a LoopAgent
    let loop_agent = LoopAgent::new(
        "iterative_refiner",
        vec![Arc::new(refiner)],
    ).with_max_iterations(5);

    println!("Loop agent created with exit capability!");
    Ok(())
}

यह कैसे काम करता है

  1. एजेंट यह निर्धारित करता है कि जारी रखना है या बाहर निकलना है
  2. बाहर निकलने के लिए तैयार होने पर, एजेंट exit_loop को कॉल करता है
  3. टूल actions.escalate = true और actions.skip_summarization = true सेट करता है
  4. LoopAgent एस्केलेट फ्लैग का पता लगाता है और पुनरावृत्ति रोक देता है

टूल विवरण

गुणधर्ममान
नामexit_loop
विवरण"लूप से बाहर निकलता है। इस फ़ंक्शन को केवल तभी कॉल करें जब आपको ऐसा करने का निर्देश दिया गया हो।"
पैरामीटरकोई नहीं
रिटर्न मानखाली ऑब्जेक्ट {}

सर्वोत्तम प्रथाएँ

  1. स्पष्ट निकास मानदंड: एजेंट के निर्देश में विशिष्ट शर्तें परिभाषित करें
  2. हमेशा max_iterations सेट करें: सुरक्षा उपाय के रूप में अनंत लूप को रोकें
  3. अर्थपूर्ण निर्देश: एजेंट को यह समझने में सहायता करें कि कब बाहर निकलना है
// Good: Clear exit criteria
.instruction(
    "Improve the text until it:\n\
     - Has no grammatical errors\n\
     - Is under 100 words\n\
     - Uses active voice\n\
     When all criteria are met, call exit_loop."
)

// Avoid: Vague criteria
.instruction("Improve the text. Exit when done.")

LoadArtifactsTool

LoadArtifactsTool एजेंटों को नाम के आधार पर संग्रहीत आर्टिफैक्ट पुनर्प्राप्त करने की अनुमति देता है। यह तब उपयोगी होता है जब एजेंटों को पहले से सहेजी गई फ़ाइलों, छवियों या अन्य बाइनरी डेटा तक पहुँचने की आवश्यकता होती है।

मूल उपयोग

use adk_rust::prelude::*;
use std::sync::Arc;

#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
    let api_key = std::env::var("GOOGLE_API_KEY")?;
    let model = GeminiModel::new(&api_key, "gemini-3.7-flash")?;

    // Create agent with artifact loading capability
    let agent = LlmAgentBuilder::new("document_analyzer")
        .description("Analyzes stored documents")
        .instruction(
            "You can load and analyze stored artifacts. \
             Use the load_artifacts tool to retrieve documents by name. \
             The tool accepts an array of artifact names."
        )
        .model(Arc::new(model))
        .tool(Arc::new(LoadArtifactsTool::new()))
        .build()?;

    println!("Agent created with artifact loading capability!");
    Ok(())
}

टूल विवरण

गुणमान
नामload_artifacts
विवरण"नाम के अनुसार आर्टिफैक्ट लोड करता है और उनकी सामग्री लौटाता है। आर्टिफैक्ट नामों की एक सारणी स्वीकार करता है।"
पैरामीटरartifact_names: स्ट्रिंग की सारणी
रिटर्नartifacts सारणी वाली ऑब्जेक्ट

पैरामीटर

टूल को एक JSON ऑब्जेक्ट की आवश्यकता होती है जिसमें एक artifact_names ऐरे हो:

{
  "artifact_names": ["document.txt", "image.png", "data.json"]
}

प्रतिक्रिया प्रारूप

टूल लोड किए गए आर्टिफैक्ट वाले ऑब्जेक्ट को लौटाता है:

{
  "artifacts": [
    {
      "name": "document.txt",
      "content": "The text content of the document..."
    },
    {
      "name": "image.png",
      "content": {
        "mime_type": "image/png",
        "data": "base64-encoded-data..."
      }
    },
    {
      "name": "missing.txt",
      "error": "Artifact not found"
    }
  ]
}

आवश्यकताएँ

LoadArtifactsTool के काम करने के लिए, आपको चाहिए:

  1. रनर में कॉन्फ़िगर किया गया एक ArtifactService
  2. पहले से सेवा में सहेजे गए आर्टिफैक्ट
  3. एजेंट में जोड़ा गया टूल
use adk_rust::prelude::*;
use std::sync::Arc;

// Set up artifact service
let artifact_service = Arc::new(InMemoryArtifactService::new());

// Configure runner with artifact service
let runner = Runner::new(agent)
    .with_artifact_service(artifact_service);

अंतर्निहित टूल को संयोजित करना

आप कई अंतर्निहित टूल को एक साथ उपयोग कर सकते हैं:

use adk_rust::prelude::*;
use std::sync::Arc;

#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
    let api_key = std::env::var("GOOGLE_API_KEY")?;
    let model = GeminiModel::new(&api_key, "gemini-3.7-flash")?;

    // Create agent with multiple built-in tools
    let agent = LlmAgentBuilder::new("research_agent")
        .description("Research agent with search and artifact capabilities")
        .instruction(
            "You are a research agent. You can:\n\
             - Search the web using google_search for current information\n\
             - Load stored documents using load_artifacts\n\
             Use these tools to help answer questions comprehensively."
        )
        .model(Arc::new(model))
        .tool(Arc::new(GoogleSearchTool))
        .tool(Arc::new(LoadArtifactsTool::new()))
        .build()?;

    println!("Multi-tool agent created!");
    Ok(())
}

कस्टम अंतर्निहित टूल बनाना

आप Tool trait को लागू करके अंतर्निहित टूल के समान पैटर्न का अनुसरण करते हुए अपने स्वयं के टूल बना सकते हैं:

use adk_rust::prelude::*;
use async_trait::async_trait;
use serde_json::{json, Value};
use std::sync::Arc;

pub struct MyCustomTool;

impl MyCustomTool {
    pub fn new() -> Self {
        Self
    }
}

#[async_trait]
impl Tool for MyCustomTool {
    fn name(&self) -> &str {
        "my_custom_tool"
    }

    fn description(&self) -> &str {
        "Description of what this tool does"
    }

    async fn execute(&self, ctx: Arc<dyn ToolContext>, args: Value) -> Result<Value> {
        // Your tool logic here
        Ok(json!({ "result": "success" }))
    }
}

API संदर्भ

GoogleSearchTool

impl GoogleSearchTool {
    /// Create a new GoogleSearchTool instance
    pub fn new() -> Self;
}

ExitLoopTool

impl ExitLoopTool {
    /// Create a new ExitLoopTool instance
    pub fn new() -> Self;
}

LoadArtifactsTool

impl LoadArtifactsTool {
    /// Create a new LoadArtifactsTool instance
    pub fn new() -> Self;
}

impl Default for LoadArtifactsTool {
    fn default() -> Self;
}

पिछला: ← फ़ंक्शन टूल | अगला: ब्राउज़र टूल →

अंतर्निर्मित टूल - ADK-Rust दस्तावेज़ीकरण | ADK-Rust