Skip to main content
Create a working AI agent in three steps.

Quick Start

1

Create Project

cargo new my-agent
cd my-agent
cargo add praisonai tokio anyhow
2

Set API Key

export OPENAI_API_KEY="your-api-key"
3

Write Code

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

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Create agent with one line
    let agent = Agent::simple("You are a helpful assistant")?;
    
    // Chat with the agent
    let response = agent.chat("What is Rust?").await?;
    println!("{}", response);
    
    Ok(())
}
4

Run

cargo run

With Builder Pattern

For more control, use the builder:
use praisonai::Agent;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let agent = Agent::new()
        .name("assistant")
        .instructions("You are a Rust expert. Explain concepts clearly.")
        .build()?;
    
    let response = agent.chat("What is ownership in Rust?").await?;
    println!("{}", response);
    
    Ok(())
}

With Tools

Add capabilities using the #[tool] macro:
use praisonai::{Agent, tool};

#[tool(description = "Calculate a math expression")]
async fn calculate(expression: String) -> String {
    // Simple example - in production, use a real evaluator
    format!("Result of {}: 42", expression)
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let agent = Agent::new()
        .instructions("Use the calculate tool for math")
        .tool(calculate)
        .build()?;
    
    let response = agent.chat("What is 2 + 2?").await?;
    println!("{}", response);
    
    Ok(())
}

Multi-Agent Team

Coordinate multiple agents:
use praisonai::{Agent, AgentTeam, Process};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let team = AgentTeam::new()
        .agent(Agent::simple("Research topics thoroughly")?)
        .agent(Agent::simple("Write clear, engaging content")?)
        .agent(Agent::simple("Edit for grammar and clarity")?)
        .process(Process::Sequential)
        .build();
    
    let result = team.start("Write about async in Rust").await?;
    println!("{}", result);
    
    Ok(())
}

Next Steps