त्वरित आरंभ
यह मार्गदर्शिका बताती है कि ADK-Rust के साथ कैसे आरंभ करें और उसे चलाएं। आप 10 मिनट से भी कम समय में अपना पहला AI एजेंट बनाएंगे।
पूर्वापेक्षाएँ
शुरू करने से पहले, सुनिश्चित करें कि आपके पास है:
- Rust 1.85.0 या बाद का संस्करण (
rustup update stable) - Gemini के लिए एक Google API key
चरण 1: एक नया प्रोजेक्ट बनाएँ
एक नया Rust प्रोजेक्ट बनाएँ:
cargo new my_agent
cd my_agent
आपकी प्रोजेक्ट संरचना इस प्रकार दिखेगी:
my_agent/
├── Cargo.toml
├── src/
│ └── main.rs
└── .env # You'll create this for your API key
चरण 2: निर्भरताएँ जोड़ें
अपनी Cargo.toml को आवश्यक निर्भरताओं के साथ अपडेट करें:
[package]
name = "my_agent"
version = "0.1.0"
edition = "2024"
[dependencies]
adk-rust = "0.2.0"
tokio = { version = "1.40", features = ["full"] }
dotenvy = "0.15"
निर्भरताएँ स्थापित करें:
cargo build
चरण 3: अपनी API Key सेट करें
यह प्रोजेक्ट Gemini API का उपयोग करता है, जिसके लिए एक API key की आवश्यकता होती है। यदि आपके पास कोई नहीं है, तो Google AI Studio में एक key बनाएँ।
अपने प्रोजेक्ट रूट में एक .env फ़ाइल बनाएँ:
Linux / macOS:
echo 'GOOGLE_API_KEY=your-api-key-here' > .env
Windows (PowerShell):
echo GOOGLE_API_KEY=your-api-key-here > .env
सुरक्षा सुझाव: अपनी API key को कमिट होने से बचाने के लिए
.envको अपने.gitignoreमें जोड़ें।
चरण 4: अपना Agent लिखें
src/main.rs की सामग्री को इससे बदलें:
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
// Load environment variables from .env file
dotenvy::dotenv().ok();
// Get API key from environment
let api_key = std::env::var("GOOGLE_API_KEY")
.expect("GOOGLE_API_KEY environment variable not set");
// Create the Gemini model
let model = GeminiModel::new(&api_key, "gemini-2.5-flash")?;
// Build your agent
let agent = LlmAgentBuilder::new("my_assistant")
.description("A helpful AI assistant")
.instruction("You are a friendly and helpful assistant. Answer questions clearly and concisely.")
.model(Arc::new(model))
.build()?;
// Run the agent with the CLI launcher
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
चरण 5: अपना Agent चलाएँ
अपने Agent को इंटरैक्टिव कंसोल मोड में शुरू करें:
cargo run
आपको एक प्रॉम्प्ट दिखाई देगा जहाँ आप अपने Agent के साथ चैट कर सकते हैं:
🤖 Agent ready! Type your questions (or 'exit' to quit).
You: Hello! What can you help me with?
Assistant: Hello! I'm a helpful AI assistant. I can help you with:
- Answering questions on various topics
- Explaining concepts
- Providing information and suggestions
- Having a friendly conversation
What would you like to know?
You: exit
👋 Goodbye!
चरण 6: एक Tool जोड़ें
आइए अपने Agent को Google Search Tool के साथ बेहतर बनाएं ताकि उसे वास्तविक समय की जानकारी तक पहुंच मिल सके:
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv().ok();
let api_key = std::env::var("GOOGLE_API_KEY")
.expect("GOOGLE_API_KEY environment variable not set");
let model = GeminiModel::new(&api_key, "gemini-2.5-flash")?;
// Build agent with Google Search tool
let agent = LlmAgentBuilder::new("search_assistant")
.description("An assistant that can search the web")
.instruction("You are a helpful assistant. Use the search tool to find current information when needed.")
.model(Arc::new(model))
.tool(Arc::new(GoogleSearchTool::new())) // Add search capability
.build()?;
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
अपने Agent को इंटरैक्टिव कंसोल मोड में फिर से शुरू करें:
cargo run
अब आप अपने Agent को वेब पर खोजने के लिए प्रॉम्प्ट कर सकते हैं:
You: What's the weather like in Tokyo today?
Assistant: मुझे वह जानकारी खोजने दें...
[Using GoogleSearchTool]
वर्तमान जानकारी के आधार पर, टोक्यो में मौसम है...
वेब सर्वर के रूप में चलाना
वेब-आधारित इंटरफ़ेस के लिए, serve कमांड के साथ चलाएं:
cargo run -- serve
यह सर्वर को डिफ़ॉल्ट पोर्ट 8080 पर शुरू करता है। इसे http://localhost:8080 पर एक्सेस करें।
एक कस्टम पोर्ट निर्दिष्ट करने के लिए:
cargo run -- serve --port 3000
यह सर्वर को पोर्ट 3000 पर शुरू करता है। इसे http://localhost:3000 पर एक्सेस करें।
कोड को समझना
आइए तोड़ें कि प्रत्येक भाग क्या करता है:
इंपोर्ट्स
use adk_rust::prelude::*; // GeminiModel, LlmAgentBuilder, Arc, etc.
use adk_rust::Launcher; // CLI launcher for console/server modes
use std::sync::Arc; // Thread-safe reference counting pointer
prelude::*सभी सामान्यतः उपयोग किए जाने वाले प्रकारों को इंपोर्ट करता है:GeminiModel,LlmAgentBuilder,Arc, त्रुटि प्रकार, और भी बहुत कुछLauncherएजेंट्स को चलाने के लिए CLI इंटरफ़ेस प्रदान करता हैArc(एटॉमिक रेफरेंस काउंटेड) async कार्यों में मॉडल और Agent को सुरक्षित रूप से साझा करने में सक्षम बनाता है
मॉडल निर्माण
let model = GeminiModel::new(&api_key, "gemini-2.5-flash")?;
एक GeminiModel इंस्टेंस बनाता है जो Llm ट्रेट को लागू करता है। मॉडल:
- आपके API कुंजी के साथ प्रमाणीकरण को संभालता है
- बड़े भाषा मॉडल (LLM) से स्ट्रीमिंग प्रतिक्रियाओं का प्रबंधन करता है
- Tool के लिए फ़ंक्शन कॉलिंग का समर्थन करता है
Agent बनाना
let agent = LlmAgentBuilder::new("my_assistant")
.description("A helpful AI assistant")
.instruction("You are a friendly assistant...")
.model(Arc::new(model))
.build()?;
बिल्डर पैटर्न आपके Agent को कॉन्फ़िगर करता है:
| Method | उद्देश्य |
|---|---|
new("name") | Agent का अद्वितीय पहचानकर्ता सेट करता है (लॉग्स और बहु-एजेंट सिस्टम में उपयोग किया जाता है) |
description() | Agent कार्ड्स और A2A प्रोटोकॉल में दिखाया गया संक्षिप्त विवरण |
instruction() | सिस्टम प्रॉम्प्ट - Agent के व्यक्तित्व और व्यवहार को परिभाषित करता है |
model(Arc::new(...)) | थ्रेड-सुरक्षित साझाकरण के लिए मॉडल को Arc में लपेटता है |
tool(Arc::new(...)) | (वैकल्पिक) Tools/फ़ंक्शन जोड़ता है जिन्हें Agent कॉल कर सकता है |
build() | कॉन्फ़िगरेशन को मान्य करता है और Agent इंस्टेंस बनाता है |
लॉन्चर
Launcher::new(Arc::new(agent)).run().await?;
लॉन्चर रनटाइम को संभालता है:
- कंसोल मोड (डिफ़ॉल्ट): आपके टर्मिनल में इंटरैक्टिव चैट
- सर्वर मोड (
-- serve): वेब इंटरफ़ेस के साथ REST API - सेशन स्थिति, स्ट्रीमिंग प्रतिक्रियाओं और सौम्य शटडाउन का प्रबंधन करता है
अन्य मॉडलों का उपयोग करना
ADK-Rust बॉक्स के बाहर कई LLM प्रोवाइडर्स का समर्थन करता है। उन्हें अपनी Cargo.toml फ़ाइल में फ़ीचर फ़्लैग के माध्यम से सक्षम करें:
[dependencies]
adk-rust = { version = "0.2.0", features = ["openai", "anthropic", "deepseek", "groq", "ollama"] }
अपने प्रोवाइडर के लिए उचित API key सेट करें:
# OpenAI
export OPENAI_API_KEY="your-api-key"
# Anthropic
export ANTHROPIC_API_KEY="your-api-key"
# DeepSeek
export DEEPSEEK_API_KEY="your-api-key"
# Groq
export GROQ_API_KEY="your-api-key"
# Ollama (no key needed, just run: ollama serve)
OpenAI
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv().ok();
let api_key = std::env::var("OPENAI_API_KEY")?;
let model = OpenAIClient::new(OpenAIConfig::new(api_key, "gpt-4o"))?;
let agent = LlmAgentBuilder::new("assistant")
.instruction("You are a helpful assistant.")
.model(Arc::new(model))
.build()?;
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
Anthropic
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv().ok();
let api_key = std::env::var("ANTHROPIC_API_KEY")?;
let model = AnthropicClient::new(AnthropicConfig::new(api_key, "claude-sonnet-4-20250514"))?;
let agent = LlmAgentBuilder::new("assistant")
.instruction("You are a helpful assistant.")
.model(Arc::new(model))
.build()?;
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
DeepSeek
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv().ok();
let api_key = std::env::var("DEEPSEEK_API_KEY")?;
// Standard chat model
let model = DeepSeekClient::chat(api_key)?;
// Or use reasoner for chain-of-thought reasoning
// let model = DeepSeekClient::reasoner(api_key)?;
let agent = LlmAgentBuilder::new("assistant")
.instruction("You are a helpful assistant.")
.model(Arc::new(model))
.build()?;
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
Groq (अल्ट्रा-फास्ट इन्फरेंस)
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv().ok();
let api_key = std::env::var("GROQ_API_KEY")?;
let model = GroqClient::new(GroqConfig::llama70b(api_key))?;
let agent = LlmAgentBuilder::new("assistant")
.instruction("You are a helpful assistant.")
.model(Arc::new(model))
.build()?;
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
Ollama (लोकल मॉडल्स)
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv().ok();
// Requires: ollama serve && ollama pull llama3.2
let model = OllamaModel::new(OllamaConfig::new("llama3.2"))?;
let agent = LlmAgentBuilder::new("assistant")
.instruction("You are a helpful assistant.")
.model(Arc::new(model))
.build()?;
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
समर्थित मॉडल्स
| प्रोवाइडर | मॉडल उदाहरण | फ़ीचर फ़्लैग |
|---|---|---|
| Gemini | gemini-3-pro-preview, gemini-3-flash-preview, gemini-2.5-flash, gemini-2.5-pro, gemini-2.0-flash | (डिफ़ॉल्ट) |
| OpenAI | gpt-5.2, gpt-5.2-mini, gpt-5-mini, gpt-5-nano, gpt-4.1, gpt-4.1-mini, o3-mini, gpt-4o, gpt-4o-mini | openai |
| Anthropic | claude-sonnet-4-5, claude-haiku-4-5, claude-opus-4-5, claude-sonnet-4, claude-opus-4, claude-haiku-4 | anthropic |
| DeepSeek | deepseek-chat, deepseek-reasoner | deepseek |
| Groq | gpt-oss-120b, qwen3-32b, llama-3.3-70b-versatile, mixtral-8x7b-32768 | groq |
| Ollama | gemma3, qwen2.5, llama3.2, mistral, phi4, codellama | ollama |
अगले कदम
अब जब आपका पहला Agent चल रहा है, तो इन विषयों को देखें:
- LlmAgent Configuration - सभी कॉन्फ़िगरेशन विकल्प
- Function Tools - कस्टम Tool बनाएं
- Workflow Agents - मल्टी-स्टेप पाइपलाइन बनाएं
- Sessions - बातचीत की स्थिति प्रबंधित करें
- Callbacks - Agent व्यवहार को अनुकूलित करें