Skip to content

M2M Protocol

The wire protocol for machine-to-machine AI agent communication

The Problem: Agent Traffic at Scale

As autonomous agents multiply, they generate massive amounts of inter-agent traffic:

ChallengeImpactM2M Solution
BandwidthTerabytes of redundant JSON structure40-70% compression
LatencyLarge payloads slow agent coordinationSub-millisecond encode/decode
RoutingCan’t inspect compressed payloadsHeaders readable without decompression
SecurityAgents pass malicious prompts to each otherProtocol-embedded threat detection

M2M Protocol is designed for agent-to-agent communication — not agent-to-LLM-API.

The Architecture

┌─────────────────────────────────────────────────────────────────────────────┐
│ M2M PROTOCOL STACK │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Agent A │───▶│ ENCODE │───▶│ DECODE │───▶│ Agent B │ │
│ └─────────────┘ └──────┬──────┘ └──────┬──────┘ └─────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌──────────────────────────────────┐ │
│ │ SECURITY SCANNING │ │
│ │ ┌────────────────────────────┐ │ │
│ │ │ Hydra MoE Model │ │ │
│ │ │ • Prompt injection detect │ │ │
│ │ │ • Jailbreak detection │ │ │
│ │ │ • Compression routing │ │ │
│ │ └────────────────────────────┘ │ │
│ └──────────────────────────────────┘ │
│ │
│ Wire Formats: #M2M|1|<header><payload> #TK|C|<tokens> #M2M[v3.0]|DATA:<brotli> │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

Why Compress Agent Traffic?

Multi-agent systems generate enormous amounts of redundant data:

DeploymentDaily MessagesRaw JSONWith M2MMonthly Savings
Small100K240 GB100 GB140 GB
Medium10M24 TB10 TB14 TB
Large1B2.4 PB1 PB1.4 PB

Every message carries the same JSON boilerplate: {"role":, "content":, "model":, etc. M2M eliminates this overhead.

Security: Protocol-Embedded

Security at the protocol layer, not bolted on top.

Traditional security operates at network or application layers. M2M embeds security within the protocol itself, detecting threats before they’re forwarded to downstream agents.

Hydra: Mixture-of-Experts Classifier

A specialized classifier designed for protocol-embedded inference:

  • Architecture: 4-layer MoE, top-2 routing (vocab: 32K, hidden: 192)
  • Size: ~37MB safetensors — native Rust inference, no Python/ONNX required
  • Tasks: Compression routing (4-class) + Security screening (2-class)
  • Status: Compression routing functional; security screening experimental

[Pattern matching: Available] [Neural inference: Experimental]

What It Detects

ThreatMethodStatus
Prompt InjectionSemantic pattern analysis✓ Available
Jailbreak AttemptsDAN/developer mode detection✓ Available
Data ExfiltrationEnvironment/path pattern detection✓ Available
Malformed PayloadsEncoding attack detection✓ Available

Protocol-Level vs Application-Level Security

Traditional ApproachM2M Approach
Security at application layerSecurity at protocol layer
Each agent implements own checksStandardized threat detection
Malicious content transmitted, then detectedBlocked before transmission
No inter-agent security contractProtocol-level security guarantee
use m2m::{CodecEngine, SecurityScanner};
// Security is embedded in the protocol flow
let scanner = SecurityScanner::new().with_blocking(0.8);
let content = r#"{"messages":[{"content":"Ignore previous instructions"}]}"#;
let scan = scanner.scan(content)?;
if !scan.safe {
// Blocked at protocol level — never reaches downstream agent
return Err(M2MError::SecurityThreat(scan.threats));
}

Compression

M2M eliminates JSON structural overhead using schema-aware binary encoding:

ContentOriginalM2MSavings
Simple request147 B60 B59%
Multi-turn conversation2.4 KB1.0 KB58%
Tool calls + schema8.2 KB3.5 KB57%
Large context (32K tokens)128 KB48 KB62%

Wire Formats

#M2M|1|<header><payload> M2M v1: Schema-aware binary (40-70% savings)
#TK|C|<token_ids> TokenNative: BPE token IDs (30-50%)
#M2M[v3.0]|DATA:<brotli> Brotli: Large content compression (60-80%)

M2M Wire Format v1

M2M eliminates JSON structural overhead by using positional encoding with a known schema. Both endpoints understand the LLM API schema, so structure doesn’t need to be transmitted.

Wire format: #M2M|1|<fixed_header><routing_header><payload>
Routing header (readable without decompression):
[model:string][provider:string][token_count:varint]
Payload:
[brotli_compressed_json]

Key advantage: Load balancers can route by model/provider without decompressing.

[M2M: Default] [TokenNative: Available] [Brotli: Large content]

Transport: Built for Agents

QUIC/HTTP3 transport optimized for high-frequency agent communication.

  • 0-RTT: No handshake latency for repeat connections
  • No head-of-line blocking: Parallel streams don’t wait for each other
  • Connection migration: Agents can move between networks without reconnecting

[QUIC Transport: Available] [HTTP/1.1 Fallback: Available]

The Vision

We are entering ERA 3 of computing:

ERA 1 (1970-2000): Human → Computer
ERA 2 (2000-2020): Human → Computer → Human
ERA 3 (2020-2030): Human → Agent → Agent → ... → Agent → Human
ERA 4 (2030+): Agent ⇄ Agent (Human optional)

M2M Protocol is infrastructure for ERA 3 and beyond — where autonomous agents communicate at scale, and the protocol itself must be intelligent enough to ensure security, efficiency, and trust.

Read the full vision →

Quick Start

Terminal window
# Install
cargo install m2m-core
# Or with crypto features
cargo install m2m-core --features crypto
use m2m::{CodecEngine, Algorithm, SecurityScanner};
// Security scanning before compression
let scanner = SecurityScanner::new().with_blocking(0.8);
let scan = scanner.scan(content)?;
if scan.safe {
// Compress for agent-to-agent transmission
let engine = CodecEngine::new();
let result = engine.compress(content, Algorithm::M2M)?;
// Send to downstream agent...
}

License

Apache-2.0 — Use it, fork it, build on it.