SponsoredImage to Layers — No Photoshop Skills NeededTry ImageLayered ↗
A2A Protocol Specification (Python)

概要

A2A(Agent2Agent)プロトコルは、インテリジェントエージェント間のインタラクションのために設計されたJSON-RPC 2.0ベースの通信プロトコルです。このプロトコルは、エージェント能力宣言、メッセージパッシング、タスク管理、セキュリティ認証を含むコア機能を定義します。

このドキュメントはa2a-python/src/a2a/types.pyファイルに基づいており、A2Aプロトコルのすべてのデータ構造とオブジェクト関係の詳細な紹介を提供します。

プロトコルバージョン

現在のプロトコルバージョン:0.2.5

コア概念

1. エージェント

エージェントはA2Aプロトコルのコアエンティティであり、ユーザーリクエストを処理し、タスクを実行するための特定のスキルと能力を持ちます。

2. タスク

タスクはエージェントによって実行される作業単位であり、ライフサイクル状態管理と履歴記録機能を特徴とします。

3. メッセージ

メッセージはユーザーとエージェント間で情報を交換する基本単位であり、複数のコンテンツタイプをサポートします。

4. JSON-RPC 2.0

A2AプロトコルはJSON-RPC 2.0標準に基づいており、標準化されたリクエスト-レスポンス通信パターンを提供します。

データ構造詳細

基本タイプ

A2A

class A2A(RootModel[Any]):
    root: Any

プロトコルのルートタイプ、任意のデータを含むことができます。

Role(列挙型)

class Role(str, Enum):
    """メッセージ送信者の役割"""
    agent = 'agent'  # エージェント
    user = 'user'    # ユーザー

TaskState(列挙型)

class TaskState(str, Enum):
    """タスクの可能な状態"""
    submitted = 'submitted'           # 提出済み
    working = 'working'               # 作業中
    input_required = 'input-required' # 入力が必要
    completed = 'completed'           # 完了
    canceled = 'canceled'             # キャンセル済み
    failed = 'failed'                 # 失敗
    rejected = 'rejected'             # 拒否
    auth_required = 'auth-required'   # 認証が必要
    unknown = 'unknown'               # 不明な状態

エージェント関連タイプ

AgentCard

class AgentCard(A2ABaseModel):
    """エージェントカード - エージェントの重要な情報を含む"""
    name: str                                    # エージェント名
    description: str                             # エージェント説明
    version: str                                 # エージェントバージョン
    url: str                                     # エージェントURL
    protocolVersion: str | None = '0.2.5'       # プロトコルバージョン
    skills: list[AgentSkill]                     # スキルリスト
    capabilities: AgentCapabilities              # 能力宣言
    defaultInputModes: list[str]                 # デフォルト入力モード
    defaultOutputModes: list[str]                # デフォルト出力モード
    provider: AgentProvider | None = None        # サービスプロバイダー
    security: list[dict[str, list[str]]] | None = None  # セキュリティ要件
    securitySchemes: dict[str, SecurityScheme] | None = None  # セキュリティスキーム
    # ... その他のフィールド

AgentSkill

class AgentSkill(A2ABaseModel):
    """エージェントスキル - エージェントが実行できる能力単位"""
    id: str                          # スキル一意識別子
    name: str                        # スキル名
    description: str                 # スキル説明
    tags: list[str]                  # スキルタグ
    examples: list[str] | None = None # 使用例
    inputModes: list[str] | None = None   # 入力モード
    outputModes: list[str] | None = None  # 出力モード

AgentCapabilities

class AgentCapabilities(A2ABaseModel):
    """エージェント能力定義"""
    extensions: list[AgentExtension] | None = None      # サポートされる拡張
    pushNotifications: bool | None = None               # プッシュ通知サポート
    stateTransitionHistory: bool | None = None          # 状態遷移履歴
    streaming: bool | None = None                       # ストリーミングサポート

AgentExtension

class AgentExtension(A2ABaseModel):
    """エージェント拡張宣言"""
    uri: str                                # 拡張URI
    description: str | None = None          # 拡張説明
    params: dict[str, Any] | None = None    # 拡張パラメータ
    required: bool | None = None            # 必須かどうか

AgentProvider

class AgentProvider(A2ABaseModel):
    """エージェントサービスプロバイダー"""
    organization: str  # 組織名
    url: str          # 組織URL

AgentInterface

class AgentInterface(A2ABaseModel):
    """エージェントインターフェース宣言"""
    transport: str  # 転送プロトコル(JSONRPC、GRPC、HTTP+JSON)
    url: str       # インターフェースURL

