nikkie-ftnextの日記

イベントレポートや読書メモを発信

Agent2Agent Protocol 素振りの記:a2a-samplesのPython Hello World Exampleを動かす

はじめに

七尾百合子さん、お誕生日 115日目 おめでとうございます! nikkieです。

A2Aを触り出しました。

目次

A2A: Agent2Agent Protocol

4月のGoogleの Next ‘25 で発表されたA2A(Agent2Agent Protocol)
Announcing the Agent2Agent Protocol (A2A) - Google Developers Blog

Python SDKがリリースされていることに先日気づきました。
https://pypi.org/project/a2a-sdk/

A2Aは耳にするけれど手を動かしたことはこれまでなかったので、まずはHello Worldを動かすことにしました。

PythonでA2A Hello World Example

README.mdの手順に従います。

  1. リポジトリをクローン
  2. samples/python/agents/helloworld を作業ディレクトリとします

A2Aは、サーバ(Remote Agent) - クライアント(Client Agent)のプロトコル1なので、それぞれ用意します。

サーバ側のログ

INFO:     127.0.0.1:58249 - "GET /.well-known/agent.json HTTP/1.1" 200 OK
INFO:     127.0.0.1:58249 - "GET /agent/authenticatedExtendedCard HTTP/1.1" 200 OK
INFO:     127.0.0.1:58249 - "POST / HTTP/1.1" 200 OK
INFO:     127.0.0.1:58249 - "POST / HTTP/1.1" 200 OK

クライアント側のログ(抜粋)

INFO:__main__:
Using PUBLIC agent card for client initialization (default).

INFO:__main__:
Using AUTHENTICATED EXTENDED agent card for client initialization.
INFO:__main__:A2AClient initialized.

{'id': 'c57431ae-c893-4650-af2d-770f829f049d', 'jsonrpc': '2.0', 'result': {'kind': 'message', 'messageId': 'ff334cba-ca94-43d7-819b-06843cc10b94', 'parts': [{'kind': 'text', 'text': 'Hello World'}], 'role': 'agent'}}

{'id': '9942a749-2418-40b7-a5a7-8198fa331ddb', 'jsonrpc': '2.0', 'result': {'kind': 'message', 'messageId': '1762d588-aa76-4a5a-84e1-753b28eac008', 'parts': [{'kind': 'text', 'text': 'Hello World'}], 'role': 'agent'}}

Hello Worldではどんな通信をしたのか

A2A Request Lifecycleに沿った通信をしています。
https://a2aproject.github.io/A2A/latest/topics/what-is-a2a/#a2a-request-lifecycle

  1. GET /.well-known/agent.json (Agent Discovery)
  2. Authentication
  3. POST / (sendMessage)
  4. POST / (sendMessageStream)

A2Aサーバ(Remote Agent)は Agent Card というJSONを公開しています。
https://a2aproject.github.io/A2A/latest/specification/#5-agent-discovery-the-agent-card
クライアントはまずこのCardを取得します。

この例ではAgent CardでsupportsAuthenticatedExtendedCardtrueなので2認証拡張カードも取得します。

その後sendMessageしています。
Remote Agentが公開する/JSON RPCでPOSTします。
https://a2aproject.github.io/A2A/latest/specification/#64-message-object
同期(client.send_message())とストリーム出力(client.send_message_streaming())の2回です。

Remote Agentは常に「Hello World」と返す実装です。
https://github.com/a2aproject/a2a-samples/blob/3ac8e0b44446edede8f7ea398d48c758285f9eeb/samples/python/agents/helloworld/agent_executor.py#L7-L11
agentのレスポンスはいずれもHello Worldとなっていますね。

終わりに

a2a-samplesのPython Hello World Exampleを動かし、概要を掴み始めた感覚です。

  • サーバ-クライアントモデル
  • サーバは2つのエンドポイントを実装
    • GET /.well-known/agent.json
    • POST / (JSON RPCで送る)

今回は同期/ストリームのsendMessageだけでした。
先人のブログではTaskという概念も解説されています。

MCPほどみんなが知っている状態に育つかはまだ分からないというのが大きく、私はA2Aを推し切れてはいません。
ただエアプでなくA2Aを口にしたいという想いもあるので、素振りはもう少し続けます。