A2A शुरुआत करना

5 मिनट से कम समय में एक A2A (Agent-to-Agent) प्रोटोकॉल एजेंट बनाएँ और चलाएँ।

आवश्यकताएँ

A2A प्रोजेक्ट का प्रारंभिक ढाँचा बनाएँ

शुरू करने का सबसे तेज़ तरीका a2a टेम्पलेट है:

cargo adk new my-a2a-agent --template a2a
cd my-a2a-agent

यह निम्नलिखित के साथ एक पूर्ण प्रोजेक्ट बनाता है:

  • Cargo.toml — A2A समर्थन सहित adk-rust, (features = ["standard"] के साथ)
  • src/main.rs — बिल्डर API का उपयोग करने वाला A2A सर्वर
  • .env.example — API कुंजी प्लेसहोल्डर

अपनी API कुंजी जोड़ें:

cp .env.example .env
# Edit .env and set GOOGLE_API_KEY=your-key-here

चलाएँ:

cargo run

आपका A2A एजेंट अब http://localhost:8080 पर सेवा दे रहा है।

अन्य प्रदाता

# OpenAI
cargo adk new my-agent --template a2a --provider openai

# Anthropic
cargo adk new my-agent --template a2a --provider anthropic

सुविधाजनक API

ADK-Rust, मैन्युअल रूट कॉन्फ़िगरेशन के बिना किसी भी एजेंट को A2A प्रोटोकॉल के माध्यम से उपलब्ध कराने के लिए A2aServer प्रदान करता है।

शून्य-कॉन्फ़िगरेशन: quick_start

सबसे सरल तरीका — एक फ़ंक्शन कॉल, उचित डिफ़ॉल्ट सेटिंग्स:

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

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    dotenvy::dotenv().ok();
    let api_key = std::env::var("GOOGLE_API_KEY")?;

    let model = GeminiModel::new(api_key, "gemini-3.7-flash")?;

    let agent: Arc<dyn Agent> = Arc::new(
        LlmAgentBuilder::new("my-agent")
            .description("A helpful AI assistant")
            .instruction("You are a helpful assistant exposed via A2A.")
            .model(Arc::new(model))
            .build()?,
    );

    let app = A2aServer::quick_start(agent);
    let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
    axum::serve(listener, app).await?;
    Ok(())
}

quick_start निम्नलिखित कॉन्फ़िगर करता है:

  • मेमोरी में सत्र सेवा
  • GET /.well-known/agent.json पर एजेंट कार्ड
  • POST /a2a पर JSON-RPC एंडपॉइंट
  • स्ट्रीमिंग सक्षम

कस्टम कॉन्फ़िगरेशन: बिल्डर

जब आपको पोर्ट, मेटाडेटा या सत्र बैकएंड पर नियंत्रण चाहिए, तब बिल्डर का उपयोग करें:

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

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    dotenvy::dotenv().ok();
    let api_key = std::env::var("GOOGLE_API_KEY")?;
    let model = GeminiModel::new(api_key, "gemini-3.7-flash")?;

    let agent: Arc<dyn Agent> = Arc::new(
        LlmAgentBuilder::new("my-agent")
            .description("Production A2A agent")
            .instruction("You are a helpful assistant.")
            .model(Arc::new(model))
            .build()?,
    );

    let server = A2aServer::builder()
        .agent(agent)
        .bind_addr("0.0.0.0:9090")
        .agent_card_name("My Production Agent")
        .agent_card_description("Handles customer queries via A2A")
        .agent_card_version("2.0.0")
        .streaming(true)
        .push_notifications(false)
        .build()?;

    server.serve().await?;
    Ok(())
}
बिल्डर विधिडिफ़ॉल्टविवरण
.agent(agent)अनिवार्यएक्सपोज़ करने वाला एजेंट
.bind_addr(addr)0.0.0.0:8080सर्वर बाइंड पता
.session_service(svc)मेमोरी मेंसत्र बैकएंड
.agent_card_name(name)agent.name()एजेंट कार्ड प्रदर्शन नाम
.agent_card_description(desc)agent.description()एजेंट कार्ड विवरण
.agent_card_version(ver)"1.0.0"एजेंट कार्ड संस्करण
.agent_card_url(url)http://localhost:{port}एजेंट के लिए सार्वजनिक URL
.streaming(bool)trueस्ट्रीमिंग प्रतिक्रियाएँ सक्षम करें
.push_notifications(bool)falseपुश सूचनाएँ सक्षम करें

