अंतर्निहित उपकरण

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

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

अवलोकन

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

GoogleSearchTool

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

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

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-2.5-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(())
}

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

नियमित FunctionTool के विपरीत, GoogleSearchTool अलग तरह से काम करता है:

  1. सर्वर-साइड निष्पादन: खोज Gemini के ग्राउंडिंग फीचर द्वारा की जाती है, स्थानीय रूप से नहीं
  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 model द्वारा निर्धारित
निष्पादनसर्वर-साइड (Gemini grounding)

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

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

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

// 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 किसी भी agent को एक callable tool के रूप में लपेटता है, जिससे agent संरचना को सक्षम बनाता है जहाँ एक parent agent अपने tool-calling workflow के हिस्से के रूप में एक child agent को इनवोक कर सकता है। sub-agent से state परिवर्तन और artifacts स्वचालित रूप से parent context को अग्रेषित किए जाते हैं।

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

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. parent agent wrapped agent को एक tool के रूप में कॉल करने का निर्णय लेता है
  2. AgentTool StreamingMode::None के साथ एक invocation context बनाता है
  3. sub-agent पूरा होने तक चलता है और अपनी पूरी प्रतिक्रिया जमा करता है
  4. प्रतिक्रिया पाठ parent agent को लौटाया जाता है
  5. State deltas और artifact deltas parent context को अग्रेषित किए जाते हैं

Tool विवरण

गुणमान
नामरैप किए गए एजेंट के नाम के समान
विवरणरैप किए गए एजेंट के विवरण के समान
पैरामीटर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-2.5-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
विवरण"लूप से बाहर निकलता है। इस फ़ंक्शन को तभी कॉल करें जब आपको ऐसा करने का निर्देश दिया गया हो।"
पैरामीटरकोई नहीं
रिटर्नखाली object {}

सर्वोत्तम अभ्यास

  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 एजेंटों को नाम से संग्रहीत artifacts को पुनः प्राप्त करने की अनुमति देता है। यह तब उपयोगी होता है जब एजेंटों को पहले सहेजी गई फ़ाइलों, छवियों या अन्य बाइनरी डेटा तक पहुंचने की आवश्यकता होती है।

मूल उपयोग

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-2.5-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-2.5-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 ट्रेट को लागू करके बिल्ट-इन टूल्स के समान पैटर्न का पालन करते हुए अपने स्वयं के टूल्स बना सकते हैं:

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;
}
  • Function Tools - कस्टम फंक्शन टूल्स बनाना
  • MCP Tools - MCP सर्वर को टूल प्रदाता के रूप में उपयोग करना
  • Workflow Agents - ExitLoopTool को LoopAgent के साथ उपयोग करना
  • Artifacts - आर्टिफैक्ट्स के साथ बाइनरी डेटा का प्रबंधन करना

पिछला: ← Function Tools | अगला: Browser Tools →

अंतर्निहित उपकरण - ADK-Rust दस्तावेज़ीकरण | ADK-Rust