メッセージ関連タイプ

Message

class Message(A2ABaseModel):
    """ユーザーとエージェント間で交換されるメッセージ"""
    messageId: str                           # メッセージID
    role: Role                               # 送信者の役割
    parts: list[Part]                        # メッセージコンテンツ部分
    kind: Literal['message'] = 'message'     # イベントタイプ
    taskId: str | None = None                # 関連するタスクID
    contextId: str | None = None             # コンテキストID
    referenceTaskIds: list[str] | None = None # 参照されるタスクIDリスト
    extensions: list[str] | None = None       # 拡張URIリスト
    metadata: dict[str, Any] | None = None    # メタデータ

Part(ユニオンタイプ)

class Part(RootModel[TextPart | FilePart | DataPart]):
    """メッセージ部分 - テキスト、ファイル、または構造化データ"""
    root: TextPart | FilePart | DataPart

TextPart

class TextPart(A2ABaseModel):
    """テキストメッセージ部分"""
    kind: Literal['text'] = 'text'           # 部分タイプ
    text: str                                # テキストコンテンツ
    metadata: dict[str, Any] | None = None   # メタデータ

FilePart

class FilePart(A2ABaseModel):
    """ファイルメッセージ部分"""
    kind: Literal['file'] = 'file'           # 部分タイプ
    file: FileWithBytes | FileWithUri        # ファイルコンテンツ
    metadata: dict[str, Any] | None = None   # メタデータ

DataPart

class DataPart(A2ABaseModel):
    """構造化データメッセージ部分"""
    kind: Literal['data'] = 'data'           # 部分タイプ
    data: dict[str, Any]                     # 構造化データ
    metadata: dict[str, Any] | None = None   # メタデータ

ファイルタイプ

FileWithBytes
class FileWithBytes(A2ABaseModel):
    """バイトコンテンツを含むファイル"""
    bytes: str                        # base64エンコードされたファイルコンテンツ
    name: str | None = None           # ファイル名
    mimeType: str | None = None       # MIMEタイプ
FileWithUri
class FileWithUri(A2ABaseModel):
    """URIを含むファイル"""
    uri: str                          # ファイルURL
    name: str | None = None           # ファイル名
    mimeType: str | None = None       # MIMEタイプ

タスク関連タイプ

Task

class Task(A2ABaseModel):
    """タスクエンティティ"""
    id: str                                  # タスク一意識別子
    contextId: str                           # コンテキストID
    status: TaskStatus                       # タスクステータス
    kind: Literal['task'] = 'task'           # イベントタイプ
    history: list[Message] | None = None     # メッセージ履歴
    artifacts: list[Artifact] | None = None  # 生成されたアーティファクト
    metadata: dict[str, Any] | None = None   # メタデータ

TaskStatus

class TaskStatus(A2ABaseModel):
    """タスクステータスと関連メッセージ"""
    state: TaskState                         # タスク状態
    message: Message | None = None           # ステータス更新メッセージ
    timestamp: str | None = None             # タイムスタンプ(ISO 8601)

Artifact

class Artifact(A2ABaseModel):
    """タスクによって生成されたアーティファクト"""
    artifactId: str                          # アーティファクトID
    parts: list[Part]                        # アーティファクトコンテンツ部分
    name: str | None = None                  # アーティファクト名
    description: str | None = None           # アーティファクト説明
    extensions: list[str] | None = None      # 拡張URIリスト
    metadata: dict[str, Any] | None = None   # メタデータ

JSON-RPC関連タイプ

JSONRPCMessage(基底クラス)

class JSONRPCMessage(A2ABaseModel):
    """JSON-RPC 2.0メッセージ基底クラス"""
    jsonrpc: Literal['2.0'] = '2.0'          # プロトコルバージョン
    id: str | int | None = None              # リクエスト/レスポンスID

JSONRPCRequest

class JSONRPCRequest(A2ABaseModel):
    """JSON-RPC 2.0リクエストオブジェクト"""
    jsonrpc: Literal['2.0'] = '2.0'          # プロトコルバージョン
    method: str                              # メソッド名
    params: dict[str, Any] | None = None     # パラメータ
    id: str | int | None = None              # リクエストID

JSONRPCSuccessResponse

class JSONRPCSuccessResponse(A2ABaseModel):
    """JSON-RPC 2.0成功レスポンスオブジェクト"""
    jsonrpc: Literal['2.0'] = '2.0'          # プロトコルバージョン
    result: Any                              # 結果データ
    id: str | int | None = None              # レスポンスID