curl के साथ परीक्षण

जब आपका agent चल रहा हो, तो इन कमांड से उसका सत्यापन करें।

Agent Card प्राप्त करें

curl http://localhost:8080/.well-known/agent.json | jq .

अपेक्षित प्रतिक्रिया:

{
  "name": "my-agent",
  "description": "A helpful AI assistant",
  "url": "http://localhost:8080",
  "version": "1.0.0",
  "capabilities": {
    "streaming": true,
    "pushNotifications": false,
    "stateTransitionHistory": true
  },
  "skills": []
}

संदेश भेजें (JSON-RPC)

curl -X POST http://localhost:8080/a2a \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "message/send",
    "params": {
      "message": {
        "role": "user",
        "parts": [{"kind": "text", "text": "What is the A2A protocol?"}],
        "messageId": "msg-1"
      }
    },
    "id": "req-1"
  }'

अपेक्षित प्रतिक्रिया:

{
  "jsonrpc": "2.0",
  "id": "req-1",
  "result": {
    "id": "task-uuid",
    "status": {"state": "completed"},
    "artifacts": [
      {
        "parts": [{"kind": "text", "text": "The A2A protocol is..."}]
      }
    ]
  }
}

प्रतिक्रिया स्ट्रीम करें

curl -X POST http://localhost:8080/a2a/stream \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "message/stream",
    "params": {
      "message": {
        "role": "user",
        "parts": [{"kind": "text", "text": "Explain Rust in 3 sentences."}],
        "messageId": "msg-2"
      }
    },
    "id": "req-2"
  }'

यह क्रमिक task स्थिति अपडेट के साथ Server-Sent Events लौटाता है।


MCP और A2A की सीमाओं को अलग रखें

MCP किसी agent application को tools, resources और अन्य प्रकाशित क्षमताओं से जोड़ता है। A2A स्वतंत्र रूप से परिनियोजित agents को जोड़ता है और उनके remote work के जीवनचक्र को वहन करता है। कोई bridge protocols के बीच अनुवाद कर सकता है, लेकिन वह bridge एक अलग से परिनियोजित component होता है, जिसकी अपनी identity, authorization, schema mapping, task-state mapping और failure behavior होते हैं।

ADK-Rust mcp-a2a-server नाम का कोई binary प्रदान नहीं करता। MCP configuration में उस command को तब तक न रखें, जब तक आपका deployment अलग से ऐसा bridge उपलब्ध और परीक्षणित न करता हो। जब दोनों पक्ष agents हों, तो सीधे A2A client का उपयोग करें।

किसी अन्य ADK-Rust Agent से कनेक्ट करना

किसी अन्य ADK-Rust application से अपने A2A agent को कॉल करने के लिए RemoteA2aAgent का उपयोग करें:

use adk_rust::server::RemoteA2aAgent;

let remote = RemoteA2aAgent::new(
    "my-remote-agent",
    "http://localhost:8080",
);

यह एक ऐसा agent बनाता है जो network के माध्यम से आपके A2A server को requests अग्रेषित करता है।


Endpoints संदर्भ

विधिपथविवरण
GET/.well-known/agent.jsonएजेंट कार्ड (क्षमताएँ, कौशल, मेटाडेटा)
POST/a2aJSON-RPC एंडपॉइंट (message/send, message/get, आदि)
POST/a2a/streamस्ट्रीमिंग JSON-RPC (message/stream)

अगले चरण


पिछला: त्वरित शुरुआत | अगला: LlmAgent