4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【 A2A ( Agent2Agent )】異なるフレームワーク間( ADK と Strands )のエージェント連携

Posted at

はじめに

2025年4月に Google が Agent2Agent(A2A) というオープンプロトコルを発表しました。
A2Aプロトコルは、AIエージェント間のシームレスな通信と連携を可能にするオープンスタンダードです。

今回、Google の AI エージェントフレームワークの Agent Development Kit (ADK) と AWS の Strands で構築した AI エージェントを A2A を使って通信してみました。

試してみた

A2A サーバー(Strands)

環境

今回のモデルは Gemini を利用します。

uv add strands-agents[a2a] strands-agents[gemini]

エージェント

簡単な例として、地名から天気のモックデータを返すエージェントを定義しました。

agent.py
import logging
from strands import tool
from strands import Agent
from strands.models.gemini import GeminiModel
from strands.multiagent.a2a import A2AServer

logging.basicConfig(level=logging.INFO)

model = GeminiModel(
    client_args={
        "api_key": "API_KEY",
    },
    model_id="gemini-2.5-flash",
    params={
        "temperature": 0.7,
        "max_output_tokens": 2048,
        "top_p": 0.9,
        "top_k": 40
    }
)

@tool
def get_weather(location: str) -> str:
    """
    地名から天気を取得します
    """
    return {
        "location": location,
        "weather": "晴れ",
        "temperature": "25度"
    }

# Strands agent の定義
strands_agent = Agent(
    model=model,
    name="weather_agent",
    description="天気を取得するAgentです",
    tools=[get_weather],
    callback_handler=None
)

# A2A サーバーの作成
a2a_server = A2AServer(agent=strands_agent)

# A2A サーバーの起動
a2a_server.serve()

起動

A2A サーバーを起動します。
例:http://localhost:9000

uv run agent.py

起動した URL の末尾に /.well-known/agent.json を追加することで Agent Card を確認できます。

{
  "capabilities": {
    "streaming": true
  },
  "defaultInputModes": [
    "text"
  ],
  "defaultOutputModes": [
    "text"
  ],
  "description": "天気を取得するAgentです",
  "name": "weather_agent",
  "preferredTransport": "JSONRPC",
  "protocolVersion": "0.3.0",
  "skills": [
    {
      "description": "地名から天気を取得します",
      "id": "get_weather",
      "name": "get_weather",
      "tags": []
    }
  ],
  "url": "http://localhost:9000",
  "version": "0.0.1"
}

Agent Card
A2A サーバーは、エージェントのスキルと認証要件が記述された JSON 形式の Agent Card を公開する必要があります。
A2A クライアントは、Agent Card から最適なエージェントを特定します。
そのため、A2A で通信するために重要な情報になります。

A2A クライアント(ADK)

環境

uv run google-adk a2a-sdk

エージェント


from google.adk.agents.llm_agent import Agent
from google.adk.agents.remote_a2a_agent import AGENT_CARD_WELL_KNOWN_PATH
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
from google.genai import types

# A2Aサーバー(リモートエージェント)の定義
weather_agent = RemoteA2aAgent(
    name="weather_agent",
    description=("天気を取得するAgentです"),
    agent_card=f"http://localhost:9000/{AGENT_CARD_WELL_KNOWN_PATH}",
)

# A2Aクライアント(クライアントエージェントの定義
root_agent = Agent(
    model="gemini-2.5-flash",
    name="root_agent",
    instruction="""
    あなたは weather_agent を使って、ある地点の天気を取得するAgentです。
    """,
    sub_agents=[weather_agent],
    generate_content_config=types.GenerateContentConfig(
        safety_settings=[
            types.SafetySetting(
                category=types.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
                threshold=types.HarmBlockThreshold.OFF,
            ),
        ]
    ),
)

起動

uv run adk web

検証

「東京の天気は?」と聞くと、weather_agent が使用されてA2A サーバー(Strands) で定義した天気データの内容を回答してくれました。

image.png

やり取りを詳しく見ていきます。
A2A クライアントから A2A サーバーの weather_agent へ「東京」というワードで依頼をしています。
image.png

そして、A2A サーバーの weather_agent から A2A クライアントへ「東京の天気は晴れで、気温は25度です。」と回答しています。
image.png

その回答を基に、 A2A クライアントがユーザーに返答しています。
image.png

おわりに

今回は、異なるプラットフォームで構築された AI エージェント同士を A2A を使って通信させてみました。
ユーザーの問いに対し、ADK のエージェントが Strands のエージェントを呼び出し、必要な情報を取得・回答できることを確認しました。

A2A の Agent Cardは、エージェントのための名刺兼マニュアルのような役割があります。
これにより、エージェントが動的に相手のエージェントの能力を理解して動く自律的な連携が可能になっています。

A2A の利用が進んでいくと、企業が A2A サーバーを公開し、他社のエージェントがそのエージェントを利用するというエージェント同士の連携がより密になると思われます。
今後の A2A の発展にも注視していきたいと思いました!

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?