Enforces strict schema validation and security policy compliance for inter-agent communication messages.
- Structural Validation: Ensure messages follow a strict envelope schema (ID, timestamp, sender, receiver, protocol, etc.).
- Payload Validation: Register custom Zod schemas for specific message types to ensure deep payload integrity.
- Security Policies: Implement powerful security policies to block prohibited commands, prevent sensitive data leaks (API keys, secrets), and enforce communication rules.
- Protocol Agnostic: Designed to handle various agent communication protocols including JSON-RPC, FIPA-ACL, and custom patterns.
- Clean API: Easy to integrate into existing agent frameworks as a middleware or standalone validation service.
- CLI Tool: Validate message files directly from the command line.
bun installimport { createValidator, DEFAULT_POLICIES } from "agent-protocol-validator";
import { z } from "zod";
// Create engine with default security policies
const engine = createValidator();
// Register a custom schema for a "trade" message
engine.registerSchema("trade", z.object({
asset: z.string(),
amount: z.number().positive(),
price: z.number().positive(),
}));
// Validate a message
const message = {
id: "550e8400-e29b-41d4-a716-446655440000",
timestamp: new Date().toISOString(),
sender: "agent-a",
receiver: "agent-b",
protocol: "json-rpc",
type: "trade",
payload: {
asset: "BTC",
amount: 0.5,
price: 60000
}
};
const result = await engine.process(message);
if (result.valid) {
console.log("Message is safe and valid!");
} else {
console.error("Validation failed:", result.errors);
}bun start validate message.jsonbun start validate message.json --verbosebun start validate message.json --policy my-policies.jsonbun start init-policy default-policy.jsonSecurity policies consist of rules that target specific parts of a message. Supported rule types include:
blacklist: Block specific values.whitelist: Allow only specific values.regex: Match patterns (e.g., secrets, prohibited strings).custom: Implement custom logic.
Example Policy:
{
"id": "p-001",
"name": "Internal Command Protection",
"enabled": true,
"severity": "critical",
"rules": [
{
"id": "r-001",
"type": "blacklist",
"target": "payload.command",
"values": ["rm", "shutdown", "reboot"],
"message": "Prohibited system command detected."
}
]
}MIT