-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path04-prompt-api.rs
More file actions
37 lines (32 loc) · 982 Bytes
/
04-prompt-api.rs
File metadata and controls
37 lines (32 loc) · 982 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
35
36
37
// Example 4: Blocking Prompt API
//
// Uses agent.prompt() for a quick one-shot query without streaming.
//
// Run: cargo run --example 04-prompt-api
use open_agent_sdk::{Agent, AgentOptions};
#[tokio::main]
async fn main() {
println!("--- Example 4: Prompt API ---");
let mut agent = Agent::new(AgentOptions {
max_turns: Some(5),
..Default::default()
})
.await
.unwrap();
match agent
.prompt("Run 'rustc --version' and 'cargo --version' using Bash, and tell me the versions.")
.await
{
Ok(result) => {
println!("\nResponse: {}", result.text);
println!("\nTurns: {}", result.num_turns);
println!(
"Tokens: {} in / {} out",
result.usage.input_tokens, result.usage.output_tokens
);
println!("Duration: {}ms", result.duration_ms);
}
Err(e) => eprintln!("Error: {}", e),
}
agent.close().await;
}