use std::sync::Arc;
use async_trait::async_trait;
use oris_runtime::{
agent::create_agent, chain::Chain, error::ToolError, prompt_args, schemas::messages::Message,
tools::Tool,
};
use serde_json::Value;
struct WeatherTool;
#[async_trait]
impl Tool for WeatherTool {
fn name(&self) -> String {
"get_weather".to_string()
}
fn description(&self) -> String {
"Get weather for a given city".to_string()
}
async fn run(&self, input: Value) -> Result<String, ToolError> {
let city = input
.get("input")
.and_then(|v| v.as_str())
.unwrap_or("unknown");
Ok(format!("It's always sunny in {}!", city))
}
}
#[tokio::main]
async fn main() {
let agent = create_agent(
"gpt-4o-mini", &[Arc::new(WeatherTool)], Some("You are a helpful assistant"), None, )
.expect("Failed to create agent");
let result = agent
.invoke(prompt_args! {
"messages" => vec![
Message::new_human_message("what is the weather in sf")
]
})
.await
.expect("Failed to invoke agent");
println!("Result: {}", result);
let result2 = agent
.invoke(prompt_args! {
"input" => "what is the weather in nyc"
})
.await
.expect("Failed to invoke agent");
println!("Result 2: {}", result2);
let messages = vec![Message::new_human_message("what is the weather in paris")];
let result3 = agent
.invoke_messages(messages)
.await
.expect("Failed to invoke agent");
println!("Result 3: {}", result3);
}