Skip to content
kagent 1.0 is available as an alpha release. To read its documentation, see the 1.x docs.

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

Agentgateway

Page as Markdown

Configure an agentgateway deployment as a model endpoint for kagent.

You can route model requests through an agentgateway deployment. Agentgateway is an AI-native proxy that provides traffic management, observability, and security for LLM calls. Because agentgateway exposes an OpenAI-compatible API, you configure the ModelConfig with provider: OpenAI and set openAI.baseUrl to your agentgateway Gateway service address.

Set up agentgateway model routing

Note

The AgentgatewayModel feature is experimental and disabled by default. You must enable it when you install agentgateway by passing --set agentgatewayModels.enabled=true to the control plane Helm chart.

  1. Install agentgateway in your cluster. For more information, see the agentgateway documentation. Add --set agentgatewayModels.enabled=true to the Helm command for the agentgateway control plane.

  2. Create a Gateway resource for model routing.

    kubectl apply -f - <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: agentgateway-proxy
      namespace: agentgateway-system
    spec:
      gatewayClassName: agentgateway
      listeners:
      - name: http
        protocol: HTTP
        port: 80
        allowedRoutes:
          namespaces:
            from: All
          kinds:
          - group: gateway.networking.k8s.io
            kind: HTTPRoute
          - group: agentgateway.dev
            kind: AgentgatewayModel
    EOF
  3. Store the provider credentials that agentgateway uses to call the model. Agentgateway authenticates to the provider on your agents’ behalf, so this key belongs to the gateway rather than to kagent. The value is read from the Secret’s Authorization key by default.

    kubectl create secret generic openai-key -n agentgateway-system \
      --from-file=Authorization=<path-to-a-file-holding-your-api-key>
  4. Create an AgentgatewayModel resource for each model that you want kagent to access. The resource name becomes the model name that kagent sends in requests, so it must match spec.model in the kagent ModelConfig. The following example routes requests for gpt-4o-mini to the OpenAI provider. For more provider options and authentication configuration, see the agentgateway model documentation.

    kubectl apply -f - <<EOF
    apiVersion: agentgateway.dev/v1alpha1
    kind: AgentgatewayModel
    metadata:
      name: gpt-4o-mini
      namespace: agentgateway-system
    spec:
      parentRefs:
      - group: gateway.networking.k8s.io
        kind: Gateway
        name: agentgateway-proxy
        sectionName: http
      provider: OpenAI
      policies:
        auth:
          secretRef:
            name: openai-key
    EOF

    Note

    policies.auth gives the gateway the credentials that it needs to reach the provider. A model with no auth is still accepted and programmed, and every request through it returns the provider’s own 401, because agentgateway forwards the call with no credentials.

  5. Save the agentgateway Gateway service address in an environment variable. The /v1 suffix is required: kagent appends /chat/completions to this value, and agentgateway serves that endpoint at /v1/chat/completions. Without the suffix, every model call returns 404 Not Found.

    export AGENTGATEWAY_URL=http://agentgateway-proxy.agentgateway-system.svc.cluster.local/v1

Connect to an agentgateway endpoint

  1. Create a ModelConfig resource. Choose the tab that matches your agentgateway authentication configuration.

    If your agentgateway deployment does not enforce any API key authentication, apply the following ModelConfig.

    kubectl apply -f - <<EOF
    apiVersion: kagent.dev/v1alpha2
    kind: ModelConfig
    metadata:
      name: agentgateway-model
      namespace: kagent
    spec:
      provider: OpenAI
      model: gpt-4o-mini
      openAI:
        baseUrl: "$AGENTGATEWAY_URL"
    EOF

    Review the following table to understand this configuration. For more information, see the API docs.

    SettingDescription
    providerSet to OpenAI, because agentgateway exposes an OpenAI-compatible API.
    modelThe model name to request from agentgateway. This value must match the name of an AgentgatewayModel resource in your agentgateway deployment.
    openAI.baseUrlThe Kubernetes service address of your agentgateway Gateway, including the /v1 path, set in $AGENTGATEWAY_URL.
  2. Verify that the ModelConfig is accepted.

    kubectl get modelconfig agentgateway-model -n kagent -o yaml

Agentgateway is now added as a model endpoint in kagent. Next, you can create or update an agent to use this model.