-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path08-oneshot-query.rs
More file actions
34 lines (29 loc) · 901 Bytes
/
08-oneshot-query.rs
File metadata and controls
34 lines (29 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Example 8: One-shot Query
//
// Quick one-shot agent query with restricted tools.
//
// Run: cargo run --example 08-oneshot-query
use open_agent_sdk::{Agent, AgentOptions};
#[tokio::main]
async fn main() {
println!("--- Example 8: One-shot Query ---");
let mut agent = Agent::new(AgentOptions {
max_turns: Some(5),
allowed_tools: Some(vec!["Bash".to_string(), "Glob".to_string()]),
..Default::default()
})
.await
.unwrap();
match agent.prompt("List the files in the current directory. Be brief.").await {
Ok(result) => {
println!("\n{}", result.text);
println!(
"\n({} turns, {} tokens)",
result.num_turns,
result.usage.input_tokens + result.usage.output_tokens
);
}
Err(e) => eprintln!("Error: {}", e),
}
agent.close().await;
}