·2 min read·Ryvos Team

Why We Built an AI Agent in Rust

rustengineering

Why We Built an AI Agent in Rust

The AI ecosystem runs on Python. LangChain, AutoGPT, CrewAI, OpenInterpreter — all Python. We built Ryvos in Rust instead. Here's why.

Performance Is a Feature

An AI agent spends most of its time waiting for LLM responses. But the time between responses — parsing, tool dispatch, security checks — matters more than you think.

In Python-based agents, we measured:

  • 200-500ms overhead per tool dispatch
  • 150MB+ memory baseline
  • 2-3 seconds startup time

In Ryvos:

  • <1ms tool dispatch
  • ~15MB memory footprint
  • <100ms startup

When your agent chains 10 tools in a row, that's the difference between 5 seconds of overhead and 10 milliseconds.

Safety at the Type Level

Rust's type system lets us encode security invariants at compile time:

// A command that hasn't been classified yet
struct UnclassifiedCommand(String);
 
// A command that has been classified and approved
struct ApprovedCommand {
    command: String,
    tier: SecurityTier,
    approved_by: ApprovalSource,
}
 
// You literally can't execute an unclassified command
fn execute(cmd: ApprovedCommand) -> Result<Output> {
    // ...
}

In Python, you'd need runtime checks and hope nobody bypasses them. In Rust, the compiler enforces it.

Fearless Concurrency

Ryvos handles multiple channels simultaneously — Telegram, Discord, Slack, Web, all at once. Rust's ownership system makes this safe by default:

  • No data races (guaranteed at compile time)
  • No deadlocks (using tokio and structured concurrency)
  • No GIL (true parallelism)

The Hard Parts

It wasn't all smooth. Rust has real costs:

  1. Compile times — A clean build takes ~3 minutes across 10 crates
  2. Ecosystem gaps — We had to build our own MCP client from scratch
  3. Learning curve — Async Rust is genuinely difficult
  4. Iteration speed — Prototyping is slower than Python

But for a security-critical system that needs to be fast, reliable, and correct? Rust is the right choice.

39,000 Lines Later

Our codebase is 39,000 lines across 10 crates:

CrateLinesPurpose
ryvos-core~8,000Config, error types, event bus, security policy, goal system
ryvos-agent~6,000ReAct loop, SecurityGate, Guardian, Judge, GoalEvaluator, CheckpointStore, CronScheduler, GraphExecutor
ryvos-tools~5,000Tool registry, 11 built-in tools
ryvos-mcp~3,500MCP client (stdio + SSE transports)
ryvos-channels~3,000Telegram, Discord, Slack adapters
ryvos-gateway~2,500Axum HTTP/WS server, Web UI, RBAC
ryvos-skills~2,500Drop-in skill loader (Lua/Rhai)
ryvos-memory~2,000SQLite-backed session and history
ryvos-tui~2,000Terminal UI (ratatui)
ryvos-llm~2,500LLM client abstraction with streaming

Zero unsafe blocks. Zero C dependencies. Open source.

Get Started

curl -fsSL https://raw.githubusercontent.com/Ryvos/ryvos/main/install.sh | sh
ryvos init
ryvos

Check out the source on GitHub or read the docs.