6 min read

VEX Protocol Architecture#

Overview#

VEX (Verified Evolutionary Xenogenesis) is the Cognitive Layer of the ProvnAI "Immune System for AI". It is a multi-layered Rust framework for building adversarial, temporal, and cryptographically-verified AI agents.

Code
┌─────────────────────────────────────────────────────────────┐
│                     Gateway Layer                           │
│  ┌─────────────────────────────────────────────────────────┐│
│  │ vex-api: Axum HTTP + JWT + Rate Limiting + Circuit Break││
│  └─────────────────────────────────────────────────────────┘│
├─────────────────────────────────────────────────────────────┤
│                   Intelligence Layer                        │
│  ┌───────────────────────┐  ┌─────────────────────────────┐│
│  │ vex-llm               │  │ vex-adversarial             ││
│  │ DeepSeek/OpenAI/Ollama│  │ Red/Blue Debate Engine      ││
│  └───────────────────────┘  └─────────────────────────────┘│
├─────────────────────────────────────────────────────────────┤
│                    Execution Layer                          │
│  ┌───────────────────────┐  ┌─────────────────────────────┐│
│  │ vex-runtime           │  │ vex-queue                   ││
│  │ Orchestrator + Executor│  │ Async Worker Pool          ││
│  └───────────────────────┘  └─────────────────────────────┘│
├─────────────────────────────────────────────────────────────┤
│                      Core Layer                             │
│  ┌───────────────────────┐  ┌─────────────────────────────┐│
│  │ vex-core              │  │ vex-temporal                ││
│  │ Agent + Genome + Merkle│  │ Episodic Memory + Decay    ││
│  └───────────────────────┘  └─────────────────────────────┘│
├─────────────────────────────────────────────────────────────┤
│                   Persistence Layer                         │
│  ┌─────────────────────────────────────────────────────────┐│
│  │ vex-persist: SQLite + Migrations + Audit Logs          ││
│  │ Semantic VectorStore + Job Result Persistence           ││
│  └─────────────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────┘

Data Flow#

Code
User Request
     │
     ▼
┌─────────────┐
│  vex-api    │──── JWT Auth ──── Rate Limit ──── Circuit Breaker
└─────────────┘
     │
     ▼
┌─────────────┐
│ vex-runtime │ Orchestrator creates agent hierarchy
└─────────────┘
     │
     ├──────────────────────────────────┐
     ▼                                  ▼
┌─────────────┐                  ┌─────────────┐
│ Blue Agent  │◄───── Debate ────│ Red Shadow  │
│ (Primary)   │                  │ (Challenger)│
└─────────────┘                  └─────────────┘
     │                                  │
     ▼                                  ▼
┌─────────────┐                  ┌─────────────┐
│  vex-llm    │                  │ Pattern     │
│  Provider   │                  │ Heuristics  │
└─────────────┘                  └─────────────┘
     │                                  │
     └──────────────┬───────────────────┘
                    ▼
             ┌─────────────┐
             │  Consensus  │ Voting Protocol
             └─────────────┘
                    │
                    ▼
             ┌─────────────┐
             │ Merkle Tree │ Hash Chain
             └─────────────┘
                    │
                    ▼
             ┌─────────────┐
             │ vex-persist │ Audit Log
             └─────────────┘

Key Components#

Agent (vex-core)

Rust
Agent {
    id: Uuid,
    parent_id: Option<Uuid>,
    config: AgentConfig,
    genome: Genome,
    generation: u32,
    fitness: f64,
}

Genome#

Five behavioral traits that map to LLM parameters:

TraitLLM ParameterRange
explorationtemperature0.1 - 1.5
precisiontop_p0.5 - 1.0
creativitypresence_penalty0.0 - 1.0
skepticismfrequency_penalty0.0 - 0.5
verbositymax_tokens0.5x - 2.0x

Consensus Protocols#

ProtocolThresholdUse Case
Majority>50%Quick decisions
SuperMajority≥67%Important decisions
Unanimous100%Critical decisions
WeightedConfidenceWeighted avg ≥0.7Nuanced decisions

Memory Horizons#

HorizonDurationmax_entries
Immediate5 min10
ShortTerm1 hour25
MediumTerm24 hours50
LongTerm1 week100
Permanent500

Self-Correcting Evolution (New)#

Code
┌─────────────────┐
│ Agent Execution │
└────────┬────────┘
         │ Records experiment
         ▼
┌─────────────────┐     ┌──────────────────┐
│ EvolutionMemory │────▶│ Pearson Correlat.│
│ (Episodic)      │     │ (Statistical)    │
└────────┬────────┘     └──────────────────┘
         │ Batch (70+ items)
         ▼
┌─────────────────┐     ┌──────────────────┐
│ ReflectionAgent │────▶│ OptimizationRules│
│ (LLM Analysis)  │     │ (Semantic)       │
└─────────────────┘     └──────────────────┘
                               │
                               ▼ Persistent
                        ┌──────────────────┐
                        │ SQLite           │
                        │ optimization_rules│
                        └──────────────────┘