JSONRPCErrorResponse

class JSONRPCErrorResponse(A2ABaseModel):
    """JSON-RPC 2.0エラーレスポンスオブジェクト"""
    jsonrpc: Literal['2.0'] = '2.0'          # プロトコルバージョン
    error: JSONRPCError | [specific error type]      # エラー情報
    id: str | int | None = None              # レスポンスID

エラータイプ

A2Aプロトコルは複数のエラータイプを定義し、すべて標準JSON-RPCエラーから継承します:

標準JSON-RPCエラー

JSONParseError
class JSONParseError(A2ABaseModel):
    """JSON解析エラー"""
    code: Literal[-32700] = -32700
    message: str | None = 'Invalid JSON payload'
    data: Any | None = None
InvalidRequestError
class InvalidRequestError(A2ABaseModel):
    """無効なリクエストエラー"""
    code: Literal[-32600] = -32600
    message: str | None = 'Request payload validation error'
    data: Any | None = None
MethodNotFoundError
class MethodNotFoundError(A2ABaseModel):
    """メソッドが見つからないエラー"""
    code: Literal[-32601] = -32601
    message: str | None = 'Method not found'
    data: Any | None = None
InvalidParamsError
class InvalidParamsError(A2ABaseModel):
    """無効なパラメータエラー"""
    code: Literal[-32602] = -32602
    message: str | None = 'Invalid parameters'
    data: Any | None = None
InternalError
class InternalError(A2ABaseModel):
    """内部エラー"""
    code: Literal[-32603] = -32603
    message: str | None = 'Internal error'
    data: Any | None = None

A2A固有エラー

TaskNotFoundError
class TaskNotFoundError(A2ABaseModel):
    """タスクが見つからないエラー"""
    code: Literal[-32001] = -32001
    message: str | None = 'Task not found'
    data: Any | None = None
TaskNotCancelableError
class TaskNotCancelableError(A2ABaseModel):
    """タスクキャンセル不可エラー"""
    code: Literal[-32002] = -32002
    message: str | None = 'Task cannot be canceled'
    data: Any | None = None
PushNotificationNotSupportedError
class PushNotificationNotSupportedError(A2ABaseModel):
    """プッシュ通知サポートなしエラー"""
    code: Literal[-32003] = -32003
    message: str | None = 'Push Notification is not supported'
    data: Any | None = None
UnsupportedOperationError
class UnsupportedOperationError(A2ABaseModel):
    """サポートされていない操作エラー"""
    code: Literal[-32004] = -32004
    message: str | None = 'This operation is not supported'
    data: Any | None = None
ContentTypeNotSupportedError
class ContentTypeNotSupportedError(A2ABaseModel):
    """コンテンツタイプサポートなしエラー"""
    code: Literal[-32005] = -32005
    message: str | None = 'Incompatible content types'
    data: Any | None = None
InvalidAgentResponseError
class InvalidAgentResponseError(A2ABaseModel):
    """無効なエージェントレスポンスエラー"""
    code: Literal[-32006] = -32006
    message: str | None = 'Invalid agent response'
    data: Any | None = None

セキュリティ認証関連タイプ

SecurityScheme(ユニオンタイプ)

class SecurityScheme(RootModel[
    APIKeySecurityScheme |
    HTTPAuthSecurityScheme |
    OAuth2SecurityScheme |
    OpenIdConnectSecurityScheme
]):
    """セキュリティスキーム - 複数の認証方法をサポート"""

APIKeySecurityScheme

class APIKeySecurityScheme(A2ABaseModel):
    """APIキーセキュリティスキーム"""
    type: Literal['apiKey'] = 'apiKey'
    name: str                              # パラメータ名
    in_: In                                # 場所(header/query/cookie)
    description: str | None = None         # 説明

HTTPAuthSecurityScheme

class HTTPAuthSecurityScheme(A2ABaseModel):
    """HTTP認証セキュリティスキーム"""
    type: Literal['http'] = 'http'
    scheme: str                            # 認証スキーム(Basic、Bearerなど)
    bearerFormat: str | None = None        # Bearerトークン形式
    description: str | None = None         # 説明

OAuth2SecurityScheme

class OAuth2SecurityScheme(A2ABaseModel):
    """OAuth2.0セキュリティスキーム"""
    type: Literal['oauth2'] = 'oauth2'
    flows: OAuthFlows                      # OAuthフロー設定
    description: str | None = None         # 説明

