Skip to main content

fn_tools/
fn_tools.rs

1mod common;
2
3use common::run_cli_loop;
4use tiny_loop::{Agent, llm::OpenAIProvider, tool::tool};
5
6/// Get the current weather for a location
7#[tool]
8async fn get_weather(
9    /// City name
10    city: String,
11) -> String {
12    format!("The weather in {} is sunny and 72°F", city)
13}
14
15/// Calculate the sum of two numbers
16#[tool]
17async fn add(
18    /// First number
19    a: i32,
20    /// Second number
21    b: i32,
22) -> String {
23    format!("{}", a + b)
24}
25
26#[tokio::main]
27async fn main() {
28    let api_key = std::env::var("LLM_API_KEY").expect("LLM_API_KEY not set");
29
30    let llm = OpenAIProvider::new()
31        .api_key(api_key)
32        .base_url("https://openrouter.ai/api/v1")
33        .model("google/gemini-3-flash-preview");
34
35    let agent = Agent::new(llm)
36        .system("You are a helpful assistant with access to tools")
37        .tool(get_weather)
38        .tool(add);
39
40    run_cli_loop(agent).await
41}