लॉन्चर

Launcher, ADK agents को चलाने का एक सरल, एक-पंक्ति तरीका प्रदान करता है। डिफ़ॉल्ट न्यूनतम स्तर में यह adk-runner का हल्का कंसोल लॉन्चर है। जब आपको पूर्ण CLI argument parser और HTTP server mode की आवश्यकता हो, तब CLI जैसी opt-in सुविधा, जैसे cli-openai, सक्षम करें।

अवलोकन

Launcher को agent deployment को यथासंभव सरल बनाने के लिए डिज़ाइन किया गया है। कोड की एक पंक्ति से आप:

  • परीक्षण और विकास के लिए अपने agent को इंटरैक्टिव कंसोल में चला सकते हैं
  • जब cli-* सुविधा या cargo-adk api template का उपयोग किया जाता है, तब अपने agent को web UI वाले HTTP server के रूप में deploy कर सकते हैं
  • application name और artifact storage को अनुकूलित कर सकते हैं

मूल उपयोग

कंसोल मोड (डिफ़ॉल्ट)

Launcher का उपयोग करने का सबसे सरल तरीका है कि इसे अपने agent के साथ बनाएँ और run() को call करें:

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

#[tokio::main]
async fn main() -> Result<()> {
    let api_key = std::env::var("GOOGLE_API_KEY")?;
    let model = Arc::new(GeminiModel::new(&api_key, "gemini-3.7-flash")?);
    
    let agent = LlmAgentBuilder::new("my_agent")
        .description("A helpful assistant")
        .instruction("You are a helpful assistant.")
        .model(model)
        .build()?;
    
    // Run with the lightweight console launcher
    Launcher::new(Arc::new(agent)).run().await
}

अपने agent को चलाएँ:

# Interactive console (default)
cargo run

# Full CLI mode is available when your app enables a `cli-*` feature

सर्वर मोड

अपने agent को web UI वाले HTTP server के रूप में चलाने के लिए, api template का उपयोग करें या cli-* सुविधा सक्षम करें:

cargo adk new my-api --template api
cd my-api
cargo run

server शुरू होगा और यह प्रदर्शित करेगा:

🚀 ADK Server starting on http://localhost:8080
📱 Open http://localhost:8080 in your browser
Press Ctrl+C to stop

कॉन्फ़िगरेशन विकल्प

कस्टम application name

डिफ़ॉल्ट रूप से, Launcher agent के name का उपयोग application name के रूप में करता है। आप इसे अनुकूलित कर सकते हैं:

Launcher::new(Arc::new(agent))
    .app_name("my_custom_app")
    .run()
    .await

कस्टम artifact service

अपना स्वयं का artifact service implementation प्रदान करें:

use adk_artifact::InMemoryArtifactService;

let artifact_service = Arc::new(InMemoryArtifactService::new());

Launcher::new(Arc::new(agent))
    .with_artifact_service(artifact_service)
    .run()
    .await

कंसोल मोड का विवरण

कंसोल मोड में, Launcher:

  1. इन-मेमोरी session service बनाता है
  2. user के लिए एक session बनाता है
  3. एक इंटरैक्टिव REPL loop शुरू करता है
  4. agent responses को real-time में stream करता है
  5. multi-agent systems में agent transfers को संभालता है

कंसोल इंटरैक्शन

🤖 Agent ready! Type your questions (or 'exit' to quit).

You: What is the capital of France?
Assistant: The capital of France is Paris.

You: exit
👋 Goodbye!

multi-agent कंसोल

multi-agent systems का उपयोग करते समय, कंसोल दिखाता है कि कौन-सा agent response दे रहा है:

You: I need help with my order

[Agent: customer_service]
Assistant: I'll help you with your order. What's your order number?

You: ORDER-12345

🔄 [Transfer requested to: order_lookup]

[Agent: order_lookup]
Assistant: I found your order. It was shipped yesterday.

सर्वर मोड का विवरण

सर्वर मोड में, Launcher:

  1. ऑब्ज़र्वेबिलिटी के लिए टेलीमेट्री प्रारंभ करता है
  2. इन-मेमोरी सत्र सेवा बनाता है
  3. HTTP सर्वर को REST API एंडपॉइंट के साथ प्रारंभ करता है
  4. आपके एजेंट के साथ इंटरैक्ट करने के लिए वेब UI उपलब्ध कराता है

प्रोडक्शन एस्केप हैच

कस्टम रूट, मिडलवेयर, मेट्रिक्स या सर्व लूप का स्वामित्व चाहने वाले प्रोडक्शन एप्लिकेशन के लिए, build_app() का उपयोग करें:

let app = Launcher::new(Arc::new(agent))
    .with_a2a_base_url("https://agent.example.com")
    .build_app()?;

let app = app.merge(my_admin_routes());
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
axum::serve(listener, app).await?;

यदि आप A2A रूट को स्पष्ट रूप से सक्षम करना चाहते हैं, तो build_app_with_a2a(...) का उपयोग करें।

उपलब्ध एंडपॉइंट