OpenIdConnectSecurityScheme

class OpenIdConnectSecurityScheme(A2ABaseModel):
    """OpenID Connectセキュリティスキーム"""
    type: Literal['openIdConnect'] = 'openIdConnect'
    openIdConnectUrl: str                  # OpenID Connect発見URL
    description: str | None = None         # 説明

OAuthフロータイプ

OAuthFlows
class OAuthFlows(A2ABaseModel):
    """OAuthフロー設定"""
    implicit: ImplicitOAuthFlow | None = None                    # 暗黙的フロー
    password: PasswordOAuthFlow | None = None                    # パスワードフロー
    clientCredentials: ClientCredentialsOAuthFlow | None = None  # クライアント認証情報フロー
    authorizationCode: AuthorizationCodeOAuthFlow | None = None  # 認可コードフロー

プッシュ通知関連タイプ

PushNotificationConfig

class PushNotificationConfig(A2ABaseModel):
    """プッシュ通知設定"""
    url: str                                                    # プッシュURL
    id: str | None = None                                       # プッシュ通知ID
    token: str | None = None                                    # セッショントークン
    authentication: PushNotificationAuthenticationInfo | None = None  # 認証情報

PushNotificationAuthenticationInfo

class PushNotificationAuthenticationInfo(A2ABaseModel):
    """プッシュ通知認証情報"""
    schemes: list[str]                     # サポートされる認証スキーム
    credentials: str | None = None         # 認証情報

リクエストとレスポンスタイプ

メッセージ送信

SendMessageRequest
class SendMessageRequest(A2ABaseModel):
    """メッセージ送信リクエスト"""
    jsonrpc: Literal['2.0'] = '2.0'
    method: Literal['message/send'] = 'message/send'
    params: MessageSendParams
    id: str | int
MessageSendParams
class MessageSendParams(A2ABaseModel):
    """メッセージ送信パラメータ"""
    message: Message                                    # 送信するメッセージ
    configuration: MessageSendConfiguration | None = None  # 送信設定
    metadata: dict[str, Any] | None = None             # メタデータ
MessageSendConfiguration
class MessageSendConfiguration(A2ABaseModel):
    """メッセージ送信設定"""
    acceptedOutputModes: list[str]                          # 受け入れられる出力モード
    blocking: bool | None = None                            # リクエストをブロックするかどうか
    historyLength: int | None = None                        # 履歴メッセージ長
    pushNotificationConfig: PushNotificationConfig | None = None  # プッシュ通知設定

タスク操作

GetTaskRequest
class GetTaskRequest(A2ABaseModel):
    """タスク取得リクエスト"""
    jsonrpc: Literal['2.0'] = '2.0'
    method: Literal['tasks/get'] = 'tasks/get'
    params: TaskQueryParams
    id: str | int
TaskQueryParams
class TaskQueryParams(A2ABaseModel):
    """タスククエリパラメータ"""
    id: str                              # タスクID
    historyLength: int | None = None     # 履歴長
    metadata: dict[str, Any] | None = None  # メタデータ
CancelTaskRequest
class CancelTaskRequest(A2ABaseModel):
    """タスクキャンセルリクエスト"""
    jsonrpc: Literal['2.0'] = '2.0'
    method: Literal['tasks/cancel'] = 'tasks/cancel'
    params: TaskIdParams
    id: str | int

イベントタイプ

TaskStatusUpdateEvent

class TaskStatusUpdateEvent(A2ABaseModel):
    """タスクステータス更新イベント"""
    kind: Literal['status-update'] = 'status-update'
    taskId: str                              # タスクID
    contextId: str                           # コンテキストID
    status: TaskStatus                       # タスクステータス
    final: bool                              # 最終イベントかどうか
    metadata: dict[str, Any] | None = None   # メタデータ

TaskArtifactUpdateEvent

class TaskArtifactUpdateEvent(A2ABaseModel):
    """タスクアーティファクト更新イベント"""
    kind: Literal['artifact-update'] = 'artifact-update'
    taskId: str                              # タスクID
    contextId: str                           # コンテキストID
    artifact: Artifact                       # アーティファクト
    append: bool | None = None               # 追加するかどうか
    lastChunk: bool | None = None            # 最後のチャンクかどうか
    metadata: dict[str, Any] | None = None   # メタデータ

オブジェクト関係図

