recovery: change agent-providers as a directory

This commit is contained in:
aiyezi committed 2026-11-05 17:36:42 +08:00
1 parent 91b44fcc16
commit 339ca0f87e
9 files changed
+345 -1

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
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(())
}