Skip to main content
Agent is the core execution unit in PraisonAI Rust SDK.

Quick Start

1

Simple Agent

use praisonai::Agent;

let agent = Agent::simple("Be helpful")?;
let response = agent.chat("Hello!").await?;
2

With Builder

use praisonai::Agent;

let agent = Agent::new()
    .name("assistant")
    .instructions("You are a helpful AI assistant")
    .build()?;

let response = agent.chat("What is Rust?").await?;

API Methods

Agent::simple()

One-liner agent creation:
// Equivalent to Agent::new().instructions(...).build()
let agent = Agent::simple("You are a helpful assistant")?;

Agent::new()

Start builder for full customization:
let agent = Agent::new()
    .name("researcher")
    .instructions("Research topics thoroughly")
    .build()?;

agent.chat()

Main method for interaction:
let response = agent.chat("Your prompt here").await?;

agent.start() / agent.run()

Aliases for chat():
let response = agent.start("Your task").await?;
let response = agent.run("Your task").await?;

Builder Methods

MethodTypeDescription
.name(str)&strAgent identifier
.instructions(str)&strSystem instructions
.tool(fn)impl ToolAdd a tool
.build()-Create the Agent

Complete Example

use praisonai::{Agent, tool};

#[tool(description = "Search the web")]
async fn search(query: String) -> String {
    format!("Results for: {}", query)
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let agent = Agent::new()
        .name("researcher")
        .instructions("Use search to find information")
        .tool(search)
        .build()?;
    
    // Multiple interactions
    let r1 = agent.chat("Find info about Rust").await?;
    let r2 = agent.chat("Now find info about Python").await?;
    
    // Memory is preserved between chats
    println!("Response 1: {}", r1);
    println!("Response 2: {}", r2);
    
    Ok(())
}

Memory

Conversation history is automatically maintained:
let agent = Agent::simple("Remember our conversation")?;

agent.chat("My name is Alice").await?;
let response = agent.chat("What's my name?").await?;
// Response will include "Alice"

// Clear memory if needed
agent.clear_memory().await?;

Best Practices

Clear instructions lead to better agent behavior. Be specific about the agent’s role and capabilities.
Give agents tools when they need to perform actions beyond text generation.
Always use ? or proper error handling for async operations.