Skip to main content
Build your first AI agent in under 5 minutes.

Your First Agent

1

Create the Project

cargo new my-agent
cd my-agent
2

Add Dependencies

# Cargo.toml
[dependencies]
praisonai = "0.1"
tokio = { version = "1", features = ["full"] }
3

Set API Key

export OPENAI_API_KEY="your-key"
4

Write the Code

// src/main.rs
use praisonai::Agent;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let agent = Agent::new()
        .name("Assistant")
        .instructions("You are a helpful assistant")
        .build()?;
    
    let response = agent.chat("What is Rust?").await?;
    println!("{}", response);
    
    Ok(())
}
5

Run It

cargo run
Output:
Rust is a systems programming language focused on safety, 
concurrency, and performance...

Add a Tool

Give your agent abilities with tools:
use praisonai::{Agent, tool};

#[tool]
fn get_weather(city: String) -> String {
    format!("Weather in {}: Sunny, 72°F", city)
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let agent = Agent::new()
        .name("Weather Bot")
        .instructions("Help with weather queries")
        .tool(get_weather)
        .build()?;
    
    agent.chat("What's the weather in Tokyo?").await?;
    // Agent calls get_weather("Tokyo") automatically
    
    Ok(())
}

What’s Next?