agent_with_tools/
agent_with_tools.rs

1//! # Example: Agent with Tools
2//!
3//! This example demonstrates how to create an agent and equip it with tools.
4//! The agent can then use these tools to perform tasks that it cannot do on its own.
5
6use helios_engine::{Agent, CalculatorTool, Config, EchoTool};
7
8#[tokio::main]
9async fn main() -> helios_engine::Result<()> {
10    // Load configuration from `config.toml`.
11    let config = Config::from_file("config.toml")?;
12
13    // Create an agent named "ToolAgent" and equip it with the `CalculatorTool` and `EchoTool`.
14    // Using the improved syntax to add multiple tools at once!
15    let mut agent = Agent::builder("ToolAgent")
16        .config(config)
17        .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
18        .tools(vec![Box::new(CalculatorTool), Box::new(EchoTool)])
19        .max_iterations(5)
20        .build()
21        .await?;
22
23    println!(
24        "Available tools: {:?}\n",
25        agent.tool_registry().list_tools()
26    );
27
28    // --- Test the calculator tool ---
29    let response = agent.chat("What is 25 * 4 + 10?").await?;
30    println!("Agent: {}\n", response);
31
32    // --- Test the echo tool ---
33    let response = agent
34        .chat("Can you echo this message: 'Hello from Helios!'")
35        .await?;
36    println!("Agent: {}\n", response);
37
38    Ok(())
39}