graph TB
    %% コアエンティティ
    AgentCard[AgentCard<br/>エージェントカード]
    Task[Task<br/>タスク]
    Message[Message<br/>メッセージ]
    
    %% エージェント関連
    AgentSkill[AgentSkill<br/>エージェントスキル]
    AgentCapabilities[AgentCapabilities<br/>エージェント能力]
    AgentProvider[AgentProvider<br/>サービスプロバイダー]
    AgentExtension[AgentExtension<br/>エージェント拡張]
    AgentInterface[AgentInterface<br/>エージェントインターフェース]
    
    %% メッセージコンテンツ
    Part[Part<br/>メッセージ部分]
    TextPart[TextPart<br/>テキスト部分]
    FilePart[FilePart<br/>ファイル部分]
    DataPart[DataPart<br/>データ部分]
    
    %% ファイルタイプ
    FileWithBytes[FileWithBytes<br/>バイトファイル]
    FileWithUri[FileWithUri<br/>URIファイル]
    
    %% タスク関連
    TaskStatus[TaskStatus<br/>タスクステータス]
    Artifact[Artifact<br/>アーティファクト]
    
    %% JSON-RPC
    JSONRPCRequest[JSONRPCRequest<br/>JSON-RPCリクエスト]
    JSONRPCResponse[JSONRPCResponse<br/>JSON-RPCレスポンス]
    
    %% セキュリティ認証
    SecurityScheme[SecurityScheme<br/>セキュリティスキーム]
    APIKeySecurityScheme[APIKeySecurityScheme<br/>APIキースキーム]
    HTTPAuthSecurityScheme[HTTPAuthSecurityScheme<br/>HTTP認証スキーム]
    OAuth2SecurityScheme[OAuth2SecurityScheme<br/>OAuth2スキーム]
    OpenIdConnectSecurityScheme[OpenIdConnectSecurityScheme<br/>OpenID Connectスキーム]
    
    %% プッシュ通知
    PushNotificationConfig[PushNotificationConfig<br/>プッシュ通知設定]
    PushNotificationAuthenticationInfo[PushNotificationAuthenticationInfo<br/>プッシュ認証情報]
    
    %% エラータイプ
    A2AError[A2AError<br/>A2Aエラー]
    JSONRPCError[JSONRPCError<br/>JSON-RPCエラー]
    
    %% イベント
    TaskStatusUpdateEvent[TaskStatusUpdateEvent<br/>ステータス更新イベント]
    TaskArtifactUpdateEvent[TaskArtifactUpdateEvent<br/>アーティファクト更新イベント]
    
    %% 関係接続
    AgentCard --> AgentSkill
    AgentCard --> AgentCapabilities
    AgentCard --> AgentProvider
    AgentCard --> AgentInterface
    AgentCard --> SecurityScheme
    
    AgentCapabilities --> AgentExtension
    
    Task --> TaskStatus
    Task --> Message
    Task --> Artifact
    
    Message --> Part
    Part --> TextPart
    Part --> FilePart
    Part --> DataPart
    
    FilePart --> FileWithBytes
    FilePart --> FileWithUri
    
    Artifact --> Part
    
    SecurityScheme --> APIKeySecurityScheme
    SecurityScheme --> HTTPAuthSecurityScheme
    SecurityScheme --> OAuth2SecurityScheme
    SecurityScheme --> OpenIdConnectSecurityScheme
    
    PushNotificationConfig --> PushNotificationAuthenticationInfo
    
    TaskStatusUpdateEvent --> TaskStatus
    TaskArtifactUpdateEvent --> Artifact
    
    JSONRPCResponse --> A2AError
    A2AError --> JSONRPCError
    
    %% スタイル
    classDef coreEntity fill:#e1f5fe
    classDef agentRelated fill:#f3e5f5
    classDef messageRelated fill:#e8f5e8
    classDef taskRelated fill:#fff3e0
    classDef securityRelated fill:#fce4ec
    classDef errorRelated fill:#ffebee
    classDef eventRelated fill:#f1f8e9
    
    class AgentCard,Task,Message coreEntity
    class AgentSkill,AgentCapabilities,AgentProvider,AgentExtension,AgentInterface agentRelated
    class Part,TextPart,FilePart,DataPart,FileWithBytes,FileWithUri messageRelated
    class TaskStatus,Artifact taskRelated
    class SecurityScheme,APIKeySecurityScheme,HTTPAuthSecurityScheme,OAuth2SecurityScheme,OpenIdConnectSecurityScheme,PushNotificationConfig,PushNotificationAuthenticationInfo securityRelated
    class A2AError,JSONRPCError errorRelated
    class TaskStatusUpdateEvent,TaskArtifactUpdateEvent eventRelated

