·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,000Core types, config, error handling
ryvos-agent~6,000ReAct loop, tool dispatch
ryvos-tools~5,000Built-in tools, skill loader
ryvos-security~4,000Tier classification, patterns
ryvos-mcp~3,500MCP client implementation
ryvos-telegram~3,000Telegram channel
ryvos-discord~2,500Discord channel
ryvos-web~2,500Web UI + API gateway
ryvos-config~2,000Configuration management
ryvos-reflect~2,500Reflexion engine

Zero unsafe blocks. Zero C dependencies. Open source.

Get Started

cargo install ryvos

Check out the source on GitHub or read the docs.