Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

5.5 KB
Raw Blame
# Envoy in front of a model provider, with beacon-gateway as its External Processing (ext_proc)
# server. Clients send their model calls to :10000; Envoy passes each exchange through
# beacon-gateway (gRPC on :4021), which records it.
#
# Validate:  docker run --rm -v $PWD/deploy/envoy:/cfg envoyproxy/envoy:v1.37-latest --mode validate -c /cfg/envoy.yaml
# Run:       docker run --rm -p 10000:10000 -v $PWD/deploy/envoy:/cfg envoyproxy/envoy:v1.37-latest -c /cfg/envoy.yaml
#
# This configuration observes: replies stream to the client as they arrive, and a gateway that is
# down or slow lets calls through.
#
#   BUFFERED  Envoy holds the whole body and sends it in one message, then forwards it once
#             beacon-gateway answers. Used for requests, which arrive whole anyway.
#   STREAMED  Envoy sends each chunk and forwards it as soon as beacon-gateway answers, which it does
#             at once. Used for replies, so streaming (SSE) keeps its token-by-token latency;
#             beacon-gateway assembles the chunks and records the reply when it ends.
#
# beacon-gateway tells the two apart by what arrives; no setting on its side has to match.

admin:
  address:
    socket_address: { address: 127.0.0.1, port_value: 9901 }

static_resources:
  listeners:
    - name: models
      address:
        socket_address: { address: 0.0.0.0, port_value: 10000 }
      # BUFFERED bodies must fit Envoy's buffers (default 1MiB); 32MiB matches beacon-gateway's
      # default max_body and long agent conversations.
      per_connection_buffer_limit_bytes: 33554432
      filter_chains:
        - filters:
            - name: envoy.filters.network.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
                stat_prefix: models
                # Appends the client's address to x-forwarded-for, which beacon-gateway records.
                use_remote_address: true
                route_config:
                  name: models
                  virtual_hosts:
                    - name: provider
                      domains: ["*"]
                      routes:
                        - match: { prefix: "/" }
                          route:
                            cluster: provider
                            # Long generations outlast Envoy's 15s default route timeout.
                            timeout: 600s
                            # For a real provider, rewrite Host to the provider's name:
                            # auto_host_rewrite: true
                http_filters:
                  - name: envoy.filters.http.ext_proc
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.ext_proc.v3.ExternalProcessor
                      grpc_service:
                        envoy_grpc: { cluster_name: beacon_gateway }
                      # The 200ms default leaves no room for a large conversation.
                      message_timeout: 2s
                      # If beacon-gateway is down or slow, calls pass through unrecorded rather than
                      # fail.
                      failure_mode_allow: true
                      processing_mode:
                        request_header_mode: SEND
                        response_header_mode: SEND
                        request_body_mode: BUFFERED
                        response_body_mode: STREAMED
                        request_trailer_mode: SKIP
                        response_trailer_mode: SKIP
                  - name: envoy.filters.http.router
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

  clusters:
    # The model provider. For the smoke test it is a plain-HTTP upstream on the Docker host. For a
    # real provider, point it at the provider over TLS and set auto_host_rewrite on the route:
    #
    #   load_assignment:
    #     cluster_name: provider
    #     endpoints:
    #       - lb_endpoints:
    #           - endpoint:
    #               address:
    #                 socket_address: { address: api.anthropic.com, port_value: 443 }  # or api.openai.com
    #   transport_socket:
    #     name: envoy.transport_sockets.tls
    #     typed_config:
    #       "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
    #       sni: api.anthropic.com  # or api.openai.com
    - name: provider
      type: STRICT_DNS
      connect_timeout: 5s
      dns_lookup_family: V4_ONLY
      per_connection_buffer_limit_bytes: 33554432
      load_assignment:
        cluster_name: provider
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address: { address: host.docker.internal, port_value: 4020 }

    # beacon-gateway's ext_proc server; gRPC needs HTTP/2.
    - name: beacon_gateway
      type: STRICT_DNS
      connect_timeout: 1s
      dns_lookup_family: V4_ONLY
      per_connection_buffer_limit_bytes: 33554432
      typed_extension_protocol_options:
        envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
          "@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
          explicit_http_config:
            http2_protocol_options: {}
      load_assignment:
        cluster_name: beacon_gateway
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address: { address: host.docker.internal, port_value: 4021 }