A2A v1.0 (Agent-to-Agent) で chatweb.ai の39エージェントを外部から呼び出す
chatweb.aiのAgent Cardは以下のURLで公開されています:
curl https://chatweb.ai/.well-known/agent-card.json | jq .
Agent Cardには、利用可能なスキル(エージェント)一覧、対応プロトコル、認証方式が含まれます。
JSON-RPC 2.0形式で POST /a2a にリクエストを送信します。
{
"jsonrpc": "2.0",
"method": "SendMessage",
"params": {
"message": {
"role": "ROLE_USER",
"parts": [
{"text": "NVIDIAの最新株価と決算を分析して", "mediaType": "text/plain"}
],
"contextId": "conv-12345"
}
},
"id": "req-001"
}
curl -X POST https://chatweb.ai/a2a \
-H "Content-Type: application/json" \
-H "X-API-Key: your_api_key" \
-d '{
"jsonrpc": "2.0",
"method": "SendMessage",
"params": {
"message": {
"role": "ROLE_USER",
"parts": [{"text": "競合3社を調べてレポートにして"}]
}
},
"id": "1"
}'
{
"jsonrpc": "2.0",
"result": {
"id": "task-uuid",
"contextId": "conv-12345",
"status": {"state": "TASK_STATE_COMPLETED"},
"artifacts": [{
"parts": [{"text": "# 競合分析レポート\n...", "mediaType": "text/markdown"}],
"metadata": {
"agent_id": "research",
"agent_name": "🔍 リサーチAI",
"latency_ms": 3200,
"cost_usd": 0.0005
}
}]
},
"id": "req-001"
}
SSE(Server-Sent Events)でリアルタイムにレスポンスを受け取れます。
curl -X POST https://chatweb.ai/a2a \
-H "Content-Type: application/json" \
-H "X-API-Key: your_api_key" \
-d '{
"jsonrpc": "2.0",
"method": "SendStreamingMessage",
"params": {
"message": {
"role": "ROLE_USER",
"parts": [{"text": "Pythonで素数判定プログラムを書いて実行して"}]
}
},
"id": "stream-1"
}'
SSEイベント:
data: {"jsonrpc":"2.0","result":{"taskStatusUpdate":{"taskId":"...","status":{"state":"TASK_STATE_WORKING"}}},"id":"stream-1"}
data: {"jsonrpc":"2.0","result":{"taskArtifactUpdate":{"taskId":"...","artifact":{"parts":[{"text":"...","mediaType":"text/markdown"}]}}},"id":"stream-1"}
data: {"jsonrpc":"2.0","result":{"taskStatusUpdate":{"taskId":"...","status":{"state":"TASK_STATE_COMPLETED"}}},"id":"stream-1"}
{"jsonrpc":"2.0","method":"GetTask","params":{"id":"task-uuid"},"id":"2"}
{"jsonrpc":"2.0","method":"ListTasks","params":{"limit":10},"id":"3"}
{"jsonrpc":"2.0","method":"CancelTask","params":{"id":"task-uuid"},"id":"4"}
import httpx, json
API_KEY = "your_api_key"
BASE = "https://chatweb.ai/a2a"
def send_task(message: str) -> dict:
resp = httpx.post(BASE, json={
"jsonrpc": "2.0",
"method": "SendMessage",
"params": {
"message": {
"role": "ROLE_USER",
"parts": [{"text": message}],
}
},
"id": "1",
}, headers={
"X-API-Key": API_KEY,
"Content-Type": "application/json",
}, timeout=120)
return resp.json()
# 使用例
result = send_task("今日のAIニュースを3つ調べて要約して")
task = result["result"]
print(f"Agent: {task['artifacts'][0]['metadata']['agent_name']}")
print(f"Response: {task['artifacts'][0]['parts'][0]['text']}")
print(f"Cost: ${task['artifacts'][0]['metadata']['cost_usd']}")
TASK_STATE_WORKING — 処理中 TASK_STATE_COMPLETED — 完了 TASK_STATE_FAILED — 失敗 TASK_STATE_CANCELED — キャンセル済み TASK_STATE_INPUT_REQUIRED — 追加入力が必要 TASK_STATE_AUTH_REQUIRED — 認証が必要
X-API-Key ヘッダーでAPIキーを送信します。APIキーは chatweb.ai の設定画面から発行できます。
curl -H "X-API-Key: cw_xxxxxxxxxxxx" https://chatweb.ai/a2a ...
Agent Cardの skills フィールドに全エージェントが列挙されています。主なもの:
research — Web検索・調査・レポート code — コード生成・E2B実行 gmail — Gmail送受信 calendar — Googleカレンダー操作 image — AI画像生成 translate — 多言語翻訳 legal — 契約書レビュー・法務 finance — 株価・財務分析 site_publisher — Webサイト公開 schedule — cron定期実行 notify — LINE/Telegram/メール通知