अंतर्निहित टूल
ADK-Rust कई अंतर्निहित टूल प्रदान करता है जो agent क्षमताओं का विस्तार करते हैं बिना कस्टम कार्यान्वयन की आवश्यकता के। ये टूल बॉक्स से बाहर उपयोग करने के लिए तैयार हैं और agent फ्रेमवर्क के साथ सहजता से एकीकृत होते हैं।
अवलोकन
| Tool | उद्देश्य | उपयोग का मामला |
|---|---|---|
GoogleSearchTool | Gemini के माध्यम से वेब सर्च | वास्तविक समय की जानकारी पुनर्प्राप्ति |
ExitLoopTool | लूप समाप्ति | LoopAgent पुनरावृति को नियंत्रित करना |
LoadArtifactsTool | आर्टिफैक्ट लोडिंग | संग्रहीत बाइनरी डेटा तक पहुंचना |
GoogleSearchTool
GoogleSearchTool agents को Google Search का उपयोग करके वेब सर्च करने में सक्षम बनाता है। इस टूल को Gemini models द्वारा ग्राउंडिंग फीचर के माध्यम से आंतरिक रूप से संभाला जाता है, जिसका अर्थ है कि सर्च स्वयं model द्वारा सर्वर-साइड पर की जाती है।
मूल उपयोग
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")?;
// GoogleSearchTool बनाएं
let search_tool = GoogleSearchTool;
// agent में जोड़ें
let agent = LlmAgentBuilder::new("research_assistant")
.description("An assistant that can search the web for information")
.instruction(
"आप एक शोध सहायक हैं। जब आपसे वर्तमान घटनाओं, \
नवीनतम समाचारों, या तथ्यात्मक जानकारी के बारे में पूछा जाए, \
तो सटीक, अद्यतन जानकारी खोजने के लिए google_search टूल का उपयोग करें।"
)
.model(Arc::new(model))
.tool(Arc::new(search_tool))
.build()?;
println!("Google Search क्षमता के साथ agent बनाया गया!");
Ok(())
}
यह कैसे काम करता है
नियमित function tools के विपरीत, GoogleSearchTool अलग तरह से काम करता है:
- सर्वर-साइड निष्पादन: सर्च Gemini के ग्राउंडिंग फीचर द्वारा की जाती है, न कि स्थानीय रूप से
- स्वचालित आह्वान: model क्वेरी के आधार पर तय करता है कि कब सर्च करना है
- एकीकृत परिणाम: सर्च परिणाम सीधे model के प्रतिसाद में शामिल किए जाते हैं
टूल कार्यान्वयन सीधे कॉल किए जाने पर एक त्रुटि देता है क्योंकि वास्तविक सर्च Gemini API के भीतर होती है:
// इसे आंतरिक रूप से संभाला जाता है - आप इसे सीधे कॉल नहीं करते हैं
async fn execute(&self, _ctx: Arc<dyn ToolContext>, _args: Value) -> Result<Value> {
Err(AdkError::Tool("GoogleSearch is handled internally by Gemini".to_string()))
}
टूल विवरण
| प्रॉपर्टी | वैल्यू |
|---|---|
| नाम | google_search |
| विवरण | "वेब से जानकारी पुनर्प्राप्त करने के लिए Google सर्च करता है।" |
| पैरामीटर | Gemini model द्वारा निर्धारित |
| निष्पादन | सर्वर-साइड (Gemini ग्राउंडिंग) |
उपयोग के मामले
- वर्तमान घटनाएँ: "आज की खबरों में क्या हुआ?"
- तथ्यात्मक प्रश्न: "टोक्यो की जनसंख्या कितनी है?"
- हाल की जानकारी: "AI में नवीनतम विकास क्या हैं?"
- शोध कार्य: "नवीकरणीय ऊर्जा प्रवृत्तियों के बारे में जानकारी प्राप्त करें"
उदाहरण क्वेरीज़
// agent स्वचालित रूप से Google Search का उपयोग इन क्वेरीज़ के लिए करेगा:
// - "इस सप्ताह न्यूयॉर्क के लिए मौसम का पूर्वानुमान क्या है?"
// - "नवीनतम चैंपियनशिप गेम किसने जीता?"
// - "टेक कंपनियों के लिए वर्तमान स्टॉक मूल्य क्या हैं?"
ExitLoopTool
ExitLoopTool एक नियंत्रण tool है जिसका उपयोग 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(())
}
यह कैसे काम करता है
agentमूल्यांकन करता है कि जारी रखना है या बाहर निकलना है- जब बाहर निकलने के लिए तैयार होता है, तो
agentexit_loopको कॉल करता है toolactions.escalate = trueऔरactions.skip_summarization = trueसेट करता हैLoopAgentescalateफ़्लैग का पता लगाता है और पुनरावृति करना बंद कर देता है
टूल विवरण
| विशेषता | मान |
|---|---|
| नाम | exit_loop |
| विवरण | "लूप से बाहर निकलता है। इस फ़ंक्शन को तभी कॉल करें जब आपको ऐसा करने का निर्देश दिया गया हो।" |
| पैरामीटर्स | कोई नहीं |
| रिटर्न | खाली ऑब्जेक्ट {} |
सर्वोत्तम अभ्यास
- स्पष्ट निकास मानदंड:
agentके निर्देश में विशिष्ट शर्तों को परिभाषित करें - हमेशा
max_iterationsसेट करें: सुरक्षा उपाय के रूप में अनंत लूप को रोकें - अर्थपूर्ण निर्देश:
agentको यह समझने में मदद करें कि कब बाहर निकलना है
// अच्छा: स्पष्ट निकास मानदंड
.instruction(
"पाठ में तब तक सुधार करें जब तक वह:\n\
- व्याकरण संबंधी त्रुटियों से मुक्त न हो\n\
- 100 शब्दों से कम हो\n\
- सक्रिय आवाज़ का उपयोग करता हो\n\
जब सभी मानदंड पूरे हो जाएं, तो exit_loop को कॉल करें।"
)
// बचें: अस्पष्ट मानदंड
.instruction("पाठ में सुधार करें। पूरा होने पर बाहर निकलें।")
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-2.5-flash")?;
// आर्टिफैक्ट लोडिंग क्षमता के साथ एजेंट बनाएं
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 के काम करने के लिए, आपको इनकी आवश्यकता है:
- रनर में कॉन्फ़िगर किया गया एक
ArtifactService - आर्टिफैक्ट्स को पहले सेवा में सहेजा गया हो
- टूल को एजेंट में जोड़ा गया हो
use adk_rust::prelude::*;
use std::sync::Arc;
// आर्टिफैक्ट सेवा सेट करें
let artifact_service = Arc::new(InMemoryArtifactService::new());
// आर्टिफैक्ट सेवा के साथ रनर को कॉन्फ़िगर करें
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")?;
// कई अंतर्निहित टूल्स के साथ एजेंट बनाएं
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 {
/// एक नया GoogleSearchTool इंस्टेंस बनाएं
pub fn new() -> Self;
}
ExitLoopTool
impl ExitLoopTool {
/// एक नया ExitLoopTool इंस्टेंस बनाएं
pub fn new() -> Self;
}
LoadArtifactsTool
impl LoadArtifactsTool {
/// Create a new LoadArtifactsTool instance
pub fn new() -> Self;
}
impl Default for LoadArtifactsTool {
fn default() -> Self;
}
संबंधित
- फंक्शन टूल - कस्टम फंक्शन टूल बनाना
- MCP टूल - टूल प्रदाताओं के रूप में MCP सर्वर का उपयोग करना
- वर्कफ़्लो एजेंट - LoopAgent के साथ ExitLoopTool का उपयोग करना
- आर्टिफैक्ट - आर्टिफैक्ट के साथ बाइनरी डेटा प्रबंधित करना
पिछला: ← फंक्शन टूल | अगला: ब्राउज़र टूल →