Deploy an Agent2Agent (A2A) protocol server in Knative

Updated at:

The Agent2Agent (A2A) protocol is an open standard designed to enable seamless communication and collaboration between AI agents. Deploying an A2A server in Knative lets you take advantage of features such as automatic scaling (including scale to zero) to enable on-demand resource usage and rapid version iteration.

How it works

AI agents have inference, planning, and memory capabilities, enabling them to learn autonomously and complete tasks on behalf of users. Similar to how Model Context Protocol (MCP) provides a data access standard for large language models (LLMs), the Agent2Agent (A2A) protocol provides a standardized definition for interoperability between agents.

Deploying an A2A server in Knative involves the following core interactions:

  • Discovery: After the Service is deployed, it exposes an interface through a standard Agent Card, allowing other agents to query its skills (AgentSkill) and capabilities (AgentCapabilities).

  • Communication: Knative's gateway and Service routing (Ingress) capabilities handle standard message exchanges over HTTP/gRPC.

  • Collaboration: Agents delegate tasks and coordinate actions through APIs.

See the A2A specification for the protocol architecture of agent communication and key concepts.

Preparations

  • You have deployed Knative in the ACS cluster.

  • You have obtained the access gateway address.

    You can obtain it on the Knative Add-ons or Services page. The following example shows how to obtain it.

    At the bottom of the Service Management page, you can view the Access Gateway address, which follows a format similar to alb-<instance ID>.cn-hangzhou.alb.aliyuncsslb.com.

Step 1: Deploy the A2A server

This example deploys a basic agent Service named helloworld-agent-server.

  1. Create a2a-service.yaml.

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: helloworld-agent-server
      # Update the namespace as needed
      namespace: default 
      annotations:
        # Use a wildcard domain name for quick verification
        knative.aliyun.com/serving-ingress: / 
    spec:
      template:
        spec:
          containers:
          # Replace {region} with the actual region, such as cn-hangzhou
          - image: registry-{region}-vpc.ack.aliyuncs.com/acs/knative-samples-a2a:v1.0-952c112
            name: user-container
            env:
            # INVOKE defines the invoke URL returned in the Agent Card. Replace it with the service access gateway address.
            - name: INVOKE
              value: http://<YOUR_GATEWAY_ADDRESS>/invoke
            ports:
            - containerPort: 9001
              name: http1
              protocol: TCP
  2. Deploy the Service.

    kubectl apply -f a2a-service.yaml
  3. Check the Knative Service status.

    kubectl get ksvc helloworld-agent-server

    Expected output:

    NAME                      URL                                                  LATESTCREATED                   LATESTREADY                     READY   REASON
    helloworld-agent-server   http://helloworld-agent-server.default.example.com   helloworld-agent-server-00001   helloworld-agent-server-00001   True    

Step 2: Verify the Service and retrieve the Agent Card

After deployment, verify that the Service correctly returns an Agent Card that complies with the A2A protocol.

  1. Obtain the access gateway address and the default domain name of the Service.

    1. Log on to the ACS console. In the left navigation pane, click Clusters.

    2. On the Clusters page, click the name of the target cluster. In the left navigation pane, choose Applications > Knative.

    3. On the Services page, obtain the Service Default Domain.

      The following example shows the Gateway and the Default Domain.

      The access gateway address follows the format alb-<instance ID>.cn-hangzhou.alb.aliyuncsslb.com. The helloworld-agent-server Service is in the successful state, and its default domain name is helloworld-agent-server.default.example.com.

  2. Access the Service metadata endpoint.

    # Replace <GATEWAY_ADDRESS> with the access gateway address that you obtained
    curl http://<GATEWAY_ADDRESS>/.well-known/agent-card.json | jq .

    Review the expected output.
    It must include the agent capabilities (capabilities), description (description), and skill list (skills).

    {
      "capabilities": {
        "streaming": true
      },
      "defaultInputModes": [
        "text"
      ],
      "defaultOutputModes": [
        "text"
      ],
      "description": "Just a hello world agent",
      "name": "Hello World Agent",
      "preferredTransport": "JSONRPC",
      "protocolVersion": "",
      "skills": [
        {
          "description": "Returns a 'Hello, world!'",
          "examples": [
            "hi",
            "hello"
          ],
          "id": "hello_world",
          "name": "Hello, world!",
          "tags": [
            "hello world"
          ]
        }
      ],
      "url": "http://XXX/invoke",
      "version": ""
    }

Step 3: Call the Service by using an A2A client

Write client code in Go to simulate another agent communicating with the deployed A2A server.

  1. Prepare the development environment and install Go.

  2. Create the main.go file and add the following code.

    package main
    import (
    	"context"
    	"flag"
    	"log"
    	// Import the core libraries for the A2A protocol
    	"github.com/a2aproject/a2a-go/a2a"
    	"github.com/a2aproject/a2a-go/a2aclient"
    	"github.com/a2aproject/a2a-go/a2aclient/agentcard"
    	// Import gRPC-related libraries
    	"google.golang.org/grpc"
    	"google.golang.org/grpc/credentials/insecure"
    )
    // Replace <GATEWAY_ADDRESS> with the access gateway address that you obtained
    var cardURL = flag.String("card-url", "http://<GATEWAY_ADDRESS>", "Base URL of AgentCard client.")
    func main() {
    	flag.Parse()
    	ctx := context.Background()
    	// Service discovery
    	card, err := agentcard.DefaultResolver.Resolve(ctx, *cardURL)
    	if err != nil {
    		log.Fatalf("Failed to resolve an AgentCard: %v", err)
    	}
    	// Configure the transport layer
    	withInsecureGRPC := a2aclient.WithGRPCTransport(grpc.WithTransportCredentials(insecure.NewCredentials()))
    	// Create the client
    	client, err := a2aclient.NewFromCard(ctx, card, withInsecureGRPC)
    	if err != nil {
    		log.Fatalf("Failed to create a client: %v", err)
    	}
    	// Build the message
    	msg := a2a.NewMessage(a2a.MessageRoleUser, a2a.TextPart{Text: "Hello, world"})
    	resp, err := client.SendMessage(ctx, &a2a.MessageSendParams{Message: msg})
    	if err != nil {
    		log.Fatalf("Failed to send a message: %v", err)
    	}
    	log.Printf("Server responded with: %+v", resp)
    }
  3. Run the code to test it.

    go mod init a2a-demo
    go mod tidy
    go run main.go

    The following expected output indicates that the client successfully connected to the Knative Service, and the server completed processing and returned a response.

    2025/11/27 17:24:21 Server responded with: &{ID:019ac4a0-c386-7cdc-9aad-d40fb8f98ae2 ContextID: Extensions:[] Metadata:map[] Parts:[{Text:Hello, world! Metadata:map[]}] ReferenceTasks:[] Role:agent TaskID:}

Recommendations for production environments

  • Custom domain name and HTTPS: Do not use a test domain name directly in a production environment. Configure a custom domain name and enable an HTTPS certificate to secure communication between agents.

  • Optimization for cold start: If agents are called infrequently, Knative scales instances to zero. To prevent cold start latency on the first request from affecting the interaction experience, you can configure the minimum number of instances (MinScale) .

Billing

The Knative add-on itself does not incur additional charges. However, each cloud product charges for the compute resources, network resources, and other resources that you consume. For more information, see Billing overview.