Why We Built an AI Agent in Rust
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
tokioand structured concurrency) - No GIL (true parallelism)
The Hard Parts
It wasn't all smooth. Rust has real costs:
- Compile times — A clean build takes ~3 minutes across 10 crates
- Ecosystem gaps — We had to build our own MCP client from scratch
- Learning curve — Async Rust is genuinely difficult
- 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:
| Crate | Lines | Purpose |
|---|---|---|
| ryvos-core | ~8,000 | Core types, config, error handling |
| ryvos-agent | ~6,000 | ReAct loop, tool dispatch |
| ryvos-tools | ~5,000 | Built-in tools, skill loader |
| ryvos-security | ~4,000 | Tier classification, patterns |
| ryvos-mcp | ~3,500 | MCP client implementation |
| ryvos-telegram | ~3,000 | Telegram channel |
| ryvos-discord | ~2,500 | Discord channel |
| ryvos-web | ~2,500 | Web UI + API gateway |
| ryvos-config | ~2,000 | Configuration management |
| ryvos-reflect | ~2,500 | Reflexion engine |
Zero unsafe blocks. Zero C dependencies. Open source.
Get Started
cargo install ryvosCheck out the source on GitHub or read the docs.