Expand description
Zentinel Agent SDK - Build proxy agents with less boilerplate.
This crate provides a high-level SDK for building Zentinel proxy agents. It wraps the low-level protocol with ergonomic types and handles common patterns like CLI parsing, logging setup, and graceful shutdown.
§Quick Start
ⓘ
use zentinel_agent_sdk::prelude::*;
struct MyAgent;
#[async_trait]
impl Agent for MyAgent {
async fn on_request(&self, request: &Request) -> Decision {
if request.path_starts_with("/admin") && request.header("x-admin-token").is_none() {
Decision::deny().with_body("Admin access required")
} else {
Decision::allow()
}
}
}
#[tokio::main]
async fn main() {
AgentRunner::new(MyAgent)
.with_name("my-agent")
.run()
.await
.unwrap();
}§V2 Protocol Support
The SDK supports the v2 agent protocol with gRPC and UDS transports:
ⓘ
use zentinel_agent_sdk::v2::{AgentRunnerV2, TransportConfig};
AgentRunnerV2::new(MyAgent)
.with_name("my-agent")
.with_uds("/tmp/my-agent.sock")
.run()
.await?;§Features
- Simplified types:
Request,Response, andDecisionprovide ergonomic APIs - Fluent decision builder: Chain methods to build complex responses
- Configuration handling: Receive config from proxy’s KDL file
- CLI support: Built-in argument parsing with clap (optional)
- Logging: Automatic tracing setup
- V2 protocol: Support for gRPC and UDS transports
§Crate Features
cli(default): Enable CLI argument parsing with clapmacros(default): Enable derive macrosv2(default): Enable v2 protocol support with AgentRunnerV2
Re-exports§
pub use serde;pub use serde_json;pub use tokio;pub use tracing;
Modules§
- decisions
- Shorthand functions for common decisions.
- prelude
- Prelude module for convenient imports.
- v2
- V2 protocol runner with gRPC and UDS support.
Structs§
- Agent
Handler - Handler adapter that bridges the simplified Agent trait to the protocol.
- Agent
Response - Agent response message
- Agent
Runner - Runner for Zentinel agents.
- Configure
Event - Configure event
- Decision
- A builder for constructing agent decisions.
- Guardrail
Detection - A single guardrail detection (prompt injection attempt, PII instance, etc.)
- Guardrail
Inspect Event - Guardrail inspection event
- Guardrail
Response - Guardrail inspection response from agent
- Request
- A simplified view of an HTTP request for agent processing.
- Request
Headers Event - Request headers event
- Request
Metadata - Request metadata sent to agents
- Response
- A simplified view of an HTTP response for agent processing.
- Response
Headers Event - Response headers event
- Runner
Config - Configuration for the agent runner.
- Text
Span - Text span indicating location in content
Enums§
- Detection
Severity - Severity level for guardrail detections
- Guardrail
Inspection Type - Type of guardrail inspection to perform
- Header
Op - Header modification operation
- Protocol
Decision - Agent decision
Traits§
- Agent
- A simplified agent trait for processing HTTP traffic.
- Configurable
Agent - A configurable agent that deserializes its configuration.
- Configurable
Agent Ext - Extension trait providing default
on_configurefor configurable agents.