RUST for Building Agents
This is a write up to discuss approach for building agents using Rust.
Why RUST?
This would the obvious question. Rust language biggest advantage is the speed. Rust has an ability to perform close to C/C++, better in reliability and security areas. Rust Language also has a fast compiler without the overhead of garbage collector and resource consumptions are less.
There are frameworks available in Rust that can be used for building Ai Agents (Some examples given below)
Rust for AI is fairly new but i feel this will gain momentum when organisation begin to prioritise more over speed and security.
Example of how we can use Rust for building AI Agents
Install Rust from below URL
https://rust-lang.org/tools/install/
use Cargo to create a new project (Cargo is a package manager for Rust)
add rig and tokio (tokio is de facto for Rust for ansc and high speed performance)
cargo add new <projectname> (This will create a main.rs file which is the main file for the rust program)
-------
main.rs
use rig::providers::gemini;
use rig::client::{CompletionClient, ProviderClient}
(ProviderClient initializes the client, Completion client is for coversional chat completions)
#[tokio::main] -- this is async and ensuring high performance
async fn main -> Result<(), anyhow::Error> {
let client = gemini::Client::new("Enter your APi Key");
let agent = client
.agent("gemini-2.5-flash")
.preamble("hi")
.tool(testTool)
.build()
#[derive(Deserialize, Serialize)] -- defines that we would need to serialise and deserialize
struct testTool;
impl Tool for testTool {
async fn definition(&self, _prompt: String) -> ToolDefinition {
ToolDefinition {
deserialize the input arguments
}
}
async call () {
perform the operation that needs to be done with the input
}
}
Embeddings can also be created using Rig
Above is very high level example using Rig library, we also have another library ADK-Rust
Rust being faster will help in building agents that may respond faster. In the future you may see many organisations Adopting to Rust.
This is very small write up on how can Rust be used, will be writing more as this is something i am learning in my free time.
Thank you for Reading.....
Hope this helps :-)