プロトコルフロー図

sequenceDiagram
    participant Client as クライアント
    participant Agent as エージェント
    
    Note over Client,Agent: 1. エージェント発見と能力クエリ
    Client->>Agent: GET /agent-card
    Agent->>Client: AgentCard(スキル、能力、セキュリティ要件)
    
    Note over Client,Agent: 2. 認証(必要な場合)
    Client->>Agent: 認証リクエスト(SecuritySchemeに従って)
    Agent->>Client: 認証レスポンス
    
    Note over Client,Agent: 3. メッセージ送信とタスク作成
    Client->>Agent: SendMessageRequest
    Note right of Agent: タスク作成<br/>状態:submitted
    Agent->>Client: SendMessageResponse(Task)
    
    Note over Client,Agent: 4. タスク処理(オプションのプッシュ通知)
    loop タスク処理
        Note right of Agent: タスク状態更新<br/>working -> completed
        alt プッシュ通知サポート
            Agent->>Client: TaskStatusUpdateEvent
        else ポーリングモード
            Client->>Agent: GetTaskRequest
            Agent->>Client: GetTaskResponse(更新されたTask)
        end
    end
    
    Note over Client,Agent: 5. 最終結果取得
    Client->>Agent: GetTaskRequest
    Agent->>Client: Task(Artifactsと完全な履歴を含む)

タスク状態遷移図

stateDiagram-v2
    [*] --> submitted: タスク作成
    
    submitted --> working: 処理開始
    submitted --> rejected: タスク拒否
    submitted --> auth_required: 認証が必要
    
    working --> completed: 処理完了
    working --> failed: 処理失敗
    working --> input_required: ユーザー入力が必要
    working --> canceled: ユーザーキャンセル
    
    input_required --> working: ユーザー入力受信
    input_required --> canceled: ユーザーキャンセル
    
    auth_required --> working: 認証成功
    auth_required --> rejected: 認証失敗
    
    completed --> [*]
    failed --> [*]
    canceled --> [*]
    rejected --> [*]
    
    unknown --> working: 状態回復
    unknown --> failed: 回復不可

メッセージ部分タイプ階層図

flowchart TD
    Part["Part<br/>メッセージ部分基底クラス"]
    
    Part --> TextPart["TextPart<br/>テキスト部分<br/>kind: text"]
    Part --> FilePart["FilePart<br/>ファイル部分<br/>kind: file"]
    Part --> DataPart["DataPart<br/>データ部分<br/>kind: data"]
    
    FilePart --> FileContent{"ファイルコンテンツ"}
    FileContent --> FileWithBytes["FileWithBytes<br/>base64バイトデータを含む"]
    FileContent --> FileWithUri["FileWithUri<br/>ファイルURIを含む"]
    
    TextPart --> TextContent["text: str<br/>テキストコンテンツ"]
    DataPart --> DataContent["data: dict[str, Any]<br/>構造化データ"]
    
    FileWithBytes --> BytesContent["bytes: str<br/>base64エンコードコンテンツ"]
    FileWithUri --> UriContent["uri: str<br/>ファイルURL"]
    
    %% 共通属性
    Part --> Metadata["metadata: dict[str, Any]<br/>オプションメタデータ"]
    FileWithBytes --> FileMetadata["name: str<br/>mimeType: str<br/>ファイルメタデータ"]
    FileWithUri --> FileMetadata
    
    classDef baseClass fill:#e3f2fd
    classDef textClass fill:#e8f5e8
    classDef fileClass fill:#fff3e0
    classDef dataClass fill:#f3e5f5
    classDef metaClass fill:#f5f5f5
    
    class Part baseClass
    class TextPart,TextContent textClass
    class FilePart,FileWithBytes,FileWithUri,BytesContent,UriContent fileClass
    class DataPart,DataContent dataClass
    class Metadata,FileMetadata metaClass

セキュリティスキームタイプ図