ComponentPurpose
EvolutionMemoryStores experiments with importance decay
ReflectionAgentLLM + statistical analysis for suggestions
OptimizationRuleSemantic lessons extracted from experiments
EvolutionStorePersistent storage for cross-session learning

Security Model#

  1. Authentication:

    • JWT tokens with role-based claims (vex-api)
    • Secure secret handling with zeroize memory clearing
    • API keys hashed with Argon2id (salted)
  2. Input Sanitization:

    • 50+ Prompt Injection Patterns blocked (DAN, Policy Puppetry, etc.)
    • Unicode normalization (homoglyph attack prevention)
    • JSON depth limiting (DoS prevention)
  3. Resilience:

    • 3-state Circuit Breaker (Closed → Open → HalfOpen)
    • Rate Limiting: Per-user tier-based limits
    • Integer Overflow Checks: Enabled in release profile
  4. Audit Trail:

    • Cryptographic hash chaining (SHA-256)
    • Sensitive field redaction (logs sanitized of secrets)
  5. Network:

    • HSTS allowed (Strict-Transport-Security)
    • Strict CORS configuration via environment

Tool System (vex-llm)

Cryptographically-verified tool execution with Merkle audit integration.

Code
┌─────────────────────────────────────────────────────────────┐
│                    Tool Execution Flow                       │
├─────────────────────────────────────────────────────────────┤
│  ToolExecutor                                                │
│  ├── Validate(args)      // Schema + length checks           │
│  ├── Execute(timeout)    // With DoS protection              │
│  ├── Hash(result)        // SHA-256 for Merkle chain         │
│  └── Audit(log)          // To AuditStore                    │
├─────────────────────────────────────────────────────────────┤
│  ToolRegistry                                                │
│  • O(1) lookup by name                                       │
│  • Collision detection (no duplicates)                       │
│  • OpenAI/Anthropic format export                            │
├─────────────────────────────────────────────────────────────┤
│  Built-in Tools                                              │
│  calculator | datetime | uuid | hash | regex | json_path     │
└─────────────────────────────────────────────────────────────┘

Capability System (for future WASM sandboxing):

CapabilityDescription
PureComputationNo I/O, safe for WASM isolation
NetworkRequires HTTP/WebSocket access
FileSystemRequires local file access
CryptographyUses crypto operations
SubprocessCan spawn child processes

MCP Client (vex-llm)

Model Context Protocol integration for external tool servers.

Code
┌─────────────────────────────────────────────────────────────┐
│                    MCP Client Flow                           │
├─────────────────────────────────────────────────────────────┤
│  McpClient                                                   │
│  ├── Connect(url)        // TLS enforced for remote          │
│  ├── Authenticate        // OAuth 2.1 token                  │
│  ├── ListTools()         // Discover available tools         │
│  └── CallTool(name,args) // Execute with timeout             │
├─────────────────────────────────────────────────────────────┤
│  McpToolAdapter                                              │
│  • Wraps MCP tool as VEX Tool                                │
│  • Results Merkle-hashed for audit                           │
│  • Capability: Network                                       │
└─────────────────────────────────────────────────────────────┘

A2A Protocol (vex-api)

Agent-to-Agent protocol for cross-framework agent collaboration.

Code
┌─────────────────────────────────────────────────────────────┐
│                    A2A Endpoints                             │
├─────────────────────────────────────────────────────────────┤
│  GET  /.well-known/agent.json                                │
│       └── AgentCard { name, skills, auth }                   │
│                                                              │
│  POST /a2a/tasks                                             │
│       └── TaskRequest { skill, input, nonce }                │
│       └── TaskResponse { status, result, merkle_hash }       │
│                                                              │
│  GET  /a2a/tasks/{id}                                        │
│       └── TaskResponse { status, result, merkle_hash }       │
├─────────────────────────────────────────────────────────────┤
│  Security                                                    │
│  • OAuth 2.0 / JWT authentication                            │
│  • Nonce + timestamp replay protection                       │
│  • Task responses include Merkle hash                        │
└─────────────────────────────────────────────────────────────┘

Directory Structure#

Code
vex/
├── crates/
│   ├── vex-core/         # Agent, Genome, Merkle, Evolution
│   ├── vex-adversarial/  # Shadow, Debate, Consensus
│   ├── vex-temporal/     # Memory, Horizon, Compression
│   ├── vex-persist/      # SQLite, Stores, Migrations
│   ├── vex-api/          # HTTP Server, Auth, Middleware
│   ├── vex-runtime/      # Orchestrator, Executor
│   ├── vex-queue/        # Worker Pool, Job Trait
│   ├── vex-llm/          # Providers, Tools, Rate Limit
│   ├── vex-cli/          # CLI: tools, verify, info
│   └── vex-macros/       # Procedural Macros
├── examples/
│   └── vex-demo/         # Demo Applications
├── tests/                # Integration Tests
└── scripts/              # Utilities
Was this page helpful?
Edit this page on GitHub