multiple_agents/
multiple_agents.rs

1//! # Example: Multiple Agents
2//!
3//! This example demonstrates how to create and use multiple agents with different
4//! personalities and tools. Each agent maintains its own separate conversation
5//! history and can be specialized for different tasks.
6
7use helios_engine::{Agent, CalculatorTool, Config};
8
9#[tokio::main]
10async fn main() -> helios_engine::Result<()> {
11    // Load configuration from `config.toml`.
12    let config = Config::from_file("config.toml")?;
13
14    // --- Create multiple agents with different personalities and tools ---
15
16    // An agent specialized in math, equipped with a calculator tool.
17    let mut math_agent = Agent::builder("MathAgent")
18        .config(config.clone())
19        .system_prompt("You are a math expert. You love numbers and equations.")
20        .tool(Box::new(CalculatorTool))
21        .build()
22        .await?;
23
24    // A creative agent for writing and storytelling.
25    let mut creative_agent = Agent::builder("CreativeAgent")
26        .config(config)
27        .system_prompt("You are a creative writer who loves storytelling and poetry.")
28        .build()
29        .await?;
30
31    // --- Interact with the Math Agent ---
32    println!("=== Math Agent ===");
33    let response = math_agent.chat("What is the square root of 144?").await?;
34    println!("Math Agent: {}\n", response);
35
36    // --- Interact with the Creative Agent ---
37    println!("=== Creative Agent ===");
38    let response = creative_agent
39        .chat("Write a haiku about programming.")
40        .await?;
41    println!("Creative Agent: {}\n", response);
42
43    Ok(())
44}