Skip to content

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. 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
    EOF
  4. Save the agentgateway Gateway service address in an environment variable.

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

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, 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.