Agents

Agents are the primary extension mechanism for Zentinel. They allow you to add custom logic, security policies, and integrations without modifying the core proxy.

Protocol

Zentinel uses the v2 agent protocol for all agent communication:

FeatureDetails
TransportsUDS (binary), gRPC, Reverse Connections
Connection PoolingMultiple connections per agent with load balancing (4 strategies)
StreamingFull bidirectional streaming support
ObservabilityBuilt-in metrics export in Prometheus format
Config PushDynamic configuration updates
Health TrackingComprehensive health checks
Flow ControlBackpressure support
Request CancellationCancel in-flight requests when clients disconnect

See the v2 protocol documentation for full details.


What Are Agents?

Agents are external processes that communicate with Zentinel over a well-defined protocol. When a request flows through Zentinel, configured agents receive events at key lifecycle points and can:

  • Inspect request/response headers and bodies
  • Modify headers, routing metadata, and more
  • Decide to allow, block, redirect, or challenge requests
  • Log audit information for observability
┌───────────────────────────────────────────────────────────────────────────┐
│                             Zentinel Proxy                                 │
│  ┌─────────────────────────────────────────────────────────────────────┐  │
│  │                          Agent Manager                               │  │
│  │  ┌───────────┐  ┌───────────┐  ┌───────────┐  ┌───────────┐        │  │
│  │  │   Auth    │  │ RateLimit │  │    WAF    │  │  Policy   │        │  │
│  │  │  Client   │  │  Client   │  │  Client   │  │  Client   │        │  │
│  │  └─────┬─────┘  └─────┬─────┘  └─────┬─────┘  └─────┬─────┘        │  │
│  └────────┼──────────────┼──────────────┼──────────────┼──────────────┘  │
└───────────┼──────────────┼──────────────┼──────────────┼─────────────────┘
            │              │              │              │
            ▼              ▼              ▼              ▼
     ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐
     │ Auth Agent │ │ RateLimit  │ │ WAF Agent  │ │  Policy    │
     │  (local)   │ │   Agent    │ │  (remote)  │ │  Agent     │
     └────────────┘ └────────────┘ └────────────┘ └────────────┘
          UDS           gRPC           gRPC         Reverse

Why External Agents?

Zentinel’s architecture keeps the dataplane minimal and predictable:

BenefitDescription
IsolationA buggy or crashing agent cannot take down the proxy
Independent DeploymentUpdate agents without restarting Zentinel
Language FlexibilityWrite agents in any language with gRPC or Unix socket support
Circuit BreakersZentinel protects itself from slow or failing agents
Horizontal ScalingRun agents as separate services for high availability

Transport Options

Agents can communicate with Zentinel via multiple transports:

TransportProtocolBest For
Unix SocketBinary + JSONLocal agents, lowest latency
gRPCProtocol Buffers over HTTP/2High throughput, streaming, remote
Reverse ConnectionBinaryNAT traversal, dynamic scaling

Quick Configuration Example

agents {
    // Unix socket agent with pooling
    agent "auth-agent" type="auth" {
        unix-socket "/var/run/zentinel/auth.sock"
        connections 4
        events "request_headers"
        timeout-ms 100
        failure-mode "closed"
    }

    // gRPC agent
    agent "waf-agent" type="waf" {
        grpc "http://localhost:50051"
        connections 4
        events "request_headers" "request_body"
        timeout-ms 200
        failure-mode "open"
        circuit-breaker {
            failure-threshold 5
            timeout-seconds 30
        }
    }
}

// Reverse connection listener
reverse-listener {
    path "/var/run/zentinel/agents.sock"
    max-connections-per-agent 4
    handshake-timeout "10s"
}

routes {
    route "api" {
        matches { path-prefix "/api/" }
        upstream "backend"
        agents "auth-agent" "waf-agent"
    }
}

Building Your Own Agent

The easiest way to build a custom agent is with the Zentinel Agent SDK:

use zentinel_agent_protocol::v2::{AgentPool, AgentPoolConfig};

let pool = AgentPool::new();
pool.add_agent("my-agent", "/var/run/my-agent.sock").await?;

let response = pool.send_request_headers("my-agent", &headers).await?;

The SDK provides ergonomic wrappers around the protocol, handling connection management, health tracking, and metrics automatically.

Documentation

Protocol Reference

PageDescription
Protocol SpecificationWire protocol, message types, streaming
API ReferenceAgentPool, client, and server APIs
Connection PoolingLoad balancing and circuit breakers
Transport OptionsgRPC, UDS, and Reverse comparison
Reverse ConnectionsNAT traversal setup

Legacy (Removed)

PageDescription
Protocol v1Historical v1 documentation (removed in 26.02_18)

Protocol v2 (Current)

Protocol v1 (Removed)