Rust for AI Agent Infrastructure: A Field Guide for Engineers
The models are commoditising. The infrastructure around them is not. Rust is the language for that infrastructure. This is the field guide for engineers who want to build in this space.
Why Rust
Three properties make Rust the right choice for AI agent infrastructure:
-
Memory safety without GC: Rust’s ownership model prevents use-after-free, buffer overflows, and data races at compile time. No garbage collection pauses. For a 24/7 agent runtime, this means consistent p99 latency. Python’s GC pauses are 10-100ms; Rust’s worst case is zero.
-
Async runtime (Tokio): Rust’s async ecosystem (Tokio, async-std) is mature. For an agent runtime that handles hundreds of concurrent agent sessions, each with multiple tool calls, async is not optional. Tokio’s scheduler is production-grade.
-
Zero-copy and memory efficiency: for inference servers and data pipelines, memory is the bottleneck. Rust’s ownership model enables zero-copy parsing, custom allocators (jemalloc, mimalloc), and precise memory control. Python’s reference counting + GC is 2-5x more memory-intensive for the same workload.
The ecosystem
| Crate | What it does | Maturity |
|---|---|---|
candle | Hugging Face’s Rust ML framework | Production |
tokenizers | Hugging Face tokenisation in Rust | Production |
rig | AI agent framework in Rust | Early |
harmony-protocol | OpenAI Harmony response format (ours) | Production |
tokio | Async runtime | Production |
serde | Serialisation | Production |
pyo3 | Python-Rust bridge | Production |
polars | DataFrames (faster than Pandas) | Production |
axum | Web framework | Production |
The architecture
A production AI agent infrastructure in Rust has four layers:
-
Runtime: the orchestrator. Manages agent sessions, handles tool calls, enforces safety gates (the Substrate Pattern). Built on Tokio. This is what Neul Labs builds.
-
Inference: the model serving layer. Can be vLLM (Python), TGI (Python), or a custom Rust inference server. The Rust server wraps the model with pre/post-processing in Rust for 5-10x speedup on the non-model parts.
-
Tools: the external services the agent calls. Each tool is a Rust function with a schema, a scope, and a rate limit. The tool substrate enforces these.
-
Observability: tracing, metrics, kill switches. Built with
tracing(Rust’s structured logging), exported to Prometheus/Grafana or Langfuse.
The career path
If you’re an engineer considering Rust for AI infrastructure:
- Learn Rust properly: not just the syntax. The ownership model, lifetimes, and async. “The Rust Programming Language” book + the Tokio tutorial.
- Build something small: a CLI tool that calls an LLM API. Our
gdelt-cliorgsheet-cliare good examples — small, focused, useful. - Build something with async: a concurrent agent runtime that handles multiple sessions. This is where Tokio + Rust shines.
- Learn PyO3: the bridge between Python and Rust. Most AI teams have Python code; the Rust engineer who can also write PyO3 bindings is the most valuable.
What we’re building at Neul Labs
Neul Labs builds the production runtime, safety, observability, and deployment layers for AI agents in Rust. The open-source work is at github.com/sarkar-dipankar:
fragaria— Chain of Thought reasoning API with RL (21 stars)harmony-protocol— OpenAI Harmony response format in Rustdeepfake-detection-network— Decentralized deepfake detectionfairflow-protocol-paper— MEV mitigation in Ethereum
Plus 7+ Rust CLIs at github.com/dipankar: gdelt-cli, gsheet-cli, hubspot-cli, apollo-io-cli, gity, iced-plus, datalab-cli.
We’re hiring
Selectively. Rust engineers who care about production safety. Email me@dipankar.name with a link to something you’ve built.
— Dipankar Sarkar, Founder of Neul Labs
Related Articles
AI Agent Safety Governance: An Engineer's Playbook
The practical playbook for AI agent safety governance. Threat model, runtime policy, prompt injection defense, audit, red-team, and the tooling matrix.
Harmony Protocol in Rust: Parsing OpenAI's GPT-OSS Response Format
A deep dive into implementing OpenAI's Harmony response format in Rust. Channel semantics, streaming, comparison with ChatML, and the Rust implementation.
AI Governance for Financial Services: The 4-Tier NIST AI RMF
How to implement the 4-tier NIST AI RMF Agentic Profile for financial services. The framework I developed at Neul Labs for compliance-first AI agents.