全部产品
Search
文档中心

Container Service for Kubernetes:Bangun agen Tanya & Jawab dengan Kagent di ACK

更新时间:Dec 17, 2025

Panduan ini menjelaskan cara menerapkan agen Question & Answer (Tanya & Jawab) menggunakan Kagent. Agen tersebut memanfaatkan model qwen3-coder-plus dari Alibaba Cloud Model Studio dan layanan Model Context Protocol (MCP) fetch untuk mengambil serta merangkum konten halaman web secara real time.

Persiapan

  1. Buat namespace bernama kagent di kluster ACK Anda.

  2. Pasang aplikasi kagent-crds dan kagent di namespace kagent melalui Marketplace ACK atau menggunakan Applications > Helm.

  3. Aktifkan Alibaba Cloud Model Studio dan buat kunci API.

Langkah 1: Buat ModelConfig

  1. Dapatkan KubeConfig kluster Anda dan gunakan kubectl untuk terhubung ke kluster. Jika kluster Anda tidak memiliki akses jaringan publik yang diaktifkan, Anda dapat menggunakan Workbench untuk terhubung ke kluster melalui jaringan internal. Di halaman Cluster Information, klik Manage Clusters Using Workbench di pojok kanan atas.

  2. Ekspor kunci API Model Studio Anda sebagai variabel lingkungan dan buat Secret di namespace kagent.

    export PROVIDER_API_KEY=${Your_Model_Studio_API_Key}
    kubectl create secret generic bailian-apikey -n kagent --from-literal credential="$PROVIDER_API_KEY"
  3. Terapkan YAML berikut untuk membuat resource ModelConfig. Provider diatur ke OpenAI karena Model Studio menyediakan API yang kompatibel dengan OpenAI.

    kubectl -n kagent apply -f - <<EOF
    apiVersion: kagent.dev/v1alpha2
    kind: ModelConfig
    metadata:
      name: bailian-provider-config
    spec:
      model: qwen3-coder-plus
      apiKeySecret: bailian-apikey
      apiKeySecretKey: credential
      openAI:
        baseUrl: https://dashscope-intl.aliyuncs.com/compatible-mode/v1
      provider: OpenAI
    EOF

Langkah 2: Terapkan server MCP fetch

  1. Terapkan server MCP fetch di kluster ACK Anda.

    kubectl -n kagent apply -f - <<EOF
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: streamablehttp-fetch-deployment
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: streamablehttp-fetch
      template:
        metadata:
          labels:
            app: streamablehttp-fetch
        spec:
          containers:
          - name: streamablehttp-fetch-container
            image: registry-cn-hangzhou.ack.aliyuncs.com/dev/streamablehttp-fetch:latest
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: streamablehttp-fetch-service
    spec:
      selector:
        app: streamablehttp-fetch
      ports:
        - protocol: TCP
          port: 3000
          targetPort: 3000
      type: ClusterIP
    EOF

Langkah 3: Daftarkan Server MCP

  1. Buat resource RemoteMCPServer untuk mendaftarkan layanan fetch ke Kagent. Resource ini memberi tahu sistem cara berkomunikasi dengan server MCP yang diterapkan pada langkah sebelumnya.

    kubectl -n kagent apply -f - <<EOF
    apiVersion: kagent.dev/v1alpha2
    kind: RemoteMCPServer
    metadata:
      name: streamablehttp-fetch
    spec:
      description: A Model Context Protocol server that provides web content fetching capabilities. This server enables LLMs to retrieve and process content from web pages, converting HTML to Markdown for easier consumption.
      protocol: STREAMABLE_HTTP
      sseReadTimeout: 5m0s
      terminateOnClose: true
      timeout: 30s
      url: http://streamablehttp-fetch-service:3000/
    EOF
  2. Verifikasi bahwa server MCP berhasil didaftarkan dan diterima.

    kubectl get RemoteMCPServer -n kagent

    Output yang diharapkan:

    NAME                   PROTOCOL          URL                                        ACCEPTED
    streamablehttp-fetch   STREAMABLE_HTTP   http://streamablehttp-fetch-service:3000/   True

Langkah 4: Buat agen

  1. Terapkan konfigurasi Agent.

    kubectl -n kagent apply -f - <<EOF
    apiVersion: kagent.dev/v1alpha2
    kind: Agent
    metadata:
      name: gateway-api-professor
      namespace: kagent
    spec:
      declarative:
        modelConfig: bailian-provider-config
        stream: true
        systemMessage: |-
          You are a friendly and helpful agent. Use the streamablehttp-fetch tool to get GatewayAPI information from the following URLs to answer user questions about GatewayAPI.
          
          # Links
          - intro: https://gateway-api.sigs.k8s.io/
          - api-overview: https://gateway-api.sigs.k8s.io/concepts/api-overview/
          - use-case: https://gateway-api.sigs.k8s.io/concepts/use-cases/
          - servicemesh: https://gateway-api.sigs.k8s.io/mesh/
          - implementations: https://gateway-api.sigs.k8s.io/implementations/
          - v1.4 support overview: https://gateway-api.sigs.k8s.io/implementations/v1.4/
          - Full spec, large page: https://gateway-api.sigs.k8s.io/reference/spec/
    
          # Instructions
    
          - If a user's question is unclear, ask for clarification before running any tools.
          - Be friendly and enthusiastic in your responses to the user.
          - If you do not know how to answer a question, do not make up an answer.
            Reply with "Sorry, I don't know how to answer that question" and ask the user to clarify.
          - If the user asks for a summary or an overview, make sure to read the entire text before answering.
    
          # Response format
          - Always reply in Markdown format.
          - Your response must include a summary of the actions you performed and an explanation of the results.
        tools:
        - type: McpServer
          mcpServer:
            apiGroup: kagent.dev
            kind: RemoteMCPServer
            name: streamablehttp-fetch
            toolNames:
            - fetch
      description: This agent primarily answers questions related to the GatewayAPI specification.
      type: Declarative
    EOF
  2. Verifikasi bahwa agen dan komponen dependennya sedang berjalan.

    kubectl get pod -n kagent

    Output yang diharapkan:

    NAME                                              READY   STATUS    RESTARTS   AGE
    gateway-api-professor-7cb6496b9d-l7nlj            1/1     Running   0          3m1s
    kagent-controller-794fc765df-hqswt                1/1     Running   0          45m
    kagent-ui-569cb875c6-h55mg                        1/1     Running   0          45m
    streamablehttp-fetch-deployment-75d5cd86cf-h9rvp   1/1     Running   0          4m3s

Langkah 5: Akses agen

Kagent menyertakan antarmuka Web UI bawaan untuk berinteraksi dengan agen.

  1. Gunakan penerusan port untuk mengekspos layanan kagent-ui ke mesin lokal Anda.

    kubectl port-forward -n kagent service/kagent-ui 8082:8080
  2. Buka browser Anda dan arahkan ke http://localhost:8082.

    1. Contoh interaksi 1: Apa saja API yang ada dalam Gateway API?

      image

      image

    2. Contoh interaksi 2: Implementasi mana yang saat ini memiliki dukungan fitur Gateway API paling lengkap?

      image

      image