flowchart TD
    SecurityScheme["SecurityScheme<br/>セキュリティスキームユニオンタイプ"]
    
    SecurityScheme --> APIKeySecurityScheme["APIKeySecurityScheme<br/>APIキー認証<br/>type: apiKey"]
    SecurityScheme --> HTTPAuthSecurityScheme["HTTPAuthSecurityScheme<br/>HTTP認証<br/>type: http"]
    SecurityScheme --> OAuth2SecurityScheme["OAuth2SecurityScheme<br/>OAuth2認証<br/>type: oauth2"]
    SecurityScheme --> OpenIdConnectSecurityScheme["OpenIdConnectSecurityScheme<br/>OpenID Connect<br/>type: openIdConnect"]
    
    APIKeySecurityScheme --> APIKeyDetails["name: str<br/>in: header|query|cookie"]
    HTTPAuthSecurityScheme --> HTTPDetails["scheme: str<br/>bearerFormat: str"]
    OAuth2SecurityScheme --> OAuthFlows["flows: OAuthFlows"]
    OpenIdConnectSecurityScheme --> OIDCDetails["openIdConnectUrl: str"]
    
    OAuthFlows --> ImplicitFlow["implicit: ImplicitOAuthFlow"]
    OAuthFlows --> PasswordFlow["password: PasswordOAuthFlow"]
    OAuthFlows --> ClientCredentialsFlow["clientCredentials: ClientCredentialsOAuthFlow"]
    OAuthFlows --> AuthorizationCodeFlow["authorizationCode: AuthorizationCodeOAuthFlow"]
    
    ImplicitFlow --> ImplicitDetails["authorizationUrl: str<br/>scopes: dict[str, str]"]
    PasswordFlow --> PasswordDetails["tokenUrl: str<br/>scopes: dict[str, str]"]
    ClientCredentialsFlow --> ClientDetails["tokenUrl: str<br/>scopes: dict[str, str]"]
    AuthorizationCodeFlow --> AuthCodeDetails["authorizationUrl: str<br/>tokenUrl: str<br/>scopes: dict[str, str]"]
    
    classDef baseClass fill:#e3f2fd
    classDef apiKeyClass fill:#e8f5e8
    classDef httpClass fill:#fff3e0
    classDef oauthClass fill:#f3e5f5
    classDef oidcClass fill:#fce4ec
    
    class SecurityScheme baseClass
    class APIKeySecurityScheme,APIKeyDetails apiKeyClass
    class HTTPAuthSecurityScheme,HTTPDetails httpClass
    class OAuth2SecurityScheme,OAuthFlows,ImplicitFlow,PasswordFlow,ClientCredentialsFlow,AuthorizationCodeFlow,ImplicitDetails,PasswordDetails,ClientDetails,AuthCodeDetails oauthClass
    class OpenIdConnectSecurityScheme,OIDCDetails oidcClass

エラーコードマッピングテーブル

エラーコード エラータイプ 説明 使用ケース
-32700 JSONParseError JSON解析エラー 無効なJSON形式
-32600 InvalidRequestError 無効なリクエスト リクエスト形式が仕様に準拠していない
-32601 MethodNotFoundError メソッドが見つからない 存在しないメソッドの呼び出し
-32602 InvalidParamsError 無効なパラメータ メソッドパラメータが正しくない
-32603 InternalError 内部エラー サーバー内部処理エラー
-32001 TaskNotFoundError タスクが見つからない リクエストされたタスクIDが存在しない
-32002 TaskNotCancelableError タスクキャンセル不可 タスク状態がキャンセルを許可しない
-32003 PushNotificationNotSupportedError プッシュ通知サポートなし エージェントがプッシュ通知をサポートしていない
-32004 UnsupportedOperationError 操作サポートなし エージェントがリクエストされた操作をサポートしていない
-32005 ContentTypeNotSupportedError コンテンツタイプサポートなし リクエストされたコンテンツタイプがエージェント能力と一致しない
-32006 InvalidAgentResponseError 無効なエージェントレスポンス エージェントが形式の間違ったレスポンスを返した

サポートされるメソッドリスト

A2Aプロトコルは以下の標準メソッドを定義します:

メッセージ関連メソッド

  • message/send - エージェントにメッセージを送信
  • message/stream - エージェントにストリーミングメッセージを送信

タスク関連メソッド

  • tasks/get - タスク詳細を取得
  • tasks/cancel - タスクをキャンセル
  • tasks/resubscribe - タスク更新を再購読

プッシュ通知設定メソッド

  • tasks/pushNotificationConfig/set - プッシュ通知設定を設定
  • tasks/pushNotificationConfig/get - プッシュ通知設定を取得
  • tasks/pushNotificationConfig/list - プッシュ通知設定をリスト
  • tasks/pushNotificationConfig/delete - プッシュ通知設定を削除

使用例

1. シンプルなテキストメッセージの送信

from a2a.types import SendMessageRequest, MessageSendParams, Message, TextPart, Part

# テキストメッセージ部分を作成
text_part = TextPart(text="こんにちは、どのようにお手伝いできますか?")
part = Part(root=text_part)