सर्वर निम्नलिखित REST API एंडपॉइंट उपलब्ध कराता है:

  • GET /health - हेल्थ चेक एंडपॉइंट
  • POST /run_sse - Server-Sent Events स्ट्रीमिंग के साथ एजेंट चलाएँ
  • GET /sessions - सत्रों की सूची बनाएँ
  • POST /sessions - नया सत्र बनाएँ
  • GET /sessions/:app_name/:user_id/:session_id - सत्र का विवरण प्राप्त करें
  • DELETE /sessions/:app_name/:user_id/:session_id - सत्र हटाएँ

विस्तृत एंडपॉइंट विनिर्देशों के लिए सर्वर API दस्तावेज़ देखें।

वेब UI

सर्वर में एक अंतर्निर्मित वेब UI शामिल है, जिसे http://localhost:8080/ui/ पर ऐक्सेस किया जा सकता है। UI निम्नलिखित सुविधाएँ प्रदान करता है:

  • इंटरैक्टिव चैट इंटरफ़ेस
  • सत्र, स्थिति, आर्टिफैक्ट और इवेंट-टाइमलाइन का निरीक्षण
  • रीयल-टाइम स्ट्रीमिंग प्रतिक्रियाएँ और टूल गतिविधि
  • सटीक टीम डेलीगेशन और हैंडऑफ़ टोपोलॉजी
  • एजेंट और UI-प्रोटोकॉल क्षमता खोज

CLI तर्क

पूर्ण CLI लॉन्चर, cli-* सुविधा सक्षम होने पर, निम्नलिखित कमांड का समर्थन करता है:

कमांडविवरणउदाहरण
(कोई नहीं)इंटरैक्टिव कंसोल (डिफ़ॉल्ट)cargo run
chatइंटरैक्टिव कंसोल (स्पष्ट)cargo run -- chat
serveHTTP सर्वर मोडcargo run -- serve
serve --port PORTHTTP कस्टम पोर्ट पर सर्वरcargo run -- serve --port 3000

पूर्ण उदाहरण

यहाँ दोनों मोड दिखाने वाला एक पूर्ण उदाहरण दिया गया है:

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

#[tokio::main]
async fn main() -> Result<()> {
    // Load API key
    let api_key = std::env::var("GOOGLE_API_KEY")
        .expect("GOOGLE_API_KEY environment variable not set");
    
    // Create model
    let model = Arc::new(GeminiModel::new(&api_key, "gemini-3.7-flash")?);
    
    // Create agent with tools
    let weather_tool = FunctionTool::new(
        "get_weather",
        "Get the current weather for a location",
        |params, _ctx| async move {
            let location = params["location"].as_str().unwrap_or("unknown");
            Ok(json!({
                "location": location,
                "temperature": 72,
                "condition": "sunny"
            }))
        },
    );
    
    let agent = LlmAgentBuilder::new("weather_agent")
        .description("An agent that provides weather information")
        .instruction("You are a weather assistant. Use the get_weather tool to provide weather information.")
        .model(model)
        .tool(Arc::new(weather_tool))
        .build()?;
    
    // Run with Launcher. Enable a `cli-*` feature for full CLI/server mode.
    Launcher::new(Arc::new(agent))
        .app_name("weather_app")
        .run()
        .await
}

कंसोल मोड में चलाएँ:

cargo run

जनरेट किए गए API प्रोजेक्ट से सर्वर मोड में चलाएँ:

cargo adk new weather-api --template api
cd weather-api
cargo run

परिनियोजन-पूर्व सत्यापन

अपने agent को परिनियोजित करने से पहले, cargo adk build का उपयोग करके सत्यापित करें कि प्रोजेक्ट वास्तव में परिनियोजित किए बिना सही ढंग से compile होता है:

# Verify compilation (no deployment)
cargo adk build

# Build with release optimizations
cargo adk build --release

यह आपको परिनियोजन के लिए प्रतिबद्ध होने से पहले compilation errors, missing dependencies और configuration issues पकड़ने में मदद करता है। यह CI pipelines में cargo adk deploy से पहले gate के रूप में विशेष रूप से उपयोगी है।

पूर्ण command documentation के लिए cargo adk build देखें।

सर्वोत्तम प्रक्रियाएँ

  1. Environment Variables: संवेदनशील configuration (API keys) को हमेशा environment variables से लोड करें
  2. Error Handling: Result types के साथ उचित error handling का उपयोग करें
  3. Graceful Shutdown: Launcher दोनों modes में Ctrl+C को सहज रूप से संभालता है
  4. Port Selection: ऐसे ports चुनें जो अन्य services से conflict न करें (default 8080)
  5. Session Management: production में in-memory sessions के बजाय PostgresSessionService या SqliteSessionService का उपयोग करने पर विचार करें
  6. Pre-Deployment Check: समस्याओं को पहले ही पकड़ने के लिए परिनियोजन से पहले cargo adk build चलाएँ

पिछला: ← Telemetry | अगला: Server →

लॉन्चर - ADK-Rust दस्तावेज़ीकरण | ADK-Rust