Files

36 lines
1.2 KiB
Rust

use std::sync::Arc;
use agent_core::ReActAgent;
use agent_providers::ChatCompletionsProvider;
use agent_tools::{CurrentTimeTool, ReadFileTool};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv().ok();
let provider = Arc::new(ChatCompletionsProvider::from_env()?);
let agent = ReActAgent::builder(provider, std::env::var("MODEL").unwrap_or_default())
.system_prompt("你是小助手!")
.max_iterations(5)
.tool(Arc::new(CurrentTimeTool))
.tool(Arc::new(ReadFileTool))
.build();
let output = agent
.run("帮我看看 /home/aieyzi/Documents/prompts.txt 第二行里是什么, 你只看第二行。")
.await?;
println!("-- after {} iteration(s) ---", output.iterations);
println!("{}", output.final_message.content.unwrap_or_default());
println!("-- full history ---");
for (i, m) in output.history.iter().enumerate() {
println!("[{}] {:?}: {:?}", i, m.role, m.content);
if let Some(calls) = &m.tool_calls {
for call in calls {
println!("{} -> {}({})", call.id, call.name, call.arguments);
}
}
}
Ok(())
}