0
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-sampleのHello Worldを動かしてみる

0
Last updated at Posted at 2026-03-21

A2Aとは

AIエージェント同士が相互に通信するためのプロトコル。

A2Aのエージェントと通常のエージェントとの違いは何か。

通常のエージェントは人間と会話することを目的に設計されている。一方で、A2Aのエージェントは他のAIエージェントと話すために設計されている。

なぜA2Aが必要なのか?

それは、1つのエージェントだけで解決できないタスクが発生した場合、他のエージェントにタスク委任して解決するためである。

サンプルのHello World

RAEDMEに記載の通りに動かしてみたところ、ログが出たので内容を理解していく。

ログの流れ

ざっくりとした流れは以下のようです。

  1. Publicなエージェントカードの取得
  2. Publicなエージェントカードで判明したAUTHENTICATED EXTENDEDエージェントカードの取得
  3. エージェントカードを元にA2A通信(JSON-RPC通信)

ログの内容

エージェントカードの取得に成功
Successfully fetched agent card data from http://localhost:9999/.well-known/agent-card.json

公開されたエージェントカードの取得に成功
Successfully fetched public agent card

{
  "capabilities": {
    "streaming": true
  },
  "defaultInputModes": [
    "text"
  ],
  "defaultOutputModes": [
    "text"
  ],
  "description": "Just a hello world agent",
  "name": "Hello World Agent",
  "preferredTransport": "JSONRPC",
  "protocolVersion": "0.3.0",
  "skills": [
    {
      "description": "just returns hello world",
      "examples": [
        "hi",
        "hello world"
      ],
      "id": "hello_world",
      "name": "Returns hello world",
      "tags": [
        "hello world"
      ]
    }
  ],
  "supportsAuthenticatedExtendedCard": true,
  "url": "http://localhost:9999/",
  "version": "1.0.0"
}

クライアントの初期化にPUBLICエージェントカードを使用します(デフォルト)。
Using PUBLIC agent card for client initialization (default).

パブリックカードは、認証済み拡張カードに対応しています。http://localhost:9999/agent/authenticatedExtendedCard から取得しようとしています。
Public card supports authenticated extended card. Attempting to fetch from: http://localhost:9999/agent/authenticatedExtendedCard

{
  "capabilities": {
    "streaming": true
  },
  "defaultInputModes": [
    "text"
  ],
  "defaultOutputModes": [
    "text"
  ],
  "description": "The full-featured hello world agent for authenticated users.",
  "name": "Hello World Agent - Extended Edition",
  "preferredTransport": "JSONRPC",
  "protocolVersion": "0.3.0",
  "skills": [
    {
      "description": "just returns hello world",
      "examples": [
        "hi",
        "hello world"
      ],
      "id": "hello_world",
      "name": "Returns hello world",
      "tags": [
        "hello world"
      ]
    },
    {
      "description": "A more enthusiastic greeting, only for authenticated users.",
      "examples": [
        "super hi",
        "give me a super hello"
      ],
      "id": "super_hello_world",
      "name": "Returns a SUPER Hello World",
      "tags": [
        "hello world",
        "super",
        "extended"
      ]
    }
  ],
  "supportsAuthenticatedExtendedCard": true,
  "url": "http://localhost:9999/",
  "version": "1.0.1"
}

クライアントの初期化に、AUTHENTICATED EXTENDEDエージェントカードを使用します。
Using AUTHENTICATED EXTENDED agent card for client initialization.

非推奨の警告: A2AClient は非推奨となっており、将来のバージョンで削除される予定です。JSON-RPC トランスポートを使用したクライアントを作成するには、ClientFactory を使用してください。
DeprecationWarning: A2AClient is deprecated and will be removed in a future version. Use ClientFactory to create a client with a JSON-RPC transport.

POST http://localhost:9999/ "HTTP/1.1 200 OK"

{
	"id": "4e750f09-592d-4fb0-bd95-22f54d594ad9",
	"jsonrpc": "2.0",
	"result": {
		"kind": "message",
		"messageId": "a1e58f4c-3a7d-4ad6-b9cc-49377a7727c1",
		"parts": [
			{
				"kind": "text",
				"text": "Hello World"
			}
		],
		"role": "agent"
	}
}

理解

PUBLICエージェントカードとは?

認証なしで誰でも取得できる公開されたエージェントカード
.well-known/agent-card.jsonから取得する

AUTHENTICATED EXTENDEDエージェントカードとは?

認証された後にのみ開示される拡張されたエージェントカード。
supportsAuthenticatedExtendedCardtrueの場合に、拡張のエージェントカードの存在があると判断される。(v1.0.0では、AgentCard.capabilities.extendedAgentCardにBooleanが入る)

役割は、公開カードには載せられない「機密性の高いスキル」を記述する。

エージェントカードの項目

どこにどんな情報が含まれているのかを探る

{
  // エージェントカードのバージョン
  "version": "1.0.0",
  // エージェントの名前
  "name": "Hello World Agent",
  // エージェントの説明
  "description": "Just a hello world agent",
  // エージェントのURL
  "url": "http://localhost:9999/",
  // エージェントの機能
  "capabilities": {
    // エージェントがストリーミングをサポートしているかどうか
    "streaming": true
  },
  // エージェントの入力モード
  "defaultInputModes": [
    "text"
  ],
  // エージェントの出力モード
  "defaultOutputModes": [
    "text"
  ],
  // エージェントのトランスポート
  "preferredTransport": "JSONRPC",
  // エージェントのプロトコルバージョン
  "protocolVersion": "0.3.0",
  // エージェントのスキル
  // スキルはエージェントの機能を実現するための小さな機能のこと
  // 例えば、エージェントがhello worldを返す機能を実現するためのスキルは、"hello_world"というIDを持つスキルである
  "skills": [
    {
      "description": "just returns hello world",
      // スキルの例
      "examples": [
        "hi",
        "hello world"
      ],
      "id": "hello_world",
      "name": "Returns hello world",
      "tags": [
        "hello world"
      ]
    }
  ],
  // エージェントが認証された拡張カードをサポートしているかどうか
  "supportsAuthenticatedExtendedCard": true
}
protocolVersion

プロトコルバージョン

preferredTransport

通信プロトコル(JSONRPC, gRPC, RESTなど)を指定する。
v1.0.0ではsupportedInterfaces内に含まれる。

skills

エージェントが「何ができるか」を定義する項目。
skills[].id:スキルを呼び出す際のキーとなる。
skills[].descriptionエージェントを呼び出す際に今のタスクを解決できそうかを判断する項目。Claude CodeのSkillsやSubagentsの呼び出しと同じようなイメージ。
skills[].examples: このスキルが対応できるプロンプトやシナリオの例。エージェントが何を送ればスキルが発火するかがわかる。

capabilities

直訳すると能力。
エージェントのhowに当たる部分で、どう振る舞えるかがこの項目でわかる。
ストリーミングが可能か、拡張エージェントがあるか、プッシュ通知が可能か?がわかる。

0
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
0
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?