# メッセージを作成
message = Message(
    messageId="msg-001",
    role="user",
    parts=[part]
)

# 送信パラメータを作成
params = MessageSendParams(message=message)

# リクエストを作成
request = SendMessageRequest(
    id="req-001",
    params=params
)

2. ファイル付きメッセージの送信

from a2a.types import FilePart, FileWithBytes
import base64

# ファイルを読み取りエンコード
with open("document.pdf", "rb") as f:
    file_bytes = base64.b64encode(f.read()).decode()

# ファイル部分を作成
file_with_bytes = FileWithBytes(
    bytes=file_bytes,
    name="document.pdf",
    mimeType="application/pdf"
)

file_part = FilePart(file=file_with_bytes)
part = Part(root=file_part)

# ファイル付きメッセージを作成
message = Message(
    messageId="msg-002",
    role="user",
    parts=[part]
)

3. タスクステータスのクエリ

from a2a.types import GetTaskRequest, TaskQueryParams

# タスククエリリクエストを作成
request = GetTaskRequest(
    id="req-002",
    params=TaskQueryParams(
        id="task-001",
        historyLength=10  # 最新10件のメッセージ履歴を取得
    )
)

4. プッシュ通知の設定

from a2a.types import (
    SetTaskPushNotificationConfigRequest,
    TaskPushNotificationConfig,
    PushNotificationConfig,
    PushNotificationAuthenticationInfo
)

# プッシュ通知設定を作成
push_config = PushNotificationConfig(
    url="https://my-app.com/webhook/task-updates",
    authentication=PushNotificationAuthenticationInfo(
        schemes=["Bearer"],
        credentials="my-auth-token"
    )
)

# タスクプッシュ設定を作成
task_push_config = TaskPushNotificationConfig(
    taskId="task-001",
    pushNotificationConfig=push_config
)

# 設定リクエストを作成
request = SetTaskPushNotificationConfigRequest(
    id="req-003",
    params=task_push_config
)

ベストプラクティス

1. エラーハンドリング

  • レスポンスのエラーフィールドを常にチェック
  • エラーコードに基づいて適切な再試行戦略を実装
  • ユーザーに意味のあるエラーメッセージを提供

2. タスク管理

  • タスク更新にはポーリングではなくプッシュ通知を使用
  • タスクタイムアウトメカニズムを実装
  • 後続のクエリのためにタスクIDを保存

3. セキュリティ

  • HTTPS転送を使用
  • 認証スキームを適切に実装
  • APIキーとトークンを定期的にローテーション

4. パフォーマンス最適化

  • 大きなレスポンスの処理にはストリーミングを使用
  • 履歴メッセージ長を制限
  • クライアント側キャッシュを実装

拡張性

A2Aプロトコルは以下のメカニズムを通じて拡張をサポートします:

  1. エージェント拡張 - AgentExtensionを通じてカスタム能力を宣言
  2. メタデータフィールド - ほとんどのオブジェクトにオプションのmetadataフィールドが含まれる
  3. カスタム転送プロトコル - AgentInterfaceを通じて新しい転送方法をサポート
  4. 拡張URI - メッセージとアーティファクトで拡張仕様を参照

まとめ

A2Aプロトコルは、インテリジェントエージェント間の通信と協力のための包括的なフレームワークを提供します。標準化されたメッセージ形式、タスク管理、セキュリティ認証、エラーハンドリングを通じて、このプロトコルは異なるエージェント実装間の相互運用性を確保します。

プロトコルの設計は拡張性と後方互換性を考慮しており、将来の要件変更に適応できます。複数のコンテンツタイプ、転送プロトコル、認証スキームをサポートすることで、A2Aプロトコルは複雑なエージェントエコシステムを構築するための堅固な基盤を提供します。

Discover Products

Discover useful AI products and services.

Decisions API brings multiple AI decision models into one workflow for classifying, scoring, routing, and evaluating text with structured outputs.

Build smarter AI workflows with a unified API for classification, scoring, routing, verification, and other structured decisions.

Try Jev AI Model online for free after sign in. Classify, score, and route text with structured results. Buy credits for API access.

The Discord bot maker your server actually needs

Turn any flat image into named, editable layers—separate text, subjects, decorations, and backgrounds in just a few clicks.

Start with a simple prompt, then let our AI OC Maker turn your idea into anime characters, fantasy OCs, roleplay avatars, and full-body character designs.

Related Articles

Explore more content related to this topic