コンテンツにスキップ
これは最新の機能を備えた最新リリースですが、長期サポートは提供されません。サポートを継続するには、新しいリリースごとにアップグレードするか、四半期ごとの安定版リリースをご利用ください。

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

エージェントへの接続

Page as Markdown

agentgateway を使用すると、Agent-to-Agent(A2A)サーバーへのルーティングとツールのセキュアな公開が可能です。

始める前に

クイックスタートガイドに従って、Solo Enterprise for agentgateway コントロールプレーンをインストールします。

ステップ 1: A2A サーバーへのルーティングを設定する

A2A サーバーをデプロイし、そのサーバーへトラフィックをルーティングするリソースを作成します。EnterpriseAgentgatewayBackend リソース経由でルーティングすることも、サーバーを公開する Service に直接ルーティングすることもできます。

ほとんどの場合は EnterpriseAgentgatewayBackend の方法を使用します。a2a バックエンドタイプは、A2A サーバーを専用バックエンドとして表し、ポリシーのアタッチなどでさらに設定できます。また、クラスター外で実行される A2A サーバーも選択できます。Service ベースの方法ではアプリの更新(appProtocol 設定)が必要で、以前の agentgateway バージョンからのレガシーな方法です。

バックエンドの a2a タイプが A2A プロトコルを示すため、Service に appProtocol 設定は不要です。

  1. Deployment と Service で A2A サーバーをデプロイします。

    kubectl apply -f- <<EOF
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: a2a-agent
      labels:
        app: a2a-agent
    spec:
      selector:
        matchLabels:
          app: a2a-agent
      template:
        metadata:
          labels:
            app: a2a-agent
        spec:
          containers:
            - name: a2a-agent
              image: gcr.io/solo-public/docs/test-a2a-agent:latest
              ports:
                - containerPort: 9090
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: a2a-agent
    spec:
      selector:
        app: a2a-agent
      type: ClusterIP
      ports:
        - protocol: TCP
          port: 9090
          targetPort: 9090
    EOF
  2. A2A サーバーをバックエンドとして定義する EnterpriseAgentgatewayBackend リソースを作成します。a2a タイプは、指定した host と port に接続するときに A2A プロトコルを使用するよう agentgateway を設定します。

    kubectl apply -f- <<EOF
    apiVersion: enterpriseagentgateway.solo.io/v1alpha1
    kind: EnterpriseAgentgatewayBackend
    metadata:
      name: a2a-backend
    spec:
      a2a:
        host: a2a-agent.default.svc.cluster.local
        port: 9090
    EOF
  3. /myagent プレフィックスパスに沿って EnterpriseAgentgatewayBackend にトラフィックをルーティングする HTTPRoute を作成します。このプレフィックスパスにより、ゲートウェイ上の一意のアドレスで A2A サーバーを公開できます。ただし、A2A サーバーはルートパス(/)にトラフィックが送信される必要があるため、HTTPRoute に URLRewrite フィルターを追加して /myagent プレフィックスを / に書き換えます。

    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: a2a
    spec:
      parentRefs:
      - name: agentgateway-proxy
        namespace: agentgateway-system
      rules:
      - matches:
        - path:
            type: PathPrefix
            value: /myagent
        filters:
        - type: URLRewrite
          urlRewrite:
            path:
              type: ReplacePrefixMatch
              replacePrefixMatch: /
        backendRefs:
          - name: a2a-backend
            group: enterpriseagentgateway.solo.io
            kind: EnterpriseAgentgatewayBackend
    EOF
  1. Deployment と Service で A2A サーバーをデプロイします。Service で appProtocol: kgateway.dev/a2a 設定が使用されていることに注意してください。

    kubectl apply -f- <<EOF
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: a2a-agent
      labels:
        app: a2a-agent
    spec:
      selector:
        matchLabels:
          app: a2a-agent
      template:
        metadata:
          labels:
            app: a2a-agent
        spec:
          containers:
            - name: a2a-agent
              image: gcr.io/solo-public/docs/test-a2a-agent:latest
              ports:
                - containerPort: 9090
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: a2a-agent
    spec:
      selector:
        app: a2a-agent
      type: ClusterIP
      ports:
        - protocol: TCP
          port: 9090
          targetPort: 9090
          appProtocol: kgateway.dev/a2a
    EOF
  2. エージェントを公開する Service に直接、/myagent プレフィックスパスに沿ってトラフィックをルーティングする HTTPRoute を作成します。この設定では Service に appProtocol: kgateway.dev/a2a 設定が必要であり、これにより Service への接続時に A2A プロトコルを使用するよう agentgateway が設定されます。/myagent プレフィックスパスにより、ゲートウェイ上の一意のアドレスで A2A サーバーを公開できます。ただし、A2A サーバーはルートパス(/)にトラフィックが送信される必要があるため、HTTPRoute に URLRewrite フィルターを追加して /myagent プレフィックスを / に書き換えます。

    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: a2a
    spec:
      parentRefs:
      - name: agentgateway-proxy
        namespace: agentgateway-system
      rules:
      - matches:
        - path:
            type: PathPrefix
            value: /myagent
        filters:
        - type: URLRewrite
          urlRewrite:
            path:
              type: ReplacePrefixMatch
              replacePrefixMatch: /
        backendRefs:
          - name: a2a-agent
            port: 9090
    EOF

ステップ 2: 接続を確認する

  1. agentgateway のアドレスを取得します。

    export INGRESS_GW_ADDRESS=$(kubectl get gateway agentgateway-proxy -n agentgateway-system -o=jsonpath="{.status.addresses[0].value}")
    echo $INGRESS_GW_ADDRESS
    kubectl port-forward deployment/agentgateway-proxy -n agentgateway-system 8080:80
  2. ユーザーとして A2A サーバーにリクエストを送信します。アシスタントとして、エージェントは送信したメッセージをエコーバックします。

    curl -X POST http://$INGRESS_GW_ADDRESS/myagent \
      -H "Content-Type: application/json" \
        -v \
        -d '{
      "jsonrpc": "2.0",
      "id": "1",
      "method": "tasks/send",
      "params": {
        "id": "1",
        "message": {
          "role": "user",
          "parts": [
            {
              "type": "text",
              "text": "hello gateway!"
            }
          ]
        }
      }
      }' | jq
    curl -X POST http://localhost:8080/myagent \
      -H "Content-Type: application/json" \
        -v \
        -d '{
      "jsonrpc": "2.0",
      "id": "1",
      "method": "tasks/send",
      "params": {
        "id": "1",
        "message": {
          "role": "user",
          "parts": [
            {
              "type": "text",
              "text": "hello gateway!"
            }
          ]
        }
      }
      }' | jq

    出力例:

    {
      "jsonrpc": "2.0",
      "id": "1",
      "result": {
        "id": "1",
        "message": {
          "role": "assistant",
          "parts": [
            {
              "type": "text",
              "text": "hello gateway!"
            }
          ]
        }
      }
    }

クリーンアップ

このガイドで作成したリソースを削除できます。

kubectl delete Deployment a2a-agent --ignore-not-found
kubectl delete Service a2a-agent --ignore-not-found
kubectl delete HTTPRoute a2a --ignore-not-found
kubectl delete EnterpriseAgentgatewayBackend a2a-backend --ignore-not-found