2 min read

VEX Examples#

Practical, copy-paste examples for building with VEX. Each example is self-contained and production-tested.

Quick Recipes#

Minimal Agent with Verification#

The smallest possible VEX agent with adversarial verification enabled.

Rust
use vex_core::{AgentContext, VexResult};
use vex_adversarial::BlueAgent;

async fn minimal() -> VexResult<()> {
    let ctx = AgentContext::new("minimal-agent");
    let agent = BlueAgent::new(ctx);
    let result = agent.execute("What is 2+2?").await?;
    println!("Verified: {}", result.answer);
    Ok(())
}

Router-Based Multi-Agent#

Route tasks to specialised agents based on semantic similarity.

Rust
use vex_router::{Router, RouteConfig};
use vex_runtime::AgentExecutor;

async fn routed() -> anyhow::Result<()> {
    let router = Router::new(RouteConfig::default());
    let executor = AgentExecutor::builder()
        .with_router(router)
        .build()?;

    let response = executor.run("Summarize this document.").await?;
    println!("{}", response.content);
    Ok(())
}

Persisted Memory Across Sessions#

Use vex-temporal to give your agent a long-term memory.

Rust
use vex_temporal::EvolutionMemory;
use vex_persist::PersistenceLayer;

async fn with_memory() -> anyhow::Result<()> {
    let db = PersistenceLayer::open("agent.db")?;
    let memory = EvolutionMemory::new(db);

    // Store context
    memory.store("user_preference", "Prefers concise answers").await?;

    // Retrieve later
    let ctx = memory.recall("user_preference").await?;
    println!("Remembered: {:?}", ctx);
    Ok(())
}

Blockchain Anchoring with vex-anchor#

Cryptographically anchor agent decisions to the Solana blockchain.

Rust
use vex_anchor::{AnchorClient, AnchorConfig};

async fn anchor_decision() -> anyhow::Result<()> {
    let client = AnchorClient::new(AnchorConfig::devnet())?;
    
    let proof = client
        .anchor("agent-decision-v1", b"The response was verified and approved")
        .await?;

    println!("Anchored TX: {}", proof.signature);
    Ok(())
}

Full Examples#

For a complete, end-to-end production setup using all VEX crates together, see the Production Integration Guide.

For the full architecture overview of how these components fit together, see the Architecture Guide.

Was this page helpful?
Edit this page